Browse Source

excel导出修改

callm 1 year ago
parent
commit
9916f54590
1 changed files with 89 additions and 25 deletions
  1. 89 25
      UAS_MES_LGDZ/DataOperate/ExcelHandler.cs

+ 89 - 25
UAS_MES_LGDZ/DataOperate/ExcelHandler.cs

@@ -12,6 +12,7 @@ using System.Collections.Generic;
 using Seagull.BarTender.Print;
 using DevExpress.XtraPrinting.Native.LayoutAdjustment;
 using DevExpress.XtraExport.Implementation;
+using NPOI.HSSF.Record.CF;
 
 namespace UAS_MES_NEW.DataOperate
 {
@@ -61,6 +62,11 @@ namespace UAS_MES_NEW.DataOperate
             MemoryStream ms = new MemoryStream();
             //创建一个Book,相当于一个Excel文件
             HSSFWorkbook book = new HSSFWorkbook();
+            ICellStyle style = book.CreateCellStyle();
+            style.BorderTop = BorderStyle.THIN;
+            style.BorderLeft = BorderStyle.THIN;
+            style.BorderRight = BorderStyle.THIN;
+            style.BorderBottom = BorderStyle.THIN;
             //Excel中的Sheet
             //获取行数量和列数量
             int rowNum = DataTable.Rows.Count;
@@ -77,7 +83,8 @@ namespace UAS_MES_NEW.DataOperate
                     SheetName = DataTable.Rows[i]["STF_MACHINE"].ToString() + "-" + DataTable.Rows[i + 1]["STF_MACHINE"].ToString().Substring(0, 1);
                     IRow row1 = sheet1.CreateRow(0);
                     row1.CreateCell(0); row1.Cells[0].SetCellValue("       SMT程式料表     ");
-
+                  
+                 
                     //客户抬头
                     IRow row2 = sheet1.CreateRow(1);
                     CellRangeAddress cellRangeAddress = new CellRangeAddress(1, 1, 0, 1);
@@ -88,11 +95,15 @@ namespace UAS_MES_NEW.DataOperate
                     sheet1.AddMergedRegion(cellRangeAddress1);
                     sheet1.AddMergedRegion(cellRangeAddress2);
                     sheet1.AddMergedRegion(cellRangeAddress3);
-                    row2.CreateCell(0); row2.CreateCell(1); row2.Cells[0].SetCellValue("客户名称:");
-                    row2.CreateCell(2); row2.CreateCell(3); row2.Cells[2].SetCellValue("CY");
-                    row2.CreateCell(4); row2.CreateCell(5); row2.Cells[4].SetCellValue("文件编号://"); 
-                    row2.CreateCell(6); row2.CreateCell(7); row2.Cells[6].SetCellValue("发行日期:2024-06-14");
-                   
+                    row2.CreateCell(0); row2.CreateCell(1); row2.Cells[0].SetCellValue("客户名称:");
+                    row2.Cells[0].CellStyle = style; row2.Cells[1].CellStyle = style;
+                    row2.CreateCell(2); row2.CreateCell(3); row2.Cells[2].SetCellValue("CY"); row2.Cells[2].CellStyle = style;
+                    row2.Cells[2].CellStyle = style; row2.Cells[3].CellStyle = style;
+                    row2.CreateCell(4); row2.CreateCell(5); row2.Cells[4].SetCellValue("文件编号://"); row2.Cells[4].CellStyle = style;
+                    row2.Cells[4].CellStyle = style; row2.Cells[5].CellStyle = style;
+                    row2.CreateCell(6); row2.CreateCell(7); row2.Cells[6].SetCellValue("发行日期:"+DateTime.Now.ToString("yyyy-MM-dd")); row2.Cells[6].CellStyle = style;
+                    row2.Cells[6].CellStyle = style; row2.Cells[7].CellStyle = style;
+
                     //产品型号
                     IRow row3 = sheet1.CreateRow(2);
                     CellRangeAddress cellRangeAddress4 = new CellRangeAddress(2, 2, 0, 1);
@@ -103,11 +114,14 @@ namespace UAS_MES_NEW.DataOperate
                     sheet1.AddMergedRegion(cellRangeAddress5);
                     sheet1.AddMergedRegion(cellRangeAddress6);
                     sheet1.AddMergedRegion(cellRangeAddress7);
-                    row3.CreateCell(0); row3.CreateCell(1); row3.Cells[0].SetCellValue("产品型号:");
+                    row3.CreateCell(0); row3.CreateCell(1); row3.Cells[0].SetCellValue("产品型号:");
+                    row3.Cells[0].CellStyle = style; row3.Cells[1].CellStyle = style;
                     row3.CreateCell(2); row3.CreateCell(3); row3.Cells[2].SetCellValue("it9220-LS2404-B1-V2.0-MB");
-                    row3.CreateCell(4); row3.CreateCell(5); row3.Cells[4].SetCellValue("BOM编号:EN-CY-BOM-143(A0)");
-                    row3.CreateCell(6); row3.CreateCell(7); row3.Cells[6].SetCellValue("生效日期:2024-06-14");
-
+                    row3.Cells[2].CellStyle = style; row3.Cells[3].CellStyle = style;
+                    row3.CreateCell(4); row3.CreateCell(5); row3.Cells[4].SetCellValue("BOM编号:EN-CY-BOM-143(A0)");
+                    row3.Cells[4].CellStyle = style; row3.Cells[5].CellStyle = style;
+                    row3.CreateCell(6); row3.CreateCell(7); row3.Cells[6].SetCellValue("生效日期:"+DateTime.Now.ToString("yyyy-MM-dd"));
+                    row3.Cells[6].CellStyle = style; row3.Cells[7].CellStyle = style;
                     //程序名称
                     IRow row4 = sheet1.CreateRow(3);
                     CellRangeAddress cellRangeAddress8 = new CellRangeAddress(3, 3, 0, 1);
@@ -117,9 +131,11 @@ namespace UAS_MES_NEW.DataOperate
                     sheet1.AddMergedRegion(cellRangeAddress9);
                     sheet1.AddMergedRegion(cellRangeAddress10);
                     row4.CreateCell(0); row4.CreateCell(1); row4.Cells[0].SetCellValue("程序名称\t\r\n");
+                    row4.Cells[0].CellStyle = style; row4.Cells[1].CellStyle = style;
                     row4.CreateCell(2); row4.CreateCell(3); row4.Cells[2].SetCellValue("CY-it9220-LS2404-B1-V2.0-MB\t\r\n");
-                    row4.CreateCell(4); row4.CreateCell(5); row4.Cells[4].SetCellValue("面别:    AB面\t\r\n");
-
+                    row4.Cells[2].CellStyle = style; row4.Cells[3].CellStyle = style;
+                    row4.CreateCell(4); row4.CreateCell(5); row4.Cells[4].SetCellValue("面别:    AB面\t\r\n");
+                    row4.Cells[4].CellStyle = style; row4.Cells[5].CellStyle = style;
                     //机器名称
                     IRow row5 = sheet1.CreateRow(4);
                     CellRangeAddress cellRangeAddress14 = new CellRangeAddress(5, 5, 0, 1);
@@ -132,9 +148,13 @@ namespace UAS_MES_NEW.DataOperate
                     sheet1.AddMergedRegion(cellRangeAddress16);
                     sheet1.AddMergedRegion(cellRangeAddress20);
                     row5.CreateCell(0); row5.CreateCell(1); row5.Cells[0].SetCellValue("机器名称\t\r\n");
+                    row5.Cells[0].CellStyle = style; row5.Cells[1].CellStyle = style;
                     row5.CreateCell(2); row5.CreateCell(3); row5.Cells[2].SetCellValue("TX2I+TX2I+TX2I+TX2+SX1\t\r\n");
-                    row5.CreateCell(4); row5.CreateCell(5); row5.Cells[4].SetCellValue("QA确认:\t\r\n");
-                    row5.CreateCell(6); row5.CreateCell(7); row5.Cells[6].SetCellValue("文控签章:");
+                    row5.Cells[2].CellStyle = style; row5.Cells[3].CellStyle = style;
+                    row5.CreateCell(4); row5.CreateCell(5); row5.Cells[4].SetCellValue("QA确认:\t\r\n");
+                    row5.Cells[4].CellStyle = style; row5.Cells[5].CellStyle = style;
+                    row5.CreateCell(6); row5.CreateCell(7); row5.Cells[6].SetCellValue("文控签章:");
+                    row5.Cells[6].CellStyle = style; row5.Cells[7].CellStyle = style;
 
                     //制作
                     IRow row6 = sheet1.CreateRow(5);
@@ -144,10 +164,12 @@ namespace UAS_MES_NEW.DataOperate
                     sheet1.AddMergedRegion(cellRangeAddress17);
                     sheet1.AddMergedRegion(cellRangeAddress18);
                     sheet1.AddMergedRegion(cellRangeAddress19);
-                    row6.CreateCell(0); row6.CreateCell(1); row6.Cells[0].SetCellValue("制作:");
+                    row6.CreateCell(0); row6.CreateCell(1); row6.Cells[0].SetCellValue("制作:");
+                    row6.Cells[0].CellStyle = style; row6.Cells[1].CellStyle = style;
                     row6.CreateCell(2); row6.CreateCell(3); row6.Cells[2].SetCellValue("贺瑞华");
-                    row6.CreateCell(4); row6.CreateCell(5); row6.Cells[4].SetCellValue("QA审核:");
-
+                    row6.Cells[2].CellStyle = style; row6.Cells[3].CellStyle = style;
+                    row6.CreateCell(4); row6.CreateCell(5); row6.Cells[4].SetCellValue("QA审核:");
+                    row6.Cells[4].CellStyle = style; row6.Cells[5].CellStyle = style;
                     //制作
                     IRow row7 = sheet1.CreateRow(6);
                     CellRangeAddress cellRangeAddress21 = new CellRangeAddress(6, 6, 0, 7);
@@ -155,14 +177,37 @@ namespace UAS_MES_NEW.DataOperate
                     row7.CreateCell(0); row7.CreateCell(1); row7.Cells[0].SetCellValue(DataTable.Rows[i]["STF_MACHINE"].ToString() + "-" + DataTable.Rows[i + 1]["STF_MACHINE"].ToString().Substring(0, 1));
 
                     IRow row8 = sheet1.CreateRow(7);
-                    row8.CreateCell(0); row8.Cells[0].SetCellValue("站位");
-                    row8.CreateCell(1); row8.Cells[1].SetCellValue("Feeder类型");
-                    row8.CreateCell(2); row8.Cells[2].SetCellValue("位置");
-                    row8.CreateCell(3); row8.Cells[3].SetCellValue("物料编码");
-                    row8.CreateCell(4); row8.Cells[4].SetCellValue("物料描述");
-                    row8.CreateCell(5); row8.Cells[5].SetCellValue("用量");
-                    row8.CreateCell(6); row8.Cells[6].SetCellValue("位号");
-                    row8.CreateCell(7); row8.Cells[7].SetCellValue("备注");
+                    row8.CreateCell(0);
+                    row8.Cells[0].SetCellValue("站位");
+                    row8.Cells[0].CellStyle = style; 
+
+                    row8.CreateCell(1);
+                    row8.Cells[1].SetCellValue("Feeder类型");
+                    row8.Cells[1].CellStyle = style;
+
+                    row8.CreateCell(2);
+                    row8.Cells[2].SetCellValue("位置");
+                    row8.Cells[2].CellStyle = style;
+
+                    row8.CreateCell(3); 
+                    row8.Cells[3].SetCellValue("物料编码");
+                    row8.Cells[3].CellStyle = style;
+
+                    row8.CreateCell(4);
+                    row8.Cells[4].SetCellValue("物料描述");
+                    row8.Cells[4].CellStyle = style;
+
+                    row8.CreateCell(5);
+                    row8.Cells[5].SetCellValue("用量");
+                    row8.Cells[5].CellStyle = style;
+
+                    row8.CreateCell(6);
+                    row8.Cells[6].SetCellValue("位号");
+                    row8.Cells[6].CellStyle = style;
+
+                    row8.CreateCell(7); 
+                    row8.Cells[7].SetCellValue("备注");
+                    row8.Cells[7].CellStyle = style;
 
                     i = i + 1;
                     DataRowCount = 8;
@@ -172,6 +217,7 @@ namespace UAS_MES_NEW.DataOperate
                 {
                     if (SheetName != "")
                     {
+
                         ISheet sheet = book.GetSheet(SheetName);
                         IRow row = sheet.CreateRow(DataRowCount);
                         row.CreateCell(0);
@@ -181,6 +227,7 @@ namespace UAS_MES_NEW.DataOperate
                         row.CreateCell(4);
                         row.CreateCell(5);
                         row.CreateCell(6);
+                        row.CreateCell(7);
                         //位置编号
                         CellRangeAddress cellRangeAddress = new CellRangeAddress(DataRowCount, DataRowCount + 1, 0, 0);
                         sheet.AddMergedRegion(cellRangeAddress);
@@ -188,14 +235,31 @@ namespace UAS_MES_NEW.DataOperate
                         CellRangeAddress cellRangeAddress1 = new CellRangeAddress(DataRowCount, DataRowCount + 1, 1, 1);
                         sheet.AddMergedRegion(cellRangeAddress1);
                         row.Cells[0].SetCellValue(DataTable.Rows[i]["STF_MODEL"].ToString());
+                        row.Cells[0].CellStyle = style;
+
                         row.Cells[1].SetCellValue(DataTable.Rows[i]["STF_FEEDER"].ToString());
+                        row.Cells[1].CellStyle = style;
+
                         //物料编号
                         row.Cells[2].SetCellValue(DataTable.Rows[i]["STF_FEEDERNO"].ToString());
+                        row.Cells[2].CellStyle = style;
+
                         row.Cells[3].SetCellValue(DataTable.Rows[i]["STF_LOCATION"].ToString());
+                        row.Cells[3].CellStyle = style;
+
                         row.Cells[4].SetCellValue(DataTable.Rows[i]["pr_orispeccode"].ToString());
+                        row.Cells[4].CellStyle = style;
                         row.Cells[4].CellStyle.WrapText = true;
+
                         row.Cells[5].SetCellValue(DataTable.Rows[i]["bd_baseqty"].ToString());
+                        row.Cells[5].CellStyle = style;
+
                         row.Cells[6].SetCellValue(DataTable.Rows[i]["bd_soncode"].ToString());
+                        row.Cells[6].CellStyle = style;
+
+                        row.Cells[7].SetCellValue("");
+                        row.Cells[7].CellStyle = style;
+
                         row.Cells[4].CellStyle.ShrinkToFit = true;
                         DataRowCount = DataRowCount + 1;
                     }