12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235 |
- using System.IO;
- using System.Data;
- using NPOI.HSSF.UserModel;
- using NPOI.SS.UserModel;
- using NPOI.HSSF.Util;
- using NPOI.XSSF.UserModel;
- using System;
- using UAS_LabelMachine.Entity;
- using UAS_LabelMachine.PublicMethod;
- using System.Collections.Generic;
- using System.Windows.Forms;
- using System.Text.RegularExpressions;
- namespace UAS_LabelMachine
- {
- class ExcelHandler
- {
- DataHelper dh = SystemInf.dh;
-
-
-
- public string ExportExcel(DataTable dt, string FolderPath, string FileName)
- {
-
- MemoryStream ms;
- ms = DataTableToExcel(dt);
-
- string filePath = @FolderPath + "\\" + FileName + ".xls";
- FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
- byte[] data = ms.ToArray();
- fs.Write(data, 0, data.Length);
- fs.Flush();
-
- ms.Dispose();
- fs.Dispose();
- return filePath;
- }
-
-
-
- public string ExportExcel(DataTable firstsdt, DataTable dt, string FolderPath, string FileName, string Type, int PageSize, List<CheckBox> conditionbox)
- {
-
- MemoryStream ms;
- ms = DataTableToExcel1(firstsdt, dt, Type, FileName, PageSize, conditionbox);
-
- string filePath = @FolderPath + "\\" + FileName + ".xls";
- FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
- byte[] data = ms.ToArray();
- fs.Write(data, 0, data.Length);
- fs.Flush();
-
- ms.Dispose();
- fs.Dispose();
- return filePath;
- }
-
-
-
- public void ImportExcel(DataTable DataTable, string TableName)
- {
- int columnNum = DataTable.Columns.Count;
- int rowNum = DataTable.Columns.Count;
- string[] field = new string[columnNum];
- for (int i = 0; i < columnNum; i++)
- {
- field[i] = DataTable.Rows[0][i].ToString();
- }
- }
- public static DataTable ExcelToDataTable(string filePath, bool isColumnName)
- {
- DataTable dataTable = null;
- FileStream fs = null;
- DataColumn column = null;
- DataRow dataRow = null;
- IWorkbook workbook = null;
- ISheet sheet = null;
- IRow row = null;
- ICell cell = null;
- int startRow = 0;
- try
- {
- using (fs = File.OpenRead(filePath))
- {
-
- if (filePath.IndexOf(".xlsx") > 0)
- {
- workbook = new XSSFWorkbook(fs);
- }
-
- else if (filePath.IndexOf(".xls") > 0)
- {
- workbook = new HSSFWorkbook(fs);
- }
- if (workbook != null)
- {
- sheet = workbook.GetSheetAt(0);
- dataTable = new DataTable();
- if (sheet != null)
- {
- int rowCount = sheet.LastRowNum;
- if (rowCount > 0)
- {
- IRow firstRow = sheet.GetRow(0);
- int cellCount = firstRow.LastCellNum;
-
- if (isColumnName)
- {
- startRow = 1;
- for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
- {
- cell = firstRow.GetCell(i);
- if (cell != null)
- {
- if (cell.StringCellValue != null)
- {
- column = new DataColumn(cell.StringCellValue);
- dataTable.Columns.Add(column);
- }
- }
- }
- }
- else
- {
- for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
- {
- column = new DataColumn("column" + (i + 1));
- dataTable.Columns.Add(column);
- }
- }
-
- for (int i = startRow; i <= rowCount; ++i)
- {
- row = sheet.GetRow(i);
- if (row == null) continue;
- dataRow = dataTable.NewRow();
- for (int j = row.FirstCellNum; j < cellCount; ++j)
- {
- cell = row.GetCell(j);
- if (cell == null)
- {
- dataRow[j] = "";
- }
- else
- {
-
- switch (cell.CellType)
- {
- case CellType.Blank:
- dataRow[j] = "";
- break;
- case CellType.Numeric:
- short format = cell.CellStyle.DataFormat;
-
- if (format == 14 || format == 31 || format == 57 || format == 58)
- dataRow[j] = cell.DateCellValue;
- else
- dataRow[j] = cell.NumericCellValue;
- break;
- case CellType.String:
- dataRow[j] = cell.StringCellValue;
- break;
- }
- }
- }
- dataTable.Rows.Add(dataRow);
- }
- }
- }
- }
- }
- return dataTable;
- }
- catch (Exception)
- {
- if (fs != null)
- {
- fs.Close();
- }
- return null;
- }
- }
- int RowHeight = 11;
-
-
-
-
-
- public MemoryStream DataTableToExcel(DataTable DataTable)
- {
-
- MemoryStream ms = new MemoryStream();
-
- HSSFWorkbook book = new HSSFWorkbook();
-
- ISheet sheet = book.CreateSheet("sheet1");
-
- int rowNum = DataTable.Rows.Count;
- int columnNum = DataTable.Columns.Count;
-
- for (int i = 0; i < columnNum; i++)
- {
- int dataLength;
-
- if (DataTable.Rows[0][i].ToString().Length < DataTable.Columns[i].ColumnName.Length)
- {
- dataLength = DataTable.Columns[i].ColumnName.Length;
- dataLength = dataLength * 300;
- }
- else
- {
- dataLength = DataTable.Rows[0][i].ToString().Length;
- dataLength = dataLength * 300;
- }
- sheet.SetColumnWidth(i, dataLength);
- }
-
- IRow row = sheet.CreateRow(0);
-
- sheet.CreateFreezePane(0, 1, 0, 1);
- ICellStyle style = book.CreateCellStyle();
- style.FillForegroundColor = HSSFColor.PaleBlue.Index;
- style.FillPattern = FillPattern.BigSpots;
- style.FillBackgroundColor = HSSFColor.LightGreen.Index;
-
- style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
- style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
- style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
- style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
- row.HeightInPoints = 20;
-
-
-
- for (int j = 0; j < columnNum; j++)
- {
- row.CreateCell(j);
- row.Cells[j].CellStyle = style;
- row.Cells[j].CellStyle.VerticalAlignment = VerticalAlignment.Center;
- row.Cells[j].CellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
- row.Cells[j].SetCellValue(DataTable.Columns[j].Caption);
- }
-
-
- for (int i = 0; i < rowNum; i++)
- {
- IRow row1 = sheet.CreateRow(i + 1);
- row1.HeightInPoints = 20;
- for (int j = 0; j < columnNum; j++)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i][j].ToString());
- row1.GetCell(j).CellStyle.VerticalAlignment = VerticalAlignment.Center;
- }
- }
-
- book.Write(ms);
- return ms;
- }
-
-
-
-
-
- public MemoryStream DataTableToExcel1(DataTable FirstDT, DataTable DataTable, string Type,string Inoutno, int PageSize, List<CheckBox> conditionbox)
- {
-
- CheckBox[] box = conditionbox.ToArray();
-
- MemoryStream ms = new MemoryStream();
-
- HSSFWorkbook book = new HSSFWorkbook();
-
- ISheet sheet = book.CreateSheet("分页");
-
- List<string> ch_code = new List<string>();
-
- List<string> pib_outboxcode1 = new List<string>();
- int BoxCode = 1;
- ICellStyle style = book.CreateCellStyle();
- style.VerticalAlignment = VerticalAlignment.Center;
- style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
- ICellStyle styleborder = book.CreateCellStyle();
- styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
- styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
- styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
- styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
- styleborder.VerticalAlignment = VerticalAlignment.Center;
- styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
- string pi_inoutno = "";
-
- for (int i = DataTable.Columns.Count - 1; i > 0; i--)
- {
- for (int j = 0; j < box.Length; j++)
- {
- if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
- {
- if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
- {
- DataTable.Columns.RemoveAt(i);
- break;
- }
- }
- if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
- {
- if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
- {
- DataTable.Columns.RemoveAt(i);
- break;
- }
- }
- if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
- {
- if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
- {
- DataTable.Columns.RemoveAt(i);
- break;
- }
- }
- if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
- {
- if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
- {
- DataTable.Columns.RemoveAt(i);
- break;
- }
- }
- if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
- {
- if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
- {
- DataTable.Columns.RemoveAt(i);
- break;
- }
- }
- if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
- {
- if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
- {
- DataTable.Columns.RemoveAt(i);
- break;
- }
- }
- if (box[j].Name.ToLower() == "percent" && !box[j].Checked)
- {
- if (DataTable.Columns[i].ColumnName.ToLower().Contains("chw_percent1") || DataTable.Columns[i].ColumnName.ToLower().Contains("chw_percent2") || DataTable.Columns[i].ColumnName.ToLower().Contains("chw_itemname1") || DataTable.Columns[i].ColumnName.ToLower().Contains("chw_itemname2"))
- {
- DataTable.Columns.RemoveAt(i);
- break;
- }
- }
- if (box[j].Name.ToLower() == "ts" && !box[j].Checked)
- {
- if (DataTable.Columns[i].ColumnName.ToLower() == ("ts1") || DataTable.Columns[i].ColumnName.ToLower() == ("ts2") || DataTable.Columns[i].ColumnName.ToLower() == ("ts3"))
- {
- DataTable.Columns.RemoveAt(i);
- break;
- }
- }
- if (box[j].Name.ToLower() == "bvceo" && !box[j].Checked)
- {
- if (DataTable.Columns[i].ColumnName.ToLower() == "bvceo1" || DataTable.Columns[i].ColumnName.ToLower() == ("bvceo2") || DataTable.Columns[i].ColumnName.ToLower() == ("bvceo3"))
- {
- DataTable.Columns.RemoveAt(i);
- break;
- }
- }
- }
- }
-
- int rowNum = DataTable.Rows.Count;
- int columnNum = DataTable.Columns.Count;
-
- IRow row = sheet.CreateRow(0);
-
- sheet.CreateFreezePane(0, 1, 0, 1);
-
- row.HeightInPoints = RowHeight;
-
-
-
- row.CreateCell(0);
- row.Cells[0].SetCellValue(" 深爱半导体有限公司芯片出货清单");
- row.GetCell(0).CellStyle = style;
-
- int PaintIndex = 1;
- int sumCount = 0;
- int totalCount = 0;
- switch (Type)
- {
- case "FixRow":
-
- BaseUtil.CleanDataTableData(FirstDT);
-
- string First_OrderCode = "";
- string First_Prspec = "";
- string First_Batch = "";
- ArrayList<string> First_WID = new ArrayList<string>();
- for (int i = 0; i < rowNum; i++)
- {
- IRow row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- row1.HeightInPoints = RowHeight;
-
- if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
- {
- First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
- }
-
- if (DataTable.Columns.Contains("pr_spec1") && !First_Prspec.Contains(DataTable.Rows[i]["pr_spec1"].ToString()))
- {
- First_Prspec += DataTable.Rows[i]["pr_spec1"].ToString() + " ";
- }
-
- if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
- {
- First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
- }
-
- if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
- {
- First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
- }
- if (i / PageSize >= 1 && i % PageSize == 0)
- {
- DataRow dr = FirstDT.NewRow();
- dr["pr_spec"] = DataTable.Rows[i]["pr_spec"].ToString();
- dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
- pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
- dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
- dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
- dr["pd_ordercode"] = First_OrderCode;
- dr["pr_spec1"] = First_Prspec;
- dr["ch_splitbatch"] = First_Batch;
- dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
- dr["num"] = PageSize;
- dr["io_qty"] = sumCount;
- FirstDT.Rows.Add(dr);
- First_OrderCode = "";
- First_Prspec = "";
- First_Batch = "";
- First_WID.Clear();
- BoxCode = BoxCode + 1;
- for (int j = 0; j < columnNum - 4; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("小计");
- }
- else if (j == 2)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(sumCount);
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.Cells[j].CellStyle = styleborder;
- }
- sumCount = 0;
- row1 = sheet.CreateRow(PaintIndex);
- sheet.SetRowBreak(PaintIndex-1);
- PaintIndex = PaintIndex + 1;
- }
-
- if (i % PageSize == 0 || i == rowNum - 1)
- {
-
- if (i != rowNum - 1 || rowNum == 1)
- {
- for (int j = 0; j < columnNum - 3; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_title"].ToString());
- }
- else if (j > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
- }
- else if (columnNum > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.GetCell(j).CellStyle = style;
- }
- row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
-
- for (int j = 0; j < columnNum - 3; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pr_spec"].ToString());
- }
- else if (columnNum > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
- }
- else if (columnNum <= 5 && j == columnNum - 4)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.GetCell(j).CellStyle = style;
- }
-
- row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- for (int j = 4; j < columnNum; j++)
- {
- row1.CreateCell(j - 4);
- row1.Cells[j - 4].CellStyle = styleborder;
- if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
- {
- row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
- }
- else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
- {
- row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
- }
- else
- row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
-
- if (DataTable.Columns[j].ColumnName.ToLower().Contains("chw_itemname") || DataTable.Columns[j].ColumnName.ToLower().Contains("pr_spec") || DataTable.Columns[j].ColumnName.ToLower().Contains("pd_ordercode"))
- {
- sheet.SetColumnHidden(j - 4, true);
- }
- }
- row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- }
- }
-
- for (int j = 4; j < columnNum; j++)
- {
- string Data = DataTable.Rows[i][j].ToString();
- row1.CreateCell(j - 4);
- row1.Cells[j - 4].SetCellValue(Data);
- row1.GetCell(j - 4).CellStyle = styleborder;
- if (DataTable.Columns[j].ColumnName == "io_qty")
- {
- sumCount += int.Parse(DataTable.Rows[i][j].ToString());
- totalCount += int.Parse(DataTable.Rows[i][j].ToString());
- }
- if (DataTable.Columns[j].ColumnName == "rownum")
- {
- row1.Cells[j - 4].SetCellValue(i + 1);
- }
- }
-
- if (i == rowNum - 1)
- {
- DataRow dr = FirstDT.NewRow();
- dr["pr_spec"] = DataTable.Rows[i]["pr_spec"].ToString();
- dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
- dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
- dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
- dr["pd_ordercode"] = First_OrderCode;
- dr["pr_spec1"] = First_Prspec;
- dr["ch_splitbatch"] = First_Batch;
- dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
- dr["num"] = (i % PageSize) + 1;
- dr["io_qty"] = sumCount;
- FirstDT.Rows.Add(dr);
- row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- for (int j = 0; j < columnNum - 4; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("小计");
- }
- else if (j == 2)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(sumCount);
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.Cells[j].CellStyle = styleborder;
- }
- row1 = sheet.CreateRow(PaintIndex);
- for (int j = 0; j < columnNum - 3; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("备注");
- }
- else if (j == 2)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(totalCount);
- }
-
- else if (j == columnNum - 6)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(rowNum);
- }
- else if (j > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("片");
- }
- else if (columnNum > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("片");
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.Cells[j].CellStyle = style;
- }
- sheet.SetRowBreak(PaintIndex);
- PaintIndex = PaintIndex + 1;
- }
- ch_code.Add(DataTable.Rows[i]["ch_code"].ToString());
- pib_outboxcode1.Add(BoxCode.ToString());
- }
- for (int i = 0; i < sheet.LastRowNum; i++)
- {
- if (i != 0)
- {
- sheet.AutoSizeColumn(i);
- sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
- }
- }
- break;
- case "BatchCode":
- string LastBatchCode = "";
- for (int i = 0; i < rowNum; i++)
- {
- IRow row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- row1.HeightInPoints = RowHeight;
-
- if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
- {
- BoxCode = BoxCode + 1;
- for (int j = 0; j < columnNum - 4; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("小计");
- }
- else if (j == 2)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(sumCount);
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.Cells[j].CellStyle = styleborder;
- }
- sumCount = 0;
- row1 = sheet.CreateRow(PaintIndex);
- sheet.SetRowBreak(PaintIndex - 1);
- PaintIndex = PaintIndex + 1;
- }
-
- if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()) || i == rowNum - 1)
- {
- LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
-
- if (i != rowNum - 1)
- {
- for (int j = 0; j < columnNum - 3; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_title"].ToString());
- }
- else if (j == columnNum - 4)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.GetCell(j).CellStyle = style;
- }
- row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
-
- for (int j = 0; j < columnNum - 3; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pr_spec"].ToString());
- }
- else if (j == columnNum - 4)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.GetCell(j).CellStyle = style;
- }
-
- row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- for (int j = 4; j < columnNum; j++)
- {
- row1.CreateCell(j - 4);
- row1.Cells[j - 4].CellStyle = styleborder;
- if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
- {
- row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
- }
- else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
- {
- row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
- }
- else
- row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
- if (DataTable.Columns[j].ColumnName.ToLower().Contains("chw_itemname") || DataTable.Columns[j].ColumnName.ToLower().Contains("pr_spec") || DataTable.Columns[j].ColumnName.ToLower().Contains("pd_ordercode"))
- {
- sheet.SetColumnHidden(j - 4, true);
- }
- }
- row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- }
- }
-
- for (int j = 4; j < columnNum; j++)
- {
- string Data = DataTable.Rows[i][j].ToString();
- row1.CreateCell(j - 4);
- row1.Cells[j - 4].SetCellValue(Data);
- row1.GetCell(j - 4).CellStyle = styleborder;
- if (DataTable.Columns[j].ColumnName == "io_qty")
- {
- sumCount += int.Parse(DataTable.Rows[i][j].ToString());
- totalCount += int.Parse(DataTable.Rows[i][j].ToString());
- }
- if (DataTable.Columns[j].ColumnName == "rownum")
- {
- row1.Cells[j - 4].SetCellValue(i + 1);
- }
- }
- if (i == rowNum - 1)
- {
- row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- for (int j = 0; j < columnNum - 4; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("小计");
- }
- else if (j == 2)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(sumCount);
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.Cells[j].CellStyle = styleborder;
- }
-
- row1 = sheet.CreateRow(PaintIndex);
- for (int j = 0; j < columnNum - 3; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("备注");
- }
- else if (j == 2)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(totalCount);
- }
- else if (j == columnNum - 6)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(rowNum);
- }
- else if (j > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("片");
- }
- else if (columnNum > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("片");
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.Cells[j].CellStyle = style;
- }
- sheet.SetRowBreak(PaintIndex);
- PaintIndex = PaintIndex + 1;
- }
- ch_code.Add(DataTable.Rows[i]["ch_code"].ToString());
- pib_outboxcode1.Add(BoxCode.ToString());
- }
- for (int i = 0; i < sheet.LastRowNum; i++)
- {
- if (i != 0)
- {
- sheet.AutoSizeColumn(i);
- sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
- }
- }
- break;
- case "BoxCode":
- string LastBoxCode = "";
- for (int i = 0; i < rowNum; i++)
- {
- IRow row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- row1.HeightInPoints = RowHeight;
-
- if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
- {
- BoxCode = BoxCode + 1;
- for (int j = 0; j < columnNum - 4; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("小计");
- }
- else if (j == 2)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(sumCount);
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.Cells[j].CellStyle = styleborder;
- }
- sumCount = 0;
- row1 = sheet.CreateRow(PaintIndex);
- sheet.SetRowBreak(PaintIndex - 1);
- PaintIndex = PaintIndex + 1;
- }
-
- if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || i == rowNum - 1)
- {
- LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
-
- if (i != rowNum - 1)
- {
- for (int j = 0; j < columnNum - 3; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_title"].ToString());
- }
- else if (j > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
- }
- else if (columnNum > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.GetCell(j).CellStyle = style;
- }
- row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
-
- for (int j = 0; j < columnNum - 3; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pr_spec"].ToString());
- }
- else if (j > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
- }
- else if (columnNum > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.GetCell(j).CellStyle = style;
- }
-
- row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- for (int j = 4; j < columnNum; j++)
- {
-
- row1.CreateCell(j - 4);
- row1.Cells[j - 4].CellStyle = styleborder;
- if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
- {
- row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
- }
- else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
- {
- row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
- }
- else
- row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
- if (DataTable.Columns[j].ColumnName.ToLower().Contains("chw_itemname") || DataTable.Columns[j].ColumnName.ToLower().Contains("pr_spec") || DataTable.Columns[j].ColumnName.ToLower().Contains("pd_ordercode"))
- {
- sheet.SetColumnHidden(j - 4, true);
- }
- }
- row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- }
- }
-
- for (int j = 4; j < columnNum; j++)
- {
- string Data = DataTable.Rows[i][j].ToString();
- row1.CreateCell(j - 4);
- row1.Cells[j - 4].SetCellValue(Data);
- row1.GetCell(j - 4).CellStyle = styleborder;
- if (DataTable.Columns[j].ColumnName == "io_qty")
- {
- sumCount += int.Parse(DataTable.Rows[i][j].ToString());
- totalCount += int.Parse(DataTable.Rows[i][j].ToString());
- }
- if (DataTable.Columns[j].ColumnName == "rownum")
- {
- row1.Cells[j - 4].SetCellValue(i + 1);
- }
- }
- if (i == rowNum - 1)
- {
- row1 = sheet.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- for (int j = 0; j < columnNum - 4; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("小计");
- }
- else if (j == 2)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(sumCount);
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.Cells[j].CellStyle = styleborder;
- }
- row1 = sheet.CreateRow(PaintIndex);
-
- for (int j = 0; j < columnNum - 3; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("备注");
- }
- else if (j == 2)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(totalCount);
- }
- else if (j == columnNum - 6)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(rowNum);
- }
- else if (j > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("片");
- }
- else if (columnNum > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue("片");
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.Cells[j].CellStyle = style;
- }
- sheet.SetRowBreak(PaintIndex);
- PaintIndex = PaintIndex + 1;
- }
- ch_code.Add(DataTable.Rows[i]["ch_code"].ToString());
- pib_outboxcode1.Add(BoxCode.ToString());
- }
- for (int i = 0; i < sheet.LastRowNum; i++)
- {
- if (i != 0)
- {
- sheet.AutoSizeColumn(i);
- sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
- }
- }
- break;
- default:
- break;
- }
- dh.BatchInsert("update prodiobarcode set pib_outboxcode1=:pib_outboxcode1 where pib_inoutno='"+ Inoutno + "' and pib_custbarcode=:pib_custbarcode",new string[] { "pib_outboxcode1", "pib_custbarcode" },pib_outboxcode1.ToArray(), ch_code.ToArray());
-
- sumCount = 0;
- totalCount = 0;
- PaintIndex = 1;
- ISheet sheet2 = book.CreateSheet("首页");
- row = sheet2.CreateRow(0);
- row.CreateCell(0);
- row.Cells[0].SetCellValue(" 深爱半导体有限公司芯片出货清单");
- row.GetCell(0).CellStyle = style;
- rowNum = FirstDT.Rows.Count;
-
- for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
- {
- for (int j = 0; j < box.Length; j++)
- {
- if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
- {
- if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
- {
- FirstDT.Columns.RemoveAt(i);
- }
- }
- if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
- {
- if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
- {
- FirstDT.Columns.RemoveAt(i);
- }
- }
- if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
- {
- if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
- {
- FirstDT.Columns.RemoveAt(i);
- }
- }
- }
- }
- columnNum = FirstDT.Columns.Count;
- for (int i = 0; i < rowNum; i++)
- {
- IRow row1 = sheet2.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- row1.HeightInPoints = RowHeight;
-
- if (i == 0)
- {
- for (int j = 0; j < columnNum - 3; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(FirstDT.Rows[i]["pi_title"].ToString());
- }
- else if (j > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
- }
- else if (columnNum > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.GetCell(j).CellStyle = style;
- }
- row1 = sheet2.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
-
- for (int j = 0; j < columnNum - 3; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(FirstDT.Rows[i]["pr_spec"].ToString());
- }
- else if (j > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
- }
- else if (columnNum > 5 && j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
- }
- else
- {
- row1.CreateCell(j);
- }
- row1.GetCell(j).CellStyle = style;
- }
- row1 = sheet2.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
-
- for (int j = 4; j < columnNum; j++)
- {
- row1.CreateCell(j - 4);
- row1.Cells[j - 4].CellStyle = styleborder;
- row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
- }
- row1 = sheet2.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- }
-
- for (int j = 4; j < columnNum; j++)
- {
- string Data = FirstDT.Rows[i][j].ToString();
- row1.CreateCell(j - 4);
- row1.Cells[j - 4].SetCellValue(Data);
- row1.GetCell(j - 4).CellStyle = styleborder;
- if (FirstDT.Columns[j].ColumnName == "num")
- {
- sumCount += int.Parse(Data);
- }
- if (FirstDT.Columns[j].ColumnName == "io_qty")
- {
- totalCount += int.Parse(Data);
- }
- }
-
- if (i == rowNum - 1)
- {
- row1 = sheet2.CreateRow(PaintIndex);
- PaintIndex = PaintIndex + 1;
- for (int j = 0; j < columnNum - 4; j++)
- {
- if (j == 0)
- {
- row1.CreateCell(j);
- row1.Cells[j].CellStyle = styleborder;
- row1.Cells[j].SetCellValue("总计");
- }
- else if (j == columnNum - 6)
- {
- row1.CreateCell(j);
- row1.Cells[j].CellStyle = styleborder;
- row1.Cells[j].SetCellValue(sumCount);
- }
- else if (j == columnNum - 5)
- {
- row1.CreateCell(j);
- row1.Cells[j].CellStyle = styleborder;
- row1.Cells[j].SetCellValue(totalCount);
- }
- else
- {
- row1.CreateCell(j);
- row1.Cells[j].CellStyle = styleborder;
- }
- }
- }
- }
- for (int i = 0; i < sheet2.LastRowNum; i++)
- {
- if (i != 0)
- {
- sheet2.AutoSizeColumn(i);
- sheet2.SetColumnWidth(i, sheet2.GetColumnWidth(i) + 1000);
- }
- }
-
- book.Write(ms);
- return ms;
- }
- }
- }
|