ExcelHandler.cs 109 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163
  1. using System.IO;
  2. using System.Data;
  3. using NPOI.HSSF.UserModel;
  4. using NPOI.SS.UserModel;
  5. using NPOI.HSSF.Util;
  6. using NPOI.XSSF.UserModel;
  7. using System;
  8. using UAS_LabelMachine.Entity;
  9. using UAS_LabelMachine.PublicMethod;
  10. using System.Collections.Generic;
  11. using System.Windows.Forms;
  12. using System.Text.RegularExpressions;
  13. namespace UAS_LabelMachine
  14. {
  15. class ExcelHandler
  16. {
  17. DataHelper dh = SystemInf.dh;
  18. /// <summary>
  19. /// 导出Excel,返回文件在客户端的路径
  20. /// </summary>
  21. public string ExportExcel(DataTable dt, string FolderPath, string FileName)
  22. {
  23. //创建一个内存流,用来接收转换成Excel的内容
  24. MemoryStream ms;
  25. ms = DataTableToExcel(dt);
  26. //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
  27. string filePath = @FolderPath + "\\" + FileName + ".xls";
  28. FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  29. byte[] data = ms.ToArray();
  30. fs.Write(data, 0, data.Length);
  31. fs.Flush();
  32. //释放当前Excel文件,否则打开文件的时候会显示文件被占用
  33. ms.Dispose();
  34. fs.Dispose();
  35. return filePath;
  36. }
  37. /// <summary>
  38. /// 导出Excel,返回文件在客户端的路径
  39. /// </summary>
  40. public string ExportExcel_Special(DataTable firstsdt, DataTable dt, string FolderPath, string FileName, string Type, int PageSize, List<CheckBox> conditionbox)
  41. {
  42. //创建一个内存流,用来接收转换成Excel的内容
  43. MemoryStream ms;
  44. ms = DataTableToExcel2(firstsdt, dt, Type, FileName, PageSize, conditionbox);
  45. //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
  46. string filePath = @FolderPath + "\\" + FileName + ".xls";
  47. FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  48. byte[] data = ms.ToArray();
  49. fs.Write(data, 0, data.Length);
  50. fs.Flush();
  51. //释放当前Excel文件,否则打开文件的时候会显示文件被占用
  52. ms.Dispose();
  53. fs.Dispose();
  54. return filePath;
  55. }
  56. /// <summary>
  57. /// 导出Excel,返回文件在客户端的路径
  58. /// </summary>
  59. public string ExportExcel(DataTable firstsdt, DataTable dt, string FolderPath, string FileName, string Type, int PageSize, List<CheckBox> conditionbox)
  60. {
  61. //创建一个内存流,用来接收转换成Excel的内容
  62. MemoryStream ms;
  63. ms = DataTableToExcel1(firstsdt, dt, Type, FileName, PageSize, conditionbox);
  64. //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
  65. string filePath = @FolderPath + "\\" + FileName + ".xls";
  66. FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  67. byte[] data = ms.ToArray();
  68. fs.Write(data, 0, data.Length);
  69. fs.Flush();
  70. //释放当前Excel文件,否则打开文件的时候会显示文件被占用
  71. ms.Dispose();
  72. fs.Dispose();
  73. return filePath;
  74. }
  75. /// <summary>
  76. /// 导入Excel
  77. /// </summary>
  78. public void ImportExcel(DataTable DataTable, string TableName)
  79. {
  80. int columnNum = DataTable.Columns.Count;
  81. int rowNum = DataTable.Columns.Count;
  82. string[] field = new string[columnNum];
  83. for (int i = 0; i < columnNum; i++)
  84. {
  85. field[i] = DataTable.Rows[0][i].ToString();
  86. }
  87. }
  88. public static DataTable ExcelToDataTable(string filePath, bool isColumnName)
  89. {
  90. DataTable dataTable = null;
  91. FileStream fs = null;
  92. DataColumn column = null;
  93. DataRow dataRow = null;
  94. IWorkbook workbook = null;
  95. ISheet sheet = null;
  96. IRow row = null;
  97. ICell cell = null;
  98. int startRow = 0;
  99. try
  100. {
  101. using (fs = File.OpenRead(filePath))
  102. {
  103. // 2007版本
  104. if (filePath.IndexOf(".xlsx") > 0)
  105. {
  106. workbook = new XSSFWorkbook(fs);
  107. }
  108. // 2003版本
  109. else if (filePath.IndexOf(".xls") > 0)
  110. {
  111. workbook = new HSSFWorkbook(fs);
  112. }
  113. if (workbook != null)
  114. {
  115. sheet = workbook.GetSheetAt(0);//读取第一个sheet,当然也可以循环读取每个sheet
  116. dataTable = new DataTable();
  117. if (sheet != null)
  118. {
  119. int rowCount = sheet.LastRowNum;//总行数
  120. if (rowCount > 0)
  121. {
  122. IRow firstRow = sheet.GetRow(0);//第一行
  123. int cellCount = firstRow.LastCellNum;//列数
  124. //构建datatable的列
  125. if (isColumnName)
  126. {
  127. startRow = 1;//如果第一行是列名,则从第二行开始读取
  128. for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
  129. {
  130. cell = firstRow.GetCell(i);
  131. if (cell != null)
  132. {
  133. if (cell.StringCellValue != null)
  134. {
  135. column = new DataColumn(cell.StringCellValue);
  136. dataTable.Columns.Add(column);
  137. }
  138. }
  139. }
  140. }
  141. else
  142. {
  143. for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
  144. {
  145. column = new DataColumn("column" + (i + 1));
  146. dataTable.Columns.Add(column);
  147. }
  148. }
  149. //填充行
  150. for (int i = startRow; i <= rowCount; ++i)
  151. {
  152. row = sheet.GetRow(i);
  153. if (row == null) continue;
  154. dataRow = dataTable.NewRow();
  155. for (int j = row.FirstCellNum; j < cellCount; ++j)
  156. {
  157. cell = row.GetCell(j);
  158. if (cell == null)
  159. {
  160. dataRow[j] = "";
  161. }
  162. else
  163. {
  164. //CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
  165. switch (cell.CellType)
  166. {
  167. case CellType.Blank:
  168. dataRow[j] = "";
  169. break;
  170. case CellType.Numeric:
  171. short format = cell.CellStyle.DataFormat;
  172. //对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
  173. if (format == 14 || format == 31 || format == 57 || format == 58)
  174. dataRow[j] = cell.DateCellValue;
  175. else
  176. dataRow[j] = cell.NumericCellValue;
  177. break;
  178. case CellType.String:
  179. dataRow[j] = cell.StringCellValue;
  180. break;
  181. }
  182. }
  183. }
  184. dataTable.Rows.Add(dataRow);
  185. }
  186. }
  187. }
  188. }
  189. }
  190. return dataTable;
  191. }
  192. catch (Exception)
  193. {
  194. if (fs != null)
  195. {
  196. fs.Close();
  197. }
  198. return null;
  199. }
  200. }
  201. int RowHeight = 12;
  202. /// <summary>
  203. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  204. /// </summary>
  205. /// <param name="DataTable"></param>
  206. /// <returns></returns>
  207. public MemoryStream DataTableToExcel(DataTable DataTable)
  208. {
  209. //创建内存流
  210. MemoryStream ms = new MemoryStream();
  211. //创建一个Book,相当于一个Excel文件
  212. HSSFWorkbook book = new HSSFWorkbook();
  213. //Excel中的Sheet
  214. ISheet sheet = book.CreateSheet("sheet1");
  215. //获取行数量和列数量
  216. int rowNum = DataTable.Rows.Count;
  217. int columnNum = DataTable.Columns.Count;
  218. //设置列的宽度,根据首行的列的内容的长度来设置
  219. for (int i = 0; i < columnNum; i++)
  220. {
  221. int dataLength;
  222. //如果内容比标题短则取标题长度
  223. if (DataTable.Rows[0][i].ToString().Length < DataTable.Columns[i].ColumnName.Length)
  224. {
  225. dataLength = DataTable.Columns[i].ColumnName.Length;
  226. dataLength = dataLength * 300;
  227. }
  228. else
  229. {
  230. dataLength = DataTable.Rows[0][i].ToString().Length;
  231. dataLength = dataLength * 300;
  232. }
  233. sheet.SetColumnWidth(i, dataLength);
  234. }
  235. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  236. IRow row = sheet.CreateRow(0);
  237. //冻结第一行
  238. sheet.CreateFreezePane(0, 1, 0, 1);
  239. ICellStyle style = book.CreateCellStyle();
  240. style.FillForegroundColor = HSSFColor.PaleBlue.Index;
  241. style.FillPattern = FillPattern.BigSpots;
  242. style.FillBackgroundColor = HSSFColor.LightGreen.Index;
  243. //设置边框
  244. style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  245. style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  246. style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  247. style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  248. row.HeightInPoints = 20;
  249. //固定第一行
  250. //row.RowStyle.IsLocked=true;
  251. //给第一行的标签赋值样式和值
  252. for (int j = 0; j < columnNum; j++)
  253. {
  254. row.CreateCell(j);
  255. row.Cells[j].CellStyle = style;
  256. row.Cells[j].CellStyle.VerticalAlignment = VerticalAlignment.Center;
  257. row.Cells[j].CellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  258. row.Cells[j].SetCellValue(DataTable.Columns[j].Caption);
  259. }
  260. //将DataTable的值循环赋值给book,Aligment设置居中
  261. //之前已经画了带颜色的第一行,所以从i=1开始画
  262. for (int i = 0; i < rowNum; i++)
  263. {
  264. IRow row1 = sheet.CreateRow(i + 1);
  265. row1.HeightInPoints = 20;
  266. for (int j = 0; j < columnNum; j++)
  267. {
  268. row1.CreateCell(j);
  269. row1.Cells[j].SetCellValue(DataTable.Rows[i][j].ToString());
  270. row1.GetCell(j).CellStyle.VerticalAlignment = VerticalAlignment.Center;
  271. }
  272. }
  273. //将book的内容写入内存流中返回
  274. book.Write(ms);
  275. return ms;
  276. }
  277. /// <summary>
  278. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  279. /// </summary>
  280. /// <param name="DataTable"></param>
  281. /// <returns></returns>
  282. public MemoryStream DataTableToExcel1(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  283. {
  284. //转换为序列
  285. CheckBox[] box = conditionbox.ToArray();
  286. //创建内存流
  287. MemoryStream ms = new MemoryStream();
  288. //创建一个Book,相当于一个Excel文件
  289. HSSFWorkbook book = new HSSFWorkbook();
  290. //Excel中的Sheet
  291. ISheet sheet = book.CreateSheet("分页");
  292. sheet.SetMargin(MarginType.TopMargin, 0.4);
  293. sheet.SetMargin(MarginType.BottomMargin, 0.4);
  294. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  295. sheet.SetMargin(MarginType.RightMargin, 0.4);
  296. //芯片号需要作为更新盒号的条件
  297. HSSFFont ffont = (HSSFFont)book.CreateFont();
  298. ffont.FontName = "宋体";
  299. bool ShowChcode = true;
  300. //更新箱号
  301. List<string> pib_id = new List<string>();
  302. //系统打印箱号
  303. List<string> pib_outboxcode1 = new List<string>();
  304. int BoxCode = 1;
  305. ICellStyle style = book.CreateCellStyle();
  306. style.VerticalAlignment = VerticalAlignment.Center;
  307. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  308. style.SetFont(ffont);
  309. ICellStyle styleborder = book.CreateCellStyle();
  310. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  311. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  312. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  313. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  314. styleborder.VerticalAlignment = VerticalAlignment.Center;
  315. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  316. styleborder.SetFont(ffont);
  317. string pi_inoutno = "";
  318. List<string> NotShowColumn = new List<string>();
  319. NotShowColumn.Add("ch_level");
  320. NotShowColumn.Add("pib_id");
  321. NotShowColumn.Add("chw_itemname1");
  322. NotShowColumn.Add("chw_itemname2");
  323. NotShowColumn.Add("pd_ordercode");
  324. NotShowColumn.Add("pr_size");
  325. NotShowColumn.Add("me_desc");
  326. NotShowColumn.Add("pr_orispeccode1");
  327. NotShowColumn.Add("pi_title");
  328. //展示的内容列
  329. int ShowColumnsCount = 0;
  330. //设置列的宽度,根据首行的列的内容的长度来设置
  331. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  332. {
  333. //统计显示的列数
  334. if (!NotShowColumn.Contains(DataTable.Columns[i].ColumnName.ToLower()))
  335. {
  336. ShowColumnsCount = ShowColumnsCount + 1;
  337. }
  338. for (int j = 0; j < box.Length; j++)
  339. {
  340. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  341. {
  342. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  343. {
  344. DataTable.Columns.RemoveAt(i);
  345. break;
  346. }
  347. }
  348. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  349. {
  350. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  351. {
  352. ShowChcode = true;
  353. break;
  354. }
  355. }
  356. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  357. {
  358. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  359. {
  360. DataTable.Columns.RemoveAt(i);
  361. break;
  362. }
  363. }
  364. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  365. {
  366. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  367. {
  368. DataTable.Columns.RemoveAt(i);
  369. break;
  370. }
  371. }
  372. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  373. {
  374. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  375. {
  376. DataTable.Columns.RemoveAt(i);
  377. break;
  378. }
  379. }
  380. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  381. {
  382. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  383. {
  384. DataTable.Columns.RemoveAt(i);
  385. break;
  386. }
  387. }
  388. }
  389. }
  390. //获取行数量和列数量
  391. int rowNum = DataTable.Rows.Count;
  392. int columnNum = DataTable.Columns.Count;
  393. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  394. IRow row = sheet.CreateRow(0);
  395. //冻结第一行
  396. sheet.CreateFreezePane(0, 1, 0, 1);
  397. row.HeightInPoints = RowHeight;
  398. //固定第一行
  399. //row.RowStyle.IsLocked=true;
  400. //给第一行的标签赋值样式和值
  401. // ffont.FontHeight = 13;
  402. row.CreateCell(0);
  403. row.Cells[0].SetCellValue(" 深爱半导体股份有限公司芯片出货清单");
  404. row.GetCell(0).CellStyle.SetFont((ffont));
  405. //ffont.FontHeight = 10;
  406. //开始绘制的Index
  407. int PaintIndex = 1;
  408. int sumCount = 0;
  409. int totalCount = 0;
  410. switch (Type)
  411. {
  412. case "FixRow":
  413. //清理系统取出来的数据
  414. BaseUtil.CleanDataTableData(FirstDT);
  415. //首页参数拼接
  416. string First_OrderCode = "";
  417. string First_Prspec = "";
  418. string First_Batch = "";
  419. int NumIndex = 0;
  420. ArrayList<string> First_WID = new ArrayList<string>();
  421. for (int i = 0; i < rowNum; i++)
  422. {
  423. IRow row1 = sheet.CreateRow(PaintIndex);
  424. PaintIndex = PaintIndex + 1;
  425. row1.HeightInPoints = RowHeight;
  426. //不包含的订单号
  427. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  428. {
  429. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  430. }
  431. //不包含的物料型号
  432. if (DataTable.Columns.Contains("pr_orispeccode1") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode1"].ToString()))
  433. {
  434. First_Prspec += DataTable.Rows[i]["pr_orispeccode1"].ToString() + " ";
  435. }
  436. //不包含扩撒批号
  437. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  438. {
  439. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  440. }
  441. //不包含Wafer_id
  442. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  443. {
  444. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  445. }
  446. if (i / PageSize >= 1 && i % PageSize == 0)
  447. {
  448. DataRow dr = FirstDT.NewRow();
  449. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  450. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  451. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  452. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  453. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  454. dr["pd_ordercode"] = First_OrderCode;
  455. dr["pr_orispeccode1"] = First_Prspec;
  456. dr["ch_splitbatch"] = First_Batch;
  457. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  458. dr["num"] = PageSize;
  459. dr["io_qty"] = sumCount;
  460. FirstDT.Rows.Add(dr);
  461. First_OrderCode = "";
  462. First_Prspec = "";
  463. First_Batch = "";
  464. First_WID.Clear();
  465. BoxCode = BoxCode + 1;
  466. for (int j = 0; j < columnNum - 4; j++)
  467. {
  468. row1.CreateCell(j);
  469. if (j == 0)
  470. {
  471. row1.Cells[j].SetCellValue("小计");
  472. }
  473. else if (DataTable.Columns[j].ColumnName == "io_qty")
  474. {
  475. row1.Cells[NumIndex - 4].SetCellValue(sumCount);
  476. }
  477. row1.Cells[j].CellStyle = styleborder;
  478. }
  479. sumCount = 0;
  480. row1 = sheet.CreateRow(PaintIndex);
  481. sheet.SetRowBreak(PaintIndex - 1);
  482. sheet.Footer.Center = "第&P页,共&N页";
  483. PaintIndex = PaintIndex + 1;
  484. }
  485. //每次到了页数开始分页
  486. if (i % PageSize == 0 || i == rowNum - 1)
  487. {
  488. //第一行添加客户信息 rownum只有一行的情
  489. if (i != rowNum - 1 || rowNum == 1)
  490. {
  491. for (int j = 0; j < columnNum - 3; j++)
  492. {
  493. if (j == 0)
  494. {
  495. row1.CreateCell(j);
  496. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_title"].ToString() + " " + DataTable.Rows[i]["ch_level"].ToString());
  497. }
  498. else if (columnNum > 14 && j == columnNum - 14)
  499. {
  500. row1.CreateCell(j);
  501. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
  502. }
  503. else
  504. {
  505. row1.CreateCell(j);
  506. }
  507. row1.GetCell(j).CellStyle = style;
  508. }
  509. row1 = sheet.CreateRow(PaintIndex);
  510. PaintIndex = PaintIndex + 1;
  511. //第二行添加型号
  512. for (int j = 0; j < columnNum - 3; j++)
  513. {
  514. if (j == 0)
  515. {
  516. row1.CreateCell(j);
  517. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pr_orispeccode"].ToString() + DataTable.Rows[i]["me_desc"].ToString() + DataTable.Rows[i]["pr_size"].ToString());
  518. }
  519. else if (columnNum > 14 && j == columnNum - 14)
  520. {
  521. row1.CreateCell(j);
  522. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
  523. }
  524. else
  525. {
  526. row1.CreateCell(j);
  527. }
  528. row1.GetCell(j).CellStyle = style;
  529. }
  530. //添加列名
  531. row1 = sheet.CreateRow(PaintIndex);
  532. PaintIndex = PaintIndex + 1;
  533. //计数列所在的索引
  534. for (int j = 4; j < columnNum; j++)
  535. {
  536. row1.CreateCell(j - 4);
  537. row1.Cells[j - 4].CellStyle = styleborder;
  538. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  539. {
  540. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  541. }
  542. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  543. {
  544. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  545. }
  546. else
  547. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  548. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  549. {
  550. NumIndex = j;
  551. }
  552. //如果chw_itemname1的值为空,则值为100和0,其中一列不显示,不显示
  553. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())) || (!ShowChcode && DataTable.Columns[j].ColumnName.ToLower().Contains("ch_code")))
  554. {
  555. sheet.SetColumnHidden(j - 4, true);
  556. }
  557. }
  558. row1 = sheet.CreateRow(PaintIndex);
  559. PaintIndex = PaintIndex + 1;
  560. }
  561. }
  562. //添加数据内容
  563. for (int j = 4; j < columnNum; j++)
  564. {
  565. string Data = DataTable.Rows[i][j].ToString();
  566. row1.CreateCell(j - 4);
  567. row1.Cells[j - 4].SetCellValue(Data);
  568. row1.GetCell(j - 4).CellStyle = styleborder;
  569. if (DataTable.Columns[j].ColumnName == "io_qty")
  570. {
  571. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  572. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  573. }
  574. if (DataTable.Columns[j].ColumnName == "rownum")
  575. {
  576. row1.Cells[j - 4].SetCellValue(i + 1);
  577. }
  578. }
  579. //固定行号分组的时候自动拼接新的DataTable
  580. if (i == rowNum - 1)
  581. {
  582. DataRow dr = FirstDT.NewRow();
  583. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  584. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  585. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  586. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  587. dr["pd_ordercode"] = First_OrderCode;
  588. dr["pr_orispeccode1"] = First_Prspec;
  589. dr["ch_splitbatch"] = First_Batch;
  590. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  591. dr["num"] = (i % PageSize) + 1;
  592. dr["io_qty"] = sumCount;
  593. FirstDT.Rows.Add(dr);
  594. row1 = sheet.CreateRow(PaintIndex);
  595. PaintIndex = PaintIndex + 1;
  596. for (int j = 0; j < columnNum - 4; j++)
  597. {
  598. row1.CreateCell(j);
  599. if (j == 0)
  600. {
  601. row1.Cells[j].SetCellValue("小计");
  602. }
  603. else if (DataTable.Columns[j].ColumnName == "io_qty")
  604. {
  605. row1.Cells[j - 4].SetCellValue(sumCount);
  606. }
  607. row1.Cells[j].CellStyle = styleborder;
  608. }
  609. row1 = sheet.CreateRow(PaintIndex);
  610. for (int j = 0; j < columnNum - 3; j++)
  611. {
  612. if (j == 0)
  613. {
  614. row1.CreateCell(j);
  615. row1.Cells[j].SetCellValue("备注");
  616. }
  617. else if (j == 2)
  618. {
  619. row1.CreateCell(j);
  620. row1.Cells[j].SetCellValue(totalCount);
  621. }
  622. //原本是j == columnNum - 5因为还有spec和order两列隐藏列,所以需要在往后移动
  623. else if (j == columnNum - 6)
  624. {
  625. row1.CreateCell(j);
  626. row1.Cells[j].SetCellValue(rowNum);
  627. }
  628. else if (j > 5 && j == columnNum - 5)
  629. {
  630. row1.CreateCell(j);
  631. row1.Cells[j].SetCellValue("片");
  632. }
  633. else if (columnNum > 5 && j == columnNum - 5)
  634. {
  635. row1.CreateCell(j);
  636. row1.Cells[j].SetCellValue("片");
  637. }
  638. else
  639. {
  640. row1.CreateCell(j);
  641. }
  642. row1.Cells[j].CellStyle = style;
  643. }
  644. sheet.SetRowBreak(PaintIndex);
  645. sheet.Footer.Center = "第&P页,共&N页";
  646. PaintIndex = PaintIndex + 1;
  647. }
  648. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  649. pib_outboxcode1.Add(BoxCode.ToString());
  650. }
  651. for (int i = 0; i < sheet.LastRowNum; i++)
  652. {
  653. if (i != 0)
  654. {
  655. sheet.AutoSizeColumn(i);
  656. sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  657. }
  658. }
  659. break;
  660. case "BatchCode":
  661. string LastBatchCode = "";
  662. for (int i = 0; i < rowNum; i++)
  663. {
  664. IRow row1 = sheet.CreateRow(PaintIndex);
  665. PaintIndex = PaintIndex + 1;
  666. row1.HeightInPoints = RowHeight;
  667. //如果批号不相等的时候
  668. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  669. {
  670. BoxCode = BoxCode + 1;
  671. for (int j = 0; j < columnNum - 4; j++)
  672. {
  673. row1.CreateCell(j);
  674. if (j == 0)
  675. {
  676. row1.Cells[j].SetCellValue("小计");
  677. }
  678. else if (DataTable.Columns[j].ColumnName == "io_qty")
  679. {
  680. row1.Cells[j - 4].SetCellValue(sumCount);
  681. }
  682. row1.Cells[j].CellStyle = styleborder;
  683. }
  684. sumCount = 0;
  685. row1 = sheet.CreateRow(PaintIndex);
  686. sheet.SetRowBreak(PaintIndex - 1);
  687. sheet.Footer.Center = "第&P页,共&N页";
  688. PaintIndex = PaintIndex + 1;
  689. }
  690. //每次到了页数开始分页
  691. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()) || i == rowNum - 1)
  692. {
  693. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  694. //第一行添加客户信息
  695. if (i != rowNum - 1)
  696. {
  697. for (int j = 0; j < columnNum - 3; j++)
  698. {
  699. if (j == 0)
  700. {
  701. row1.CreateCell(j);
  702. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_title"].ToString() + " " + DataTable.Rows[i]["ch_level"].ToString());
  703. }
  704. else if (columnNum > 14 && j == columnNum - 14)
  705. {
  706. row1.CreateCell(j);
  707. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
  708. }
  709. else
  710. {
  711. row1.CreateCell(j);
  712. }
  713. row1.GetCell(j).CellStyle = style;
  714. }
  715. row1 = sheet.CreateRow(PaintIndex);
  716. PaintIndex = PaintIndex + 1;
  717. //第二行添加型号
  718. for (int j = 0; j < columnNum - 3; j++)
  719. {
  720. if (j == 0)
  721. {
  722. row1.CreateCell(j);
  723. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pr_orispeccode"].ToString() + DataTable.Rows[i]["me_desc"].ToString() + DataTable.Rows[i]["pr_size"].ToString());
  724. }
  725. else if (columnNum > 14 && j == columnNum - 14)
  726. {
  727. row1.CreateCell(j);
  728. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
  729. }
  730. else
  731. {
  732. row1.CreateCell(j);
  733. }
  734. row1.GetCell(j).CellStyle = style;
  735. }
  736. //添加列名
  737. row1 = sheet.CreateRow(PaintIndex);
  738. PaintIndex = PaintIndex + 1;
  739. for (int j = 4; j < columnNum; j++)
  740. {
  741. row1.CreateCell(j - 4);
  742. row1.Cells[j - 4].CellStyle = styleborder;
  743. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  744. {
  745. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  746. }
  747. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  748. {
  749. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  750. }
  751. else
  752. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  753. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())) || (!ShowChcode && DataTable.Columns[j].ColumnName.ToLower().Contains("ch_code")))
  754. {
  755. sheet.SetColumnHidden(j - 4, true);
  756. }
  757. }
  758. row1 = sheet.CreateRow(PaintIndex);
  759. PaintIndex = PaintIndex + 1;
  760. }
  761. }
  762. //添加数据内容
  763. for (int j = 4; j < columnNum; j++)
  764. {
  765. string Data = DataTable.Rows[i][j].ToString();
  766. row1.CreateCell(j - 4);
  767. row1.Cells[j - 4].SetCellValue(Data);
  768. row1.GetCell(j - 4).CellStyle = styleborder;
  769. if (DataTable.Columns[j].ColumnName == "io_qty")
  770. {
  771. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  772. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  773. }
  774. if (DataTable.Columns[j].ColumnName == "rownum")
  775. {
  776. row1.Cells[j - 4].SetCellValue(i + 1);
  777. }
  778. }
  779. if (i == rowNum - 1)
  780. {
  781. row1 = sheet.CreateRow(PaintIndex);
  782. PaintIndex = PaintIndex + 1;
  783. for (int j = 0; j < columnNum - 4; j++)
  784. {
  785. row1.CreateCell(j);
  786. if (j == 0)
  787. {
  788. row1.Cells[j].SetCellValue("小计");
  789. }
  790. else if (DataTable.Columns[j].ColumnName == "io_qty")
  791. {
  792. row1.Cells[j - 4].SetCellValue(sumCount);
  793. }
  794. row1.Cells[j].CellStyle = styleborder;
  795. }
  796. //创建备注内容
  797. row1 = sheet.CreateRow(PaintIndex);
  798. for (int j = 0; j < columnNum - 3; j++)
  799. {
  800. if (j == 0)
  801. {
  802. row1.CreateCell(j);
  803. row1.Cells[j].SetCellValue("备注");
  804. }
  805. else if (j == 2)
  806. {
  807. row1.CreateCell(j);
  808. row1.Cells[j].SetCellValue(totalCount);
  809. }
  810. else if (j == columnNum - 6)
  811. {
  812. row1.CreateCell(j);
  813. row1.Cells[j].SetCellValue(rowNum);
  814. }
  815. else if (j > 5 && j == columnNum - 5)
  816. {
  817. row1.CreateCell(j);
  818. row1.Cells[j].SetCellValue("片");
  819. }
  820. else if (columnNum > 5 && j == columnNum - 5)
  821. {
  822. row1.CreateCell(j);
  823. row1.Cells[j].SetCellValue("片");
  824. }
  825. else
  826. {
  827. row1.CreateCell(j);
  828. }
  829. row1.Cells[j].CellStyle = style;
  830. }
  831. sheet.SetRowBreak(PaintIndex);
  832. sheet.Footer.Center = "第&P页,共&N页";
  833. PaintIndex = PaintIndex + 1;
  834. }
  835. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  836. pib_outboxcode1.Add(BoxCode.ToString());
  837. }
  838. for (int i = 0; i < sheet.LastRowNum; i++)
  839. {
  840. if (i != 0)
  841. {
  842. sheet.AutoSizeColumn(i);
  843. sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  844. }
  845. }
  846. break;
  847. case "BoxCode":
  848. string LastBoxCode = "";
  849. for (int i = 0; i < rowNum; i++)
  850. {
  851. IRow row1 = sheet.CreateRow(PaintIndex);
  852. PaintIndex = PaintIndex + 1;
  853. row1.HeightInPoints = RowHeight;
  854. //如果批号不相等的时候
  855. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  856. {
  857. BoxCode = BoxCode + 1;
  858. for (int j = 0; j < columnNum - 4; j++)
  859. {
  860. row1.CreateCell(j);
  861. if (j == 0)
  862. {
  863. row1.Cells[j].SetCellValue("小计");
  864. }
  865. else if (DataTable.Columns[j].ColumnName == "io_qty")
  866. {
  867. row1.Cells[j - 4].SetCellValue(sumCount);
  868. }
  869. row1.Cells[j].CellStyle = styleborder;
  870. }
  871. sumCount = 0;
  872. row1 = sheet.CreateRow(PaintIndex);
  873. sheet.SetRowBreak(PaintIndex - 1);
  874. sheet.Footer.Center = "第&P页,共&N页";
  875. PaintIndex = PaintIndex + 1;
  876. }
  877. //每次到了页数开始分页
  878. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || i == rowNum - 1)
  879. {
  880. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  881. //第一行添加客户信息
  882. if (i != rowNum - 1)
  883. {
  884. for (int j = 0; j < columnNum - 3; j++)
  885. {
  886. if (j == 0)
  887. {
  888. row1.CreateCell(j);
  889. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_title"].ToString() + " " + DataTable.Rows[i]["ch_level"].ToString());
  890. }
  891. else if (columnNum > 14 && j == columnNum - 14)
  892. {
  893. row1.CreateCell(j);
  894. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
  895. }
  896. else
  897. {
  898. row1.CreateCell(j);
  899. }
  900. row1.GetCell(j).CellStyle = style;
  901. }
  902. row1 = sheet.CreateRow(PaintIndex);
  903. PaintIndex = PaintIndex + 1;
  904. //第二行添加型号
  905. for (int j = 0; j < columnNum - 3; j++)
  906. {
  907. if (j == 0)
  908. {
  909. row1.CreateCell(j);
  910. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pr_orispeccode"].ToString() + DataTable.Rows[i]["me_desc"].ToString() + DataTable.Rows[i]["pr_size"].ToString());
  911. }
  912. else if (columnNum > 14 && j == columnNum - 14)
  913. {
  914. row1.CreateCell(j);
  915. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
  916. }
  917. else
  918. {
  919. row1.CreateCell(j);
  920. }
  921. row1.GetCell(j).CellStyle = style;
  922. }
  923. //添加列名
  924. row1 = sheet.CreateRow(PaintIndex);
  925. PaintIndex = PaintIndex + 1;
  926. for (int j = 4; j < columnNum; j++)
  927. {
  928. //设定固定的列名
  929. row1.CreateCell(j - 4);
  930. row1.Cells[j - 4].CellStyle = styleborder;
  931. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  932. {
  933. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  934. }
  935. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  936. {
  937. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  938. }
  939. else
  940. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  941. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())) || (!ShowChcode && DataTable.Columns[j].ColumnName.ToLower().Contains("ch_code")))
  942. {
  943. sheet.SetColumnHidden(j - 4, true);
  944. }
  945. }
  946. row1 = sheet.CreateRow(PaintIndex);
  947. PaintIndex = PaintIndex + 1;
  948. }
  949. }
  950. //添加数据内容
  951. for (int j = 4; j < columnNum; j++)
  952. {
  953. string Data = DataTable.Rows[i][j].ToString();
  954. row1.CreateCell(j - 4);
  955. row1.Cells[j - 4].SetCellValue(Data);
  956. row1.GetCell(j - 4).CellStyle = styleborder;
  957. if (DataTable.Columns[j].ColumnName == "io_qty")
  958. {
  959. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  960. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  961. }
  962. if (DataTable.Columns[j].ColumnName == "rownum")
  963. {
  964. row1.Cells[j - 4].SetCellValue(i + 1);
  965. }
  966. }
  967. if (i == rowNum - 1)
  968. {
  969. row1 = sheet.CreateRow(PaintIndex);
  970. PaintIndex = PaintIndex + 1;
  971. for (int j = 0; j < columnNum - 4; j++)
  972. {
  973. row1.CreateCell(j);
  974. if (j == 0)
  975. {
  976. row1.Cells[j].SetCellValue("小计");
  977. }
  978. else if (DataTable.Columns[j].ColumnName == "io_qty")
  979. {
  980. row1.Cells[j - 4].SetCellValue(sumCount);
  981. }
  982. row1.Cells[j].CellStyle = styleborder;
  983. }
  984. row1 = sheet.CreateRow(PaintIndex);
  985. for (int j = 0; j < columnNum - 3; j++)
  986. {
  987. if (j == 0)
  988. {
  989. row1.CreateCell(j);
  990. row1.Cells[j].SetCellValue("备注");
  991. }
  992. else if (j == 2)
  993. {
  994. row1.CreateCell(j);
  995. row1.Cells[j].SetCellValue(totalCount);
  996. }
  997. else if (j == columnNum - 6)
  998. {
  999. row1.CreateCell(j);
  1000. row1.Cells[j].SetCellValue(rowNum);
  1001. }
  1002. else if (j > 5 && j == columnNum - 5)
  1003. {
  1004. row1.CreateCell(j);
  1005. row1.Cells[j].SetCellValue("片");
  1006. }
  1007. else if (columnNum > 5 && j == columnNum - 5)
  1008. {
  1009. row1.CreateCell(j);
  1010. row1.Cells[j].SetCellValue("片");
  1011. }
  1012. else
  1013. {
  1014. row1.CreateCell(j);
  1015. }
  1016. row1.Cells[j].CellStyle = style;
  1017. }
  1018. sheet.SetRowBreak(PaintIndex);
  1019. sheet.Footer.Center = "第&P页,共&N页";
  1020. PaintIndex = PaintIndex + 1;
  1021. }
  1022. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  1023. pib_outboxcode1.Add(BoxCode.ToString());
  1024. }
  1025. for (int i = 0; i < sheet.LastRowNum; i++)
  1026. {
  1027. if (i != 0)
  1028. {
  1029. sheet.AutoSizeColumn(i);
  1030. sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  1031. }
  1032. }
  1033. break;
  1034. default:
  1035. break;
  1036. }
  1037. dh.BatchInsert("update prodiobarcode set pib_outboxcode1=:pib_outboxcode1 where pib_inoutno='" + Inoutno + "' and pib_id=:pib_id", new string[] { "pib_outboxcode1", "pib_id" }, pib_outboxcode1.ToArray(), pib_id.ToArray());
  1038. //删除下载链接再重新插入
  1039. HttpHandler.GenDownLoadLinK(Inoutno);
  1040. //填充首页
  1041. sumCount = 0;
  1042. totalCount = 0;
  1043. PaintIndex = 1;
  1044. ISheet sheet2 = book.CreateSheet("首页");
  1045. row = sheet2.CreateRow(0);
  1046. row.CreateCell(0);
  1047. row.Cells[0].SetCellValue(" 深爱半导体股份有限公司芯片出货清单");
  1048. row.GetCell(0).CellStyle = style;
  1049. rowNum = FirstDT.Rows.Count;
  1050. //不需要显示的列移除
  1051. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  1052. {
  1053. for (int j = 0; j < box.Length; j++)
  1054. {
  1055. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  1056. {
  1057. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  1058. {
  1059. FirstDT.Columns.RemoveAt(i);
  1060. }
  1061. }
  1062. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  1063. {
  1064. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  1065. {
  1066. FirstDT.Columns.RemoveAt(i);
  1067. }
  1068. }
  1069. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  1070. {
  1071. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  1072. {
  1073. FirstDT.Columns.RemoveAt(i);
  1074. }
  1075. }
  1076. }
  1077. }
  1078. columnNum = FirstDT.Columns.Count;
  1079. for (int i = 0; i < rowNum; i++)
  1080. {
  1081. IRow row1 = sheet2.CreateRow(PaintIndex);
  1082. PaintIndex = PaintIndex + 1;
  1083. row1.HeightInPoints = RowHeight;
  1084. //只需要绘制一行
  1085. if (i == 0)
  1086. {
  1087. for (int j = 0; j < columnNum - 3; j++)
  1088. {
  1089. if (j == 0)
  1090. {
  1091. row1.CreateCell(j);
  1092. row1.Cells[j].SetCellValue(FirstDT.Rows[i]["pi_title"].ToString());
  1093. }
  1094. else if (j > 5 && j == columnNum - 5)
  1095. {
  1096. row1.CreateCell(j);
  1097. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
  1098. }
  1099. else if (columnNum > 5 && j == columnNum - 5)
  1100. {
  1101. row1.CreateCell(j);
  1102. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
  1103. }
  1104. else
  1105. {
  1106. row1.CreateCell(j);
  1107. }
  1108. row1.GetCell(j).CellStyle = style;
  1109. }
  1110. row1 = sheet2.CreateRow(PaintIndex);
  1111. PaintIndex = PaintIndex + 1;
  1112. //第二行添加型号
  1113. for (int j = 0; j < columnNum - 3; j++)
  1114. {
  1115. if (j == 0)
  1116. {
  1117. row1.CreateCell(j);
  1118. row1.Cells[j].SetCellValue(FirstDT.Rows[i]["pr_orispeccode"].ToString());
  1119. }
  1120. else if (j > 5 && j == columnNum - 5)
  1121. {
  1122. row1.CreateCell(j);
  1123. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
  1124. }
  1125. else if (columnNum > 5 && j == columnNum - 5)
  1126. {
  1127. row1.CreateCell(j);
  1128. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
  1129. }
  1130. else
  1131. {
  1132. row1.CreateCell(j);
  1133. }
  1134. row1.GetCell(j).CellStyle = style;
  1135. }
  1136. row1 = sheet2.CreateRow(PaintIndex);
  1137. PaintIndex = PaintIndex + 1;
  1138. //添加列名
  1139. for (int j = 4; j < columnNum; j++)
  1140. {
  1141. row1.CreateCell(j - 4);
  1142. row1.Cells[j - 4].CellStyle = styleborder;
  1143. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  1144. }
  1145. row1 = sheet2.CreateRow(PaintIndex);
  1146. PaintIndex = PaintIndex + 1;
  1147. }
  1148. //添加数据内容
  1149. for (int j = 4; j < columnNum; j++)
  1150. {
  1151. string Data = FirstDT.Rows[i][j].ToString();
  1152. row1.CreateCell(j - 4);
  1153. row1.Cells[j - 4].SetCellValue(Data);
  1154. row1.GetCell(j - 4).CellStyle = styleborder;
  1155. if (FirstDT.Columns[j].ColumnName == "num")
  1156. {
  1157. sumCount += int.Parse(Data);
  1158. }
  1159. if (FirstDT.Columns[j].ColumnName == "io_qty")
  1160. {
  1161. totalCount += int.Parse(Data);
  1162. }
  1163. }
  1164. //添加总计行
  1165. if (i == rowNum - 1)
  1166. {
  1167. row1 = sheet2.CreateRow(PaintIndex);
  1168. PaintIndex = PaintIndex + 1;
  1169. for (int j = 0; j < columnNum - 4; j++)
  1170. {
  1171. if (j == 0)
  1172. {
  1173. row1.CreateCell(j);
  1174. row1.Cells[j].CellStyle = styleborder;
  1175. row1.Cells[j].SetCellValue("总计");
  1176. }
  1177. else if (j == columnNum - 6)
  1178. {
  1179. row1.CreateCell(j);
  1180. row1.Cells[j].CellStyle = styleborder;
  1181. row1.Cells[j].SetCellValue(sumCount);
  1182. }
  1183. else if (j == columnNum - 5)
  1184. {
  1185. row1.CreateCell(j);
  1186. row1.Cells[j].CellStyle = styleborder;
  1187. row1.Cells[j].SetCellValue(totalCount);
  1188. }
  1189. else
  1190. {
  1191. row1.CreateCell(j);
  1192. row1.Cells[j].CellStyle = styleborder;
  1193. }
  1194. }
  1195. }
  1196. }
  1197. for (int i = 0; i < sheet2.LastRowNum; i++)
  1198. {
  1199. if (i != 0)
  1200. {
  1201. sheet2.AutoSizeColumn(i);
  1202. sheet2.SetColumnWidth(i, sheet2.GetColumnWidth(i) + 1000);
  1203. }
  1204. }
  1205. //将book的内容写入内存流中返回
  1206. book.Write(ms);
  1207. return ms;
  1208. }
  1209. /// <summary>
  1210. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  1211. /// </summary>
  1212. /// <param name="DataTable"></param>
  1213. /// <returns></returns>
  1214. public MemoryStream DataTableToExcel2(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  1215. {
  1216. //转换为序列
  1217. CheckBox[] box = conditionbox.ToArray();
  1218. //创建内存流
  1219. MemoryStream ms = new MemoryStream();
  1220. //创建一个Book,相当于一个Excel文件
  1221. HSSFWorkbook book = new HSSFWorkbook();
  1222. //Excel中的Sheet
  1223. ISheet sheet = book.CreateSheet("分页");
  1224. sheet.SetMargin(MarginType.TopMargin, 0.4);
  1225. sheet.SetMargin(MarginType.BottomMargin, 0.4);
  1226. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  1227. sheet.SetMargin(MarginType.RightMargin, 0.4);
  1228. //芯片号需要作为更新盒号的条件
  1229. HSSFFont ffont = (HSSFFont)book.CreateFont();
  1230. ffont.FontName = "宋体";
  1231. bool ShowChcode = true;
  1232. //更新箱号
  1233. List<string> pib_id = new List<string>();
  1234. //系统打印箱号
  1235. List<string> pib_outboxcode1 = new List<string>();
  1236. int BoxCode = 1;
  1237. ICellStyle style = book.CreateCellStyle();
  1238. style.VerticalAlignment = VerticalAlignment.Center;
  1239. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  1240. style.SetFont(ffont);
  1241. ICellStyle styleborder = book.CreateCellStyle();
  1242. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1243. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1244. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1245. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1246. styleborder.VerticalAlignment = VerticalAlignment.Center;
  1247. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  1248. styleborder.SetFont(ffont);
  1249. string pi_inoutno = "";
  1250. List<string> NotShowColumn = new List<string>();
  1251. NotShowColumn.Add("ch_level");
  1252. NotShowColumn.Add("pib_id");
  1253. NotShowColumn.Add("chw_itemname1");
  1254. NotShowColumn.Add("chw_itemname2");
  1255. NotShowColumn.Add("pd_ordercode");
  1256. NotShowColumn.Add("pr_size");
  1257. NotShowColumn.Add("me_desc");
  1258. NotShowColumn.Add("pr_orispeccode1");
  1259. NotShowColumn.Add("pi_title");
  1260. //展示的内容列
  1261. int ShowColumnsCount = 0;
  1262. //设置列的宽度,根据首行的列的内容的长度来设置
  1263. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  1264. {
  1265. //统计显示的列数
  1266. if (!NotShowColumn.Contains(DataTable.Columns[i].ColumnName.ToLower()))
  1267. {
  1268. ShowColumnsCount = ShowColumnsCount + 1;
  1269. }
  1270. for (int j = 0; j < box.Length; j++)
  1271. {
  1272. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  1273. {
  1274. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  1275. {
  1276. DataTable.Columns.RemoveAt(i);
  1277. break;
  1278. }
  1279. }
  1280. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  1281. {
  1282. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  1283. {
  1284. ShowChcode = true;
  1285. break;
  1286. }
  1287. }
  1288. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  1289. {
  1290. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  1291. {
  1292. DataTable.Columns.RemoveAt(i);
  1293. break;
  1294. }
  1295. }
  1296. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  1297. {
  1298. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  1299. {
  1300. DataTable.Columns.RemoveAt(i);
  1301. break;
  1302. }
  1303. }
  1304. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  1305. {
  1306. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  1307. {
  1308. DataTable.Columns.RemoveAt(i);
  1309. break;
  1310. }
  1311. }
  1312. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  1313. {
  1314. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  1315. {
  1316. DataTable.Columns.RemoveAt(i);
  1317. break;
  1318. }
  1319. }
  1320. }
  1321. }
  1322. //获取行数量和列数量
  1323. int rowNum = DataTable.Rows.Count;
  1324. int columnNum = DataTable.Columns.Count;
  1325. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  1326. //ffont.FontHeight = 10;
  1327. //开始绘制的Index
  1328. int PaintIndex = 1;
  1329. int sumCount = 0;
  1330. int totalCount = 0;
  1331. //Title的字体
  1332. HSSFFont titlefont = (HSSFFont)book.CreateFont();
  1333. titlefont.FontName = "宋体";
  1334. titlefont.FontHeight = 270;
  1335. titlefont.Boldweight = (short)FontBoldWeight.Bold;
  1336. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  1337. ColumnTitle.FontName = "宋体";
  1338. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  1339. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  1340. ColumnTitleStyle.SetFont(ColumnTitle);
  1341. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1342. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1343. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1344. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1345. ICellStyle TitleStyle = book.CreateCellStyle();
  1346. TitleStyle.SetFont(titlefont);
  1347. switch (Type)
  1348. {
  1349. case "FixRow":
  1350. //清理系统取出来的数据
  1351. BaseUtil.CleanDataTableData(FirstDT);
  1352. //首页参数拼接
  1353. string First_OrderCode = "";
  1354. string First_Prspec = "";
  1355. string First_Batch = "";
  1356. int NumIndex = 0;
  1357. ArrayList<string> First_WID = new ArrayList<string>();
  1358. for (int i = 0; i < rowNum; i++)
  1359. {
  1360. IRow row1 = null;
  1361. if (PaintIndex != 1)
  1362. {
  1363. row1 = sheet.CreateRow(PaintIndex);
  1364. PaintIndex = PaintIndex + 1;
  1365. row1.HeightInPoints = RowHeight;
  1366. }
  1367. //不包含的订单号
  1368. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  1369. {
  1370. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  1371. }
  1372. //不包含的物料型号
  1373. if (DataTable.Columns.Contains("pr_orispeccode1") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode1"].ToString()))
  1374. {
  1375. First_Prspec += DataTable.Rows[i]["pr_orispeccode1"].ToString() + " ";
  1376. }
  1377. //不包含扩撒批号
  1378. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  1379. {
  1380. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  1381. }
  1382. //不包含Wafer_id
  1383. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  1384. {
  1385. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  1386. }
  1387. if (i / PageSize >= 1 && i % PageSize == 0)
  1388. {
  1389. DataRow dr = FirstDT.NewRow();
  1390. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  1391. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  1392. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  1393. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  1394. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  1395. dr["pd_ordercode"] = First_OrderCode;
  1396. dr["pr_orispeccode1"] = First_Prspec;
  1397. dr["ch_splitbatch"] = First_Batch;
  1398. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  1399. dr["num"] = PageSize;
  1400. dr["io_qty"] = sumCount;
  1401. FirstDT.Rows.Add(dr);
  1402. First_OrderCode = "";
  1403. First_Prspec = "";
  1404. First_Batch = "";
  1405. First_WID.Clear();
  1406. BoxCode = BoxCode + 1;
  1407. for (int j = 0; j < columnNum - 4; j++)
  1408. {
  1409. row1.CreateCell(j);
  1410. if (j == 0)
  1411. {
  1412. row1.Cells[j].SetCellValue("小计");
  1413. }
  1414. else if (j == 1)
  1415. {
  1416. row1.Cells[1].SetCellValue((i % PageSize == 0 ? PageSize : i) + "片");
  1417. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1418. }
  1419. else if (j == 2)
  1420. {
  1421. row1.Cells[2].SetCellValue(sumCount);
  1422. }
  1423. row1.Cells[j].CellStyle = styleborder;
  1424. }
  1425. sumCount = 0;
  1426. row1 = sheet.CreateRow(PaintIndex);
  1427. sheet.SetRowBreak(PaintIndex - 1);
  1428. sheet.Footer.Center = "第&P页,共&N页";
  1429. PaintIndex = PaintIndex + 1;
  1430. }
  1431. //每次到了页数开始分页
  1432. if (i % PageSize == 0 || i == rowNum - 1)
  1433. {
  1434. //第一行添加客户信息 rownum只有一行的情
  1435. if (i != rowNum - 1 || rowNum == 1)
  1436. {
  1437. //抬头设置
  1438. row1 = sheet.CreateRow(PaintIndex);
  1439. PaintIndex = PaintIndex + 1;
  1440. row1.CreateCell(0).SetCellValue(" 深爱半导体股份有限公司芯片出货清单");
  1441. row1.GetCell(0).CellStyle = TitleStyle;
  1442. row1 = sheet.CreateRow(PaintIndex);
  1443. PaintIndex = PaintIndex + 1;
  1444. //特殊客户添加一列空行
  1445. for (int j = 0; j < columnNum - 3; j++)
  1446. {
  1447. if (j == 0)
  1448. {
  1449. row1.CreateCell(j);
  1450. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_title"].ToString() + " " + DataTable.Rows[i]["ch_level"].ToString());
  1451. }
  1452. else if (columnNum > 14 && j == columnNum - 14)
  1453. {
  1454. row1.CreateCell(j);
  1455. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
  1456. }
  1457. else
  1458. {
  1459. row1.CreateCell(j);
  1460. }
  1461. row1.GetCell(j).CellStyle = style;
  1462. }
  1463. row1 = sheet.CreateRow(PaintIndex);
  1464. PaintIndex = PaintIndex + 1;
  1465. //第二行添加型号
  1466. for (int j = 0; j < columnNum - 3; j++)
  1467. {
  1468. if (j == 0)
  1469. {
  1470. row1.CreateCell(j);
  1471. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pr_orispeccode"].ToString() + DataTable.Rows[i]["me_desc"].ToString() + " " + DataTable.Rows[i]["pr_size"].ToString() + " 销售部门:市场部");
  1472. }
  1473. else if (columnNum > 14 && j == columnNum - 14)
  1474. {
  1475. row1.CreateCell(j);
  1476. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
  1477. }
  1478. else
  1479. {
  1480. row1.CreateCell(j);
  1481. }
  1482. row1.GetCell(j).CellStyle = style;
  1483. }
  1484. //特殊客户添加一列空行
  1485. row1 = sheet.CreateRow(PaintIndex);
  1486. PaintIndex = PaintIndex + 1;
  1487. //添加列名
  1488. row1 = sheet.CreateRow(PaintIndex);
  1489. PaintIndex = PaintIndex + 1;
  1490. //计数列所在的索引
  1491. for (int j = 4; j < columnNum; j++)
  1492. {
  1493. row1.CreateCell(j - 4);
  1494. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1495. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  1496. {
  1497. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  1498. }
  1499. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  1500. {
  1501. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  1502. }
  1503. else
  1504. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  1505. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  1506. {
  1507. NumIndex = j;
  1508. }
  1509. //如果chw_itemname1的值为空,则值为100和0,其中一列不显示,不显示
  1510. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())) || (!ShowChcode && DataTable.Columns[j].ColumnName.ToLower().Contains("ch_code")))
  1511. {
  1512. sheet.SetColumnHidden(j - 4, true);
  1513. }
  1514. }
  1515. row1 = sheet.CreateRow(PaintIndex);
  1516. PaintIndex = PaintIndex + 1;
  1517. }
  1518. }
  1519. //添加数据内容
  1520. for (int j = 4; j < columnNum; j++)
  1521. {
  1522. string Data = DataTable.Rows[i][j].ToString();
  1523. row1.CreateCell(j - 4);
  1524. row1.Cells[j - 4].SetCellValue(Data);
  1525. row1.GetCell(j - 4).CellStyle = styleborder;
  1526. if (DataTable.Columns[j].ColumnName == "io_qty")
  1527. {
  1528. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  1529. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  1530. }
  1531. if (DataTable.Columns[j].ColumnName == "rownum")
  1532. {
  1533. row1.Cells[j - 4].SetCellValue(i + 1);
  1534. }
  1535. }
  1536. //固定行号分组的时候自动拼接新的DataTable
  1537. if (i == rowNum - 1)
  1538. {
  1539. DataRow dr = FirstDT.NewRow();
  1540. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  1541. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  1542. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  1543. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  1544. dr["pd_ordercode"] = First_OrderCode;
  1545. dr["pr_orispeccode1"] = First_Prspec;
  1546. dr["ch_splitbatch"] = First_Batch;
  1547. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  1548. dr["num"] = (i % PageSize) + 1;
  1549. dr["io_qty"] = sumCount;
  1550. FirstDT.Rows.Add(dr);
  1551. row1 = sheet.CreateRow(PaintIndex);
  1552. PaintIndex = PaintIndex + 1;
  1553. for (int j = 0; j < columnNum - 4; j++)
  1554. {
  1555. row1.CreateCell(j);
  1556. if (j == 0)
  1557. {
  1558. row1.Cells[j].SetCellValue("小计");
  1559. }
  1560. else if (j == 1)
  1561. {
  1562. row1.Cells[1].SetCellValue((i % PageSize == 0 ? PageSize : (i % PageSize + 1)) + "片");
  1563. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1564. }
  1565. else if (j == 2)
  1566. {
  1567. row1.Cells[2].SetCellValue(sumCount);
  1568. }
  1569. row1.Cells[j].CellStyle = styleborder;
  1570. }
  1571. row1 = sheet.CreateRow(PaintIndex);
  1572. sheet.SetRowBreak(PaintIndex);
  1573. sheet.Footer.Center = "第&P页,共&N页";
  1574. PaintIndex = PaintIndex + 1;
  1575. }
  1576. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  1577. pib_outboxcode1.Add(BoxCode.ToString());
  1578. }
  1579. for (int i = 0; i < sheet.LastRowNum; i++)
  1580. {
  1581. if (i != 0)
  1582. {
  1583. sheet.AutoSizeColumn(i);
  1584. sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  1585. }
  1586. }
  1587. break;
  1588. case "BatchCode":
  1589. string LastBatchCode = "";
  1590. int PageNum = 0;
  1591. for (int i = 0; i < rowNum; i++)
  1592. {
  1593. IRow row1 = sheet.CreateRow(PaintIndex);
  1594. PaintIndex = PaintIndex + 1;
  1595. row1.HeightInPoints = RowHeight;
  1596. //如果批号不相等的时候
  1597. PageNum = PageNum + 1;
  1598. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  1599. {
  1600. BoxCode = BoxCode + 1;
  1601. for (int j = 0; j < columnNum - 4; j++)
  1602. {
  1603. row1.CreateCell(j);
  1604. if (j == 0)
  1605. {
  1606. row1.Cells[j].SetCellValue("小计");
  1607. row1.Cells[j].CellStyle = styleborder;
  1608. }
  1609. else if (j == 1)
  1610. {
  1611. row1.Cells[1].SetCellValue(PageNum - 1 + "片");
  1612. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1613. }
  1614. else if (j == 2)
  1615. {
  1616. row1.Cells[2].SetCellValue(sumCount);
  1617. row1.Cells[j].CellStyle = styleborder;
  1618. }
  1619. else
  1620. {
  1621. row1.Cells[j].CellStyle = styleborder;
  1622. }
  1623. }
  1624. sumCount = 0;
  1625. row1 = sheet.CreateRow(PaintIndex);
  1626. sheet.SetRowBreak(PaintIndex - 1);
  1627. sheet.Footer.Center = "第&P页,共&N页";
  1628. PaintIndex = PaintIndex + 1;
  1629. PageNum = 1;
  1630. }
  1631. //每次到了页数开始分页
  1632. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()))
  1633. {
  1634. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  1635. //第一行添加客户信息
  1636. row1 = sheet.CreateRow(PaintIndex);
  1637. PaintIndex = PaintIndex + 1;
  1638. row1.CreateCell(0).SetCellValue(" 深爱半导体股份有限公司芯片出货清单");
  1639. row1.GetCell(0).CellStyle = TitleStyle;
  1640. row1 = sheet.CreateRow(PaintIndex);
  1641. PaintIndex = PaintIndex + 1;
  1642. if (i != rowNum - 1)
  1643. {
  1644. for (int j = 0; j < columnNum - 3; j++)
  1645. {
  1646. if (j == 0)
  1647. {
  1648. row1.CreateCell(j);
  1649. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_title"].ToString() + " " + DataTable.Rows[i]["ch_level"].ToString());
  1650. }
  1651. else if (columnNum > 14 && j == columnNum - 14)
  1652. {
  1653. row1.CreateCell(j);
  1654. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
  1655. }
  1656. else
  1657. {
  1658. row1.CreateCell(j);
  1659. }
  1660. row1.GetCell(j).CellStyle = style;
  1661. }
  1662. row1 = sheet.CreateRow(PaintIndex);
  1663. PaintIndex = PaintIndex + 1;
  1664. //第二行添加型号
  1665. for (int j = 0; j < columnNum - 3; j++)
  1666. {
  1667. if (j == 0)
  1668. {
  1669. row1.CreateCell(j);
  1670. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pr_orispeccode"].ToString() + DataTable.Rows[i]["me_desc"].ToString() + " " + DataTable.Rows[i]["pr_size"].ToString() + " 销售部门:市场部");
  1671. }
  1672. else if (columnNum > 14 && j == columnNum - 14)
  1673. {
  1674. row1.CreateCell(j);
  1675. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
  1676. }
  1677. else
  1678. {
  1679. row1.CreateCell(j);
  1680. }
  1681. row1.GetCell(j).CellStyle = style;
  1682. }
  1683. //添加列名
  1684. row1 = sheet.CreateRow(PaintIndex);
  1685. PaintIndex = PaintIndex + 1;
  1686. for (int j = 4; j < columnNum; j++)
  1687. {
  1688. row1.CreateCell(j - 4);
  1689. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1690. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  1691. {
  1692. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  1693. }
  1694. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  1695. {
  1696. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  1697. }
  1698. else
  1699. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  1700. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())) || (!ShowChcode && DataTable.Columns[j].ColumnName.ToLower().Contains("ch_code")))
  1701. {
  1702. sheet.SetColumnHidden(j - 4, true);
  1703. }
  1704. }
  1705. row1 = sheet.CreateRow(PaintIndex);
  1706. PaintIndex = PaintIndex + 1;
  1707. }
  1708. }
  1709. //添加数据内容
  1710. for (int j = 4; j < columnNum; j++)
  1711. {
  1712. string Data = DataTable.Rows[i][j].ToString();
  1713. row1.CreateCell(j - 4);
  1714. row1.Cells[j - 4].SetCellValue(Data);
  1715. row1.GetCell(j - 4).CellStyle = styleborder;
  1716. if (DataTable.Columns[j].ColumnName == "io_qty")
  1717. {
  1718. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  1719. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  1720. }
  1721. if (DataTable.Columns[j].ColumnName == "rownum")
  1722. {
  1723. row1.Cells[j - 4].SetCellValue(i + 1);
  1724. }
  1725. }
  1726. if (i == rowNum - 1)
  1727. {
  1728. row1 = sheet.CreateRow(PaintIndex);
  1729. PaintIndex = PaintIndex + 1;
  1730. for (int j = 0; j < columnNum - 4; j++)
  1731. {
  1732. row1.CreateCell(j);
  1733. if (j == 0)
  1734. {
  1735. row1.Cells[j].SetCellValue("小计");
  1736. row1.Cells[j].CellStyle = styleborder;
  1737. }
  1738. else if (j == 1)
  1739. {
  1740. row1.Cells[1].SetCellValue(PageNum + "片");
  1741. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1742. }
  1743. else if (j == 2)
  1744. {
  1745. row1.Cells[2].SetCellValue(sumCount);
  1746. row1.Cells[j].CellStyle = styleborder;
  1747. }
  1748. else
  1749. {
  1750. row1.Cells[j].CellStyle = styleborder;
  1751. }
  1752. }
  1753. //创建备注内容
  1754. row1 = sheet.CreateRow(PaintIndex);
  1755. sheet.SetRowBreak(PaintIndex);
  1756. sheet.Footer.Center = "第&P页,共&N页";
  1757. PaintIndex = PaintIndex + 1;
  1758. PageNum = 1;
  1759. }
  1760. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  1761. pib_outboxcode1.Add(BoxCode.ToString());
  1762. }
  1763. for (int i = 0; i < sheet.LastRowNum; i++)
  1764. {
  1765. if (i != 0)
  1766. {
  1767. sheet.AutoSizeColumn(i);
  1768. sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  1769. }
  1770. }
  1771. break;
  1772. case "BoxCode":
  1773. string LastBoxCode = "";
  1774. int PageNum1 = 0;
  1775. for (int i = 0; i < rowNum; i++)
  1776. {
  1777. IRow row1 = sheet.CreateRow(PaintIndex);
  1778. PaintIndex = PaintIndex + 1;
  1779. row1.HeightInPoints = RowHeight;
  1780. PageNum1 = PageNum1 + 1;
  1781. //如果批号不相等的时候
  1782. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  1783. {
  1784. BoxCode = BoxCode + 1;
  1785. for (int j = 0; j < columnNum - 4; j++)
  1786. {
  1787. row1.CreateCell(j);
  1788. if (j == 0)
  1789. {
  1790. row1.Cells[j].SetCellValue("小计");
  1791. row1.Cells[j].CellStyle = styleborder;
  1792. }
  1793. else if (j == 1)
  1794. {
  1795. row1.Cells[1].SetCellValue(PageNum1 - 1 + "片");
  1796. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1797. }
  1798. else if (j == 2)
  1799. {
  1800. row1.Cells[2].SetCellValue(sumCount);
  1801. row1.Cells[j].CellStyle = styleborder;
  1802. }
  1803. else
  1804. {
  1805. row1.Cells[j].CellStyle = styleborder;
  1806. }
  1807. }
  1808. sumCount = 0;
  1809. row1 = sheet.CreateRow(PaintIndex);
  1810. sheet.SetRowBreak(PaintIndex - 1);
  1811. sheet.Footer.Center = "第&P页,共&N页";
  1812. PaintIndex = PaintIndex + 1;
  1813. PageNum1 = 1;
  1814. }
  1815. //每次到了页数开始分页
  1816. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()))
  1817. {
  1818. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  1819. row1 = sheet.CreateRow(PaintIndex);
  1820. PaintIndex = PaintIndex + 1;
  1821. row1.CreateCell(0).SetCellValue(" 深爱半导体股份有限公司芯片出货清单");
  1822. row1.GetCell(0).CellStyle = TitleStyle;
  1823. row1 = sheet.CreateRow(PaintIndex);
  1824. PaintIndex = PaintIndex + 1;
  1825. //第一行添加客户信息
  1826. if (i != rowNum - 1)
  1827. {
  1828. for (int j = 0; j < columnNum - 3; j++)
  1829. {
  1830. if (j == 0)
  1831. {
  1832. row1.CreateCell(j);
  1833. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_title"].ToString() + " " + DataTable.Rows[i]["ch_level"].ToString());
  1834. }
  1835. else if (columnNum > 14 && j == columnNum - 14)
  1836. {
  1837. row1.CreateCell(j);
  1838. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
  1839. }
  1840. else
  1841. {
  1842. row1.CreateCell(j);
  1843. }
  1844. row1.GetCell(j).CellStyle = style;
  1845. }
  1846. row1 = sheet.CreateRow(PaintIndex);
  1847. PaintIndex = PaintIndex + 1;
  1848. //第二行添加型号
  1849. for (int j = 0; j < columnNum - 3; j++)
  1850. {
  1851. if (j == 0)
  1852. {
  1853. row1.CreateCell(j);
  1854. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pr_orispeccode"].ToString() + DataTable.Rows[i]["me_desc"].ToString() + " " + DataTable.Rows[i]["pr_size"].ToString() + " 销售部门:市场部");
  1855. }
  1856. else if (columnNum > 14 && j == columnNum - 14)
  1857. {
  1858. row1.CreateCell(j);
  1859. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
  1860. }
  1861. else
  1862. {
  1863. row1.CreateCell(j);
  1864. }
  1865. row1.GetCell(j).CellStyle = style;
  1866. }
  1867. //添加列名
  1868. row1 = sheet.CreateRow(PaintIndex);
  1869. PaintIndex = PaintIndex + 1;
  1870. for (int j = 4; j < columnNum; j++)
  1871. {
  1872. //设定固定的列名
  1873. row1.CreateCell(j - 4);
  1874. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1875. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  1876. {
  1877. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  1878. }
  1879. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  1880. {
  1881. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  1882. }
  1883. else
  1884. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  1885. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())) || (!ShowChcode && DataTable.Columns[j].ColumnName.ToLower().Contains("ch_code")))
  1886. {
  1887. sheet.SetColumnHidden(j - 4, true);
  1888. }
  1889. }
  1890. row1 = sheet.CreateRow(PaintIndex);
  1891. PaintIndex = PaintIndex + 1;
  1892. }
  1893. }
  1894. //添加数据内容
  1895. for (int j = 4; j < columnNum; j++)
  1896. {
  1897. string Data = DataTable.Rows[i][j].ToString();
  1898. row1.CreateCell(j - 4);
  1899. row1.Cells[j - 4].SetCellValue(Data);
  1900. row1.GetCell(j - 4).CellStyle = styleborder;
  1901. if (DataTable.Columns[j].ColumnName == "io_qty")
  1902. {
  1903. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  1904. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  1905. }
  1906. if (DataTable.Columns[j].ColumnName == "rownum")
  1907. {
  1908. row1.Cells[j - 4].SetCellValue(i + 1);
  1909. }
  1910. }
  1911. if (i == rowNum - 1)
  1912. {
  1913. row1 = sheet.CreateRow(PaintIndex);
  1914. PaintIndex = PaintIndex + 1;
  1915. for (int j = 0; j < columnNum - 4; j++)
  1916. {
  1917. row1.CreateCell(j);
  1918. if (j == 0)
  1919. {
  1920. row1.Cells[j].SetCellValue("小计");
  1921. row1.Cells[j].CellStyle = styleborder;
  1922. }
  1923. else if (j == 1)
  1924. {
  1925. row1.Cells[1].SetCellValue(PageNum1 + "片");
  1926. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1927. }
  1928. else if (j == 2)
  1929. {
  1930. row1.Cells[2].SetCellValue(sumCount);
  1931. row1.Cells[j].CellStyle = styleborder;
  1932. }
  1933. else
  1934. {
  1935. row1.Cells[j].CellStyle = styleborder;
  1936. }
  1937. }
  1938. row1 = sheet.CreateRow(PaintIndex);
  1939. sheet.SetRowBreak(PaintIndex);
  1940. sheet.Footer.Center = "第&P页,共&N页";
  1941. PaintIndex = PaintIndex + 1;
  1942. PageNum1 = 1;
  1943. }
  1944. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  1945. pib_outboxcode1.Add(BoxCode.ToString());
  1946. }
  1947. for (int i = 0; i < sheet.LastRowNum; i++)
  1948. {
  1949. if (i != 0)
  1950. {
  1951. sheet.AutoSizeColumn(i);
  1952. sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  1953. }
  1954. }
  1955. break;
  1956. default:
  1957. break;
  1958. }
  1959. dh.BatchInsert("update prodiobarcode set pib_outboxcode1=:pib_outboxcode1 where pib_inoutno='" + Inoutno + "' and pib_id=:pib_id", new string[] { "pib_outboxcode1", "pib_id" }, pib_outboxcode1.ToArray(), pib_id.ToArray());
  1960. //删除下载链接再重新插入
  1961. HttpHandler.GenDownLoadLinK(Inoutno);
  1962. //填充首页
  1963. sumCount = 0;
  1964. totalCount = 0;
  1965. PaintIndex = 1;
  1966. ISheet sheet2 = book.CreateSheet("首页");
  1967. IRow row = sheet.CreateRow(0);
  1968. row = sheet2.CreateRow(0);
  1969. row.CreateCell(0);
  1970. row.Cells[0].SetCellValue(" 深爱半导体股份有限公司芯片出货清单");
  1971. row.GetCell(0).CellStyle = style;
  1972. rowNum = FirstDT.Rows.Count;
  1973. //不需要显示的列移除
  1974. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  1975. {
  1976. for (int j = 0; j < box.Length; j++)
  1977. {
  1978. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  1979. {
  1980. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  1981. {
  1982. FirstDT.Columns.RemoveAt(i);
  1983. }
  1984. }
  1985. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  1986. {
  1987. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  1988. {
  1989. FirstDT.Columns.RemoveAt(i);
  1990. }
  1991. }
  1992. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  1993. {
  1994. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  1995. {
  1996. FirstDT.Columns.RemoveAt(i);
  1997. }
  1998. }
  1999. }
  2000. }
  2001. columnNum = FirstDT.Columns.Count;
  2002. for (int i = 0; i < rowNum; i++)
  2003. {
  2004. IRow row1 = sheet2.CreateRow(PaintIndex);
  2005. PaintIndex = PaintIndex + 1;
  2006. row1.HeightInPoints = RowHeight;
  2007. //只需要绘制一行
  2008. if (i == 0)
  2009. {
  2010. for (int j = 0; j < columnNum - 3; j++)
  2011. {
  2012. if (j == 0)
  2013. {
  2014. row1.CreateCell(j);
  2015. row1.Cells[j].SetCellValue(FirstDT.Rows[i]["pi_title"].ToString());
  2016. }
  2017. else if (j > 5 && j == columnNum - 5)
  2018. {
  2019. row1.CreateCell(j);
  2020. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
  2021. }
  2022. else if (columnNum > 5 && j == columnNum - 5)
  2023. {
  2024. row1.CreateCell(j);
  2025. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_inoutno"].ToString());
  2026. }
  2027. else
  2028. {
  2029. row1.CreateCell(j);
  2030. }
  2031. row1.GetCell(j).CellStyle = style;
  2032. }
  2033. row1 = sheet2.CreateRow(PaintIndex);
  2034. PaintIndex = PaintIndex + 1;
  2035. //第二行添加型号
  2036. for (int j = 0; j < columnNum - 3; j++)
  2037. {
  2038. if (j == 0)
  2039. {
  2040. row1.CreateCell(j);
  2041. row1.Cells[j].SetCellValue(FirstDT.Rows[i]["pr_orispeccode"].ToString());
  2042. }
  2043. else if (j > 5 && j == columnNum - 5)
  2044. {
  2045. row1.CreateCell(j);
  2046. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
  2047. }
  2048. else if (columnNum > 5 && j == columnNum - 5)
  2049. {
  2050. row1.CreateCell(j);
  2051. row1.Cells[j].SetCellValue(DataTable.Rows[i]["pi_date"].ToString());
  2052. }
  2053. else
  2054. {
  2055. row1.CreateCell(j);
  2056. }
  2057. row1.GetCell(j).CellStyle = style;
  2058. }
  2059. row1 = sheet2.CreateRow(PaintIndex);
  2060. PaintIndex = PaintIndex + 1;
  2061. //添加列名
  2062. for (int j = 4; j < columnNum; j++)
  2063. {
  2064. row1.CreateCell(j - 4);
  2065. row1.Cells[j - 4].CellStyle = styleborder;
  2066. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  2067. }
  2068. row1 = sheet2.CreateRow(PaintIndex);
  2069. PaintIndex = PaintIndex + 1;
  2070. }
  2071. //添加数据内容
  2072. for (int j = 4; j < columnNum; j++)
  2073. {
  2074. string Data = FirstDT.Rows[i][j].ToString();
  2075. row1.CreateCell(j - 4);
  2076. row1.Cells[j - 4].SetCellValue(Data);
  2077. row1.GetCell(j - 4).CellStyle = styleborder;
  2078. if (FirstDT.Columns[j].ColumnName == "num")
  2079. {
  2080. sumCount += int.Parse(Data);
  2081. }
  2082. if (FirstDT.Columns[j].ColumnName == "io_qty")
  2083. {
  2084. totalCount += int.Parse(Data);
  2085. }
  2086. }
  2087. //添加总计行
  2088. if (i == rowNum - 1)
  2089. {
  2090. row1 = sheet2.CreateRow(PaintIndex);
  2091. PaintIndex = PaintIndex + 1;
  2092. for (int j = 0; j < columnNum - 4; j++)
  2093. {
  2094. if (j == 0)
  2095. {
  2096. row1.CreateCell(j);
  2097. row1.Cells[j].CellStyle = styleborder;
  2098. row1.Cells[j].SetCellValue("总计");
  2099. }
  2100. else if (j == columnNum - 6)
  2101. {
  2102. row1.CreateCell(j);
  2103. row1.Cells[j].CellStyle = styleborder;
  2104. row1.Cells[j].SetCellValue(sumCount);
  2105. }
  2106. else if (j == columnNum - 5)
  2107. {
  2108. row1.CreateCell(j);
  2109. row1.Cells[j].CellStyle = styleborder;
  2110. row1.Cells[j].SetCellValue(totalCount);
  2111. }
  2112. else
  2113. {
  2114. row1.CreateCell(j);
  2115. row1.Cells[j].CellStyle = styleborder;
  2116. }
  2117. }
  2118. }
  2119. }
  2120. for (int i = 0; i < sheet2.LastRowNum; i++)
  2121. {
  2122. if (i != 0)
  2123. {
  2124. sheet2.AutoSizeColumn(i);
  2125. sheet2.SetColumnWidth(i, sheet2.GetColumnWidth(i) + 1000);
  2126. }
  2127. }
  2128. //将book的内容写入内存流中返回
  2129. book.Write(ms);
  2130. return ms;
  2131. }
  2132. }
  2133. }