private void btnGenerateFile_Click(object sender, EventArgs e) { bool parse; if (this.databaseInfor == null) { txtLog.Text += "Database error: Database file is not exits\r\n"; return; } if (edtFileInput.Text == "") { txtLog.Text += "Output file error: Path file is empty\r\n"; return; } packingParser = new ParkingListParser(this.databaseInfor); String file = edtFileInput.Text; parse = packingParser.PackingListParser(file); if (!parse) { txtLog.Text += "Parse packing data error: " + this.packingParser.GetErrorCode() + "\r\n"; return; } else { txtLog.Text += "Parse packing data information: " + this.packingParser.GetErrorCode() + "\r\n"; } packingParser.MergerPackingList(); if (intCommandType == 0) { packingGenerator = new PackingListGenerator(packingParser, databaseInfor, edtOutFilePath.Text); parse = packingGenerator.GeneratePackingListFile(); if (!parse) { txtLog.Text += "Generate file error: " + this.packingParser.GetErrorCode() + "\r\n"; return; } else { txtLog.Text += "Generate file log: " + this.packingParser.GetErrorCode() + "\r\n"; txtLog.Text += "\r\n\r\n---------------------------------\r\n"; txtLog.Text += "---------Sucessfully-------------\r\n"; } } }
public PackingListGenerator(ParkingListParser packingParser, Database databaseInfor, String file) { this.databaseInfor = databaseInfor; this.packingParser = packingParser; this.file = file; this.errorCode = ""; wb = new XSSFWorkbook(); // create sheet sheet_1 = (XSSFSheet)wb.CreateSheet("工作表2"); sheet_2 = (XSSFSheet)wb.CreateSheet("PL detail"); sheet_1_generator = new PackingListSheet1Generator(wb, sheet_1, databaseInfor, packingParser); sheet_2_generator = new PackingListDetailSheet2Generator(wb, sheet_2, databaseInfor, packingParser); }
public PackingListSheet1Generator(XSSFWorkbook wb, XSSFSheet sheet_1, Database databaseInfor, ParkingListParser packingParser) { this.wb = wb; this.sheet_1 = sheet_1; this.databaseInfor = databaseInfor; this.packingParser = packingParser; rowIndex_sheet_1 = 0; sheet_1_headerStyle = wb.CreateCellStyle(); sheet_1_headerStyle.Alignment = HorizontalAlignment.Center; sheet_1_headerStyle.VerticalAlignment = VerticalAlignment.Center; sheet_1_headerStyle.BorderTop = BorderStyle.Thin; sheet_1_headerStyle.BorderRight = BorderStyle.Thin; sheet_1_headerStyle.BorderBottom = BorderStyle.Thin; sheet_1_headerStyle.BorderLeft = BorderStyle.Thin; sheet_1_headerStyle_2 = wb.CreateCellStyle(); sheet_1_headerStyle_2.Alignment = HorizontalAlignment.Center; sheet_1_headerStyle_2.VerticalAlignment = VerticalAlignment.Center; sheet_1_headerStyle_2.BorderTop = BorderStyle.Thin; sheet_1_headerStyle_2.BorderRight = BorderStyle.Thin; sheet_1_headerStyle_2.BorderBottom = BorderStyle.Thin; sheet_1_headerStyle_2.BorderLeft = BorderStyle.Thin; sheet_1_headerStyle_2.FillForegroundColor = IndexedColors.Yellow.Index; sheet_1_headerStyle_2.FillPattern = FillPattern.SolidForeground; var r = sheet_1.CreateRow(rowIndex_sheet_1); rowIndex_sheet_1++; for (int idex = 0; idex < Sheet_1_Header.Length; idex++) { var cell = r.CreateCell(idex); cell.SetCellValue(Sheet_1_Header[idex]); cell.CellStyle = sheet_1_headerStyle; } }
public PackingListDetailSheet2Generator(XSSFWorkbook wb, XSSFSheet sheet_2, Database databaseInfor, ParkingListParser packingParser) { this.wb = wb; this.sheet_2 = sheet_2; this.databaseInfor = databaseInfor; this.packingParser = packingParser; sheet_2_rowIndex = 0; sheet_2_headerStyle_1 = wb.CreateCellStyle(); IFont headerbold_1 = wb.CreateFont(); headerbold_1.Boldweight = (short)FontBoldWeight.Bold; headerbold_1.FontHeight = 13; sheet_2_headerStyle_1.SetFont(headerbold_1); sheet_2_headerStyle_1.Alignment = HorizontalAlignment.Center; sheet_2_headerStyle_1.VerticalAlignment = VerticalAlignment.Center; sheet_2_headerStyle_1.BorderTop = BorderStyle.Thin; sheet_2_headerStyle_1.BorderRight = BorderStyle.Thin; sheet_2_headerStyle_1.BorderBottom = BorderStyle.Thin; sheet_2_headerStyle_2 = wb.CreateCellStyle(); IFont headerbold_2 = wb.CreateFont(); headerbold_2.Boldweight = (short)FontBoldWeight.Bold; headerbold_2.FontHeight = 12; headerbold_2.Underline = FontUnderlineType.Single; sheet_2_headerStyle_2.SetFont(headerbold_2); sheet_2_headerStyle_2.Alignment = HorizontalAlignment.Center; sheet_2_headerStyle_2.VerticalAlignment = VerticalAlignment.Center; sheet_2_headerStyle_2.BorderTop = BorderStyle.Thin; sheet_2_headerStyle_2.BorderRight = BorderStyle.Thin; sheet_2_headerStyle_2.BorderBottom = BorderStyle.Thin; sheet_2_bottomStyle_1 = wb.CreateCellStyle(); sheet_2_bottomStyle_1.FillForegroundColor = IndexedColors.Aqua.Index; sheet_2_bottomStyle_1.FillPattern = FillPattern.SolidForeground; sheet_2_bottomStyle_1.BorderBottom = BorderStyle.Thin; sheet_2_bottomStyle_1.BorderLeft = BorderStyle.Thin; sheet_2_bottomStyle_1.BorderRight = BorderStyle.Thin; IFont boldFont_1 = wb.CreateFont(); boldFont_1.Boldweight = (short)FontBoldWeight.Bold; boldFont_1.FontHeight = 13; boldFont_1.Color = IndexedColors.Red.Index; sheet_2_bottomStyle_1.SetFont(boldFont_1); sheet_2_bottomStyle_2 = wb.CreateCellStyle(); sheet_2_bottomStyle_2.FillForegroundColor = IndexedColors.Aqua.Index; sheet_2_bottomStyle_2.FillPattern = FillPattern.SolidForeground; sheet_2_bottomStyle_2.BorderBottom = BorderStyle.Thin; sheet_2_bottomStyle_2.BorderLeft = BorderStyle.Thin; sheet_2_bottomStyle_2.BorderRight = BorderStyle.Thin; IFont boldFont_2 = wb.CreateFont(); boldFont_2.Boldweight = (short)FontBoldWeight.Bold; boldFont_2.FontHeight = 13; boldFont_2.Color = IndexedColors.Black.Index; sheet_2_bottomStyle_2.SetFont(boldFont_2); sheet_2_mainStyle_2 = wb.CreateCellStyle(); sheet_2_mainStyle_2.BorderBottom = BorderStyle.Dotted; sheet_2_mainStyle_2.BorderRight = BorderStyle.Thin; sheet_2_mergerStyle = wb.CreateCellStyle(); sheet_2_mergerStyle.BorderBottom = BorderStyle.Dotted; sheet_2_mergerStyle.BorderRight = BorderStyle.Thin; sheet_2_mergerStyle.VerticalAlignment = VerticalAlignment.Center; }