public static bool Save(BarcodeSample sample, TestResult technic, TestResult reality, string saveFilename, string templateFile) { ExcelAccess access = new ExcelAccess(); access.Open(templateFile); access.IsVisibledExcel = true; access.FormCaption = "商品条码符号检测数据"; bool flag = false; access.SetCellText(2, "F", sample.SerialNumber); access.SetCellText(3, "F", sample.CustomerName); access.SetCellText(3, "Z", reality.BarcodeType); access.SetCellText(4, "F", sample.SampleName); access.SetCellText(4, "Z", sample.PrintFormat); access.SetCellText(6, "F", sample.CustomerContactPersoner); access.SetCellText(6, "N", sample.CustomerContactNumber); access.SetCellText(0x11, "J", "代办点" + sample.RegisterPoint); access.SetCellText(10, "J", technic.SymbolLevel); access.SetCellText(11, "J", technic.DecodingData); access.SetCellText(12, "J", "≥" + technic.LeftBlank); access.SetCellText(13, "J", "≥" + technic.RightBlank); access.SetCellText(14, "J", "≥" + technic.BarHeight.ToString()); access.SetCellText(15, "J", technic.SizeOfZ); access.SetCellText(0x10, "J", technic.IsValidBarcode); access.SetCellText(10, "V", reality.SymbolLevel); access.SetCellText(11, "V", reality.DecodingData); access.SetCellText(12, "V", reality.LeftBlank); access.SetCellText(13, "V", reality.RightBlank); access.SetCellText(14, "V", reality.BarHeight.ToString()); access.SetCellText(15, "V", reality.SizeOfZ.ToString()); access.SetCellText(0x10, "V", reality.IsValidBarcode); access.SetCellText(6, "Z", reality.TestDate.ToString("yyyyMMdd")); if (access.SaveAs(saveFilename, false)) { flag = true; } access.Close(); return(flag); }
public void ImportExcelMethodHandler(Object obj, ImportExcelArgs ev) { #region 实现... ExcelAccess excel = new ExcelAccess(); excel.Open(); excel.MergeCells(1, 1, 1, this._body.Cols); //合并单元格写标题,并设置字体 excel.SetFont(1, 1, 1, this._body.Cols, this._title.Font); excel.SetCellText(1, 1, 1, this._body.Cols, this._title.Text); //打印网格及网格线 excel.SetCellText((System.Data.DataTable) this.DataSource, 3, 1, true); System.Windows.Forms.FileDialog fileDlg = new System.Windows.Forms.SaveFileDialog(); fileDlg.AddExtension = true; fileDlg.DefaultExt = ".xls"; //fileDlg.InitialDirectory = System.IO.Directory.GetCurrentDirectory(); fileDlg.Title = "保存到Excel文件"; fileDlg.Filter = "Microsoft Office Excel 工作簿(*.xls)|*.xls|模板(*.xlt)|*.xlt"; if (fileDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (excel.SaveAs(fileDlg.FileName, true)) { System.Windows.Forms.MessageBox.Show("数据成功保存到Excel文件!", "GoldPrinter", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } } fileDlg.Dispose(); excel.Close(); #endregion }