public static void Print(PrintType printType, BarcodeSample sample, TestResult technic, TestResult reality) { ExcelAccess access = new ExcelAccess(); string path = ConfigurationManager.AppSettings["template"]; string fullPath = Path.GetFullPath(path); access.Open(fullPath); access.IsVisibledExcel = true; access.FormCaption = "商品条码符号检测数据"; switch (printType) { case PrintType.Print: access.Print(); break; case PrintType.PrintView: access.PrintPreview(); break; default: access.Close(); break; } access.Close(); }
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 }
static void ExcelReports() { //Console.WriteLine("Input zip file path: "); //string zipFilePath = Console.ReadLine(); ArchiveAccess archive = new ArchiveAccess(@"E:\newTeamwork\project\Sample-Reports.zip"); archive.Extract(); OpenAccessMySQL mysqlCon = new OpenAccessMySQL(); ParadiseSupermarketChainEntities sqlCon = new ParadiseSupermarketChainEntities(); using (mysqlCon) { using (sqlCon) { foreach (var product in mysqlCon.Products) { var efProduct = new EntityFramework.Data.Products(); efProduct.Id = product.Id; efProduct.Name = product.ProductName; efProduct.BasePrice = (decimal)product.BasePrice; var measure = sqlCon.Measurements.Where(m => m.Name == product.Measure.MeasureName).FirstOrDefault(); if (measure == null) { measure = new EntityFramework.Data.Measurements(); measure.Name = product.Measure.MeasureName; sqlCon.Measurements.Add(measure); } efProduct.Measurements = measure; var vendor = sqlCon.Vendors.Where(v => v.Name == product.Vendor.VendorName).FirstOrDefault(); if (vendor == null) { vendor = new EntityFramework.Data.Vendors(); vendor.Name = product.Vendor.VendorName; sqlCon.Vendors.Add(vendor); } efProduct.Vendors = vendor; sqlCon.Products.Add(efProduct); try { sqlCon.SaveChanges(); } catch (Exception e) { //Console.WriteLine(e.InnerException.InnerException.Message); } } } } // get the info from the unzipped folder string unzippedFolderName = "Paradise-Sample-Reports"; string unzippedFolderPath = String.Format(@"../../../{0}", unzippedFolderName); foreach (var dir in Directory.GetDirectories(archive.ExtractPath)) { foreach (var file in Directory.GetFiles(dir, "*.xls")) { string currentFolderName = Path.GetFileName(dir); DateTime currentDate = DateTime.Parse(currentFolderName); string fileName = Path.GetFileName(file); using (var db = new ParadiseSupermarketChainEntities()) { var excelComs = new ExcelAccess(file); string supermarketName = null; int rowIndex = 0; excelComs.Open(); excelComs.ReadSheetActionRow("Sales", (row) => { rowIndex++; if (rowIndex <= 2) { if (row.Count == 1 && row[0].ToString().IndexOf("Supermarket") != -1) { // this is the supermarket Name supermarketName = row[0] + ""; } // skip the first 2 rows return; } if (row.Count == 4) { // add a product int productId = int.Parse((row[0] + "")); double quantity = double.Parse((row[1] + "")); decimal unitPrice = decimal.Parse((row[2] + "")); decimal sum = decimal.Parse((row[3] + "")); Sales productSales = new Sales(); productSales.ProductId = productId; productSales.Quantity = quantity; productSales.UnitPrice = unitPrice; productSales.Sum = sum; // find out if the supermarket exists Supermarkets supermarket = db.Supermarkets.Where(s => s.Name == supermarketName).FirstOrDefault(); if (supermarket == null) { supermarket = new Supermarkets(); supermarket.Name = supermarketName; db.Supermarkets.Add(supermarket); } productSales.Supermarkets = supermarket; // find out if the date exists Dates date = db.Dates.Where(d => d.Date == currentDate).FirstOrDefault(); if (date == null) { date = new Dates(); date.Date = currentDate; db.Dates.Add(date); } productSales.Dates = date; db.Sales.Add(productSales); db.SaveChanges(); } else { // the final line: the sum of the products } }); excelComs.Close(); } } } Directory.Delete(archive.ExtractPath, true); }