ExcelHandler.cs 206 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970
  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. //展示抬头日期的索引
  19. int ShowDataIndex = 7;
  20. //展示芯片尺寸的索引
  21. int ShowSizeIndex = 5;
  22. //显示计数的索引
  23. int ShowCountIndex = 2;
  24. //显示片数的索引
  25. int ShowPieceIndex = 1;
  26. //显示备注的片
  27. int ShowRemarkPiece = 5;
  28. int NumIndex = 0;
  29. /// <summary>
  30. /// 导出Excel,返回文件在客户端的路径
  31. /// </summary>
  32. public string ExportExcel(DataTable dt, string FolderPath, string FileName)
  33. {
  34. //创建一个内存流,用来接收转换成Excel的内容
  35. MemoryStream ms;
  36. ms = DataTableToExcel(dt);
  37. //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
  38. string filePath = @FolderPath + "\\" + FileName + ".xls";
  39. FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  40. byte[] data = ms.ToArray();
  41. fs.Write(data, 0, data.Length);
  42. fs.Flush();
  43. //释放当前Excel文件,否则打开文件的时候会显示文件被占用
  44. ms.Dispose();
  45. fs.Dispose();
  46. return filePath;
  47. }
  48. /// <summary>
  49. /// 导出Excel,返回文件在客户端的路径
  50. /// </summary>
  51. public string ExportExcel_Normal(DataTable firstsdt, DataTable dt, string FolderPath, string FileName, string Type, int PageSize, List<CheckBox> conditionbox)
  52. {
  53. //创建一个内存流,用来接收转换成Excel的内容
  54. MemoryStream ms;
  55. ms = DataTableToExcel_Normal(firstsdt, dt, Type, FileName, PageSize, conditionbox);
  56. //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
  57. string filePath = @FolderPath + "\\" + FileName + ".xls";
  58. int counter = 1;
  59. string filename = FileName + ".xls";
  60. while (File.Exists(filePath))
  61. {
  62. filename = string.Format("{0}({1}){2}", FileName, counter, ".xls"); //文件名+(count)+后缀
  63. filePath = Path.Combine(FolderPath, filename); //保存路径
  64. counter++; //count+1
  65. }
  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. /// 晶源客户特殊方案
  77. /// </summary>
  78. public string JINYUAN(DataTable firstsdt, DataTable dt, string FolderPath, string FileName, string Type, int PageSize, List<CheckBox> conditionbox)
  79. {
  80. //创建一个内存流,用来接收转换成Excel的内容
  81. MemoryStream ms;
  82. ms = DataTableToExcel_JINYUAN(firstsdt, dt, Type, FileName, PageSize, conditionbox);
  83. //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
  84. string filePath = @FolderPath + "\\" + FileName + ".xls";
  85. int counter = 1;
  86. string filename = FileName + ".xls";
  87. while (File.Exists(filePath))
  88. {
  89. filename = string.Format("{0}({1}){2}", FileName, counter, ".xls"); //文件名+(count)+后缀
  90. filePath = Path.Combine(FolderPath, filename); //保存路径
  91. counter++; //count+1
  92. }
  93. FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  94. byte[] data = ms.ToArray();
  95. fs.Write(data, 0, data.Length);
  96. fs.Flush();
  97. //释放当前Excel文件,否则打开文件的时候会显示文件被占用
  98. ms.Dispose();
  99. fs.Dispose();
  100. return filePath;
  101. }
  102. /// <summary>
  103. /// 利普芯客户特殊方案
  104. /// </summary>
  105. public string LIPIUXIN(DataTable firstsdt, DataTable dt, string FolderPath, string FileName, string Type, int PageSize, List<CheckBox> conditionbox)
  106. {
  107. //创建一个内存流,用来接收转换成Excel的内容
  108. MemoryStream ms;
  109. ms = DataTableToExcel_LIPUXIN(firstsdt, dt, Type, FileName, PageSize, conditionbox);
  110. //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
  111. string filePath = @FolderPath + "\\" + FileName + ".xls";
  112. int counter = 1;
  113. string filename = FileName + ".xls";
  114. while (File.Exists(filePath))
  115. {
  116. filename = string.Format("{0}({1}){2}", FileName, counter, ".xls"); //文件名+(count)+后缀
  117. filePath = Path.Combine(FolderPath, filename); //保存路径
  118. counter++; //count+1
  119. }
  120. FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  121. byte[] data = ms.ToArray();
  122. fs.Write(data, 0, data.Length);
  123. fs.Flush();
  124. //释放当前Excel文件,否则打开文件的时候会显示文件被占用
  125. ms.Dispose();
  126. fs.Dispose();
  127. return filePath;
  128. }
  129. /// <summary>
  130. /// 导入Excel
  131. /// </summary>
  132. public void ImportExcel(DataTable DataTable, string TableName)
  133. {
  134. int columnNum = DataTable.Columns.Count;
  135. int rowNum = DataTable.Columns.Count;
  136. string[] field = new string[columnNum];
  137. for (int i = 0; i < columnNum; i++)
  138. {
  139. field[i] = DataTable.Rows[0][i].ToString();
  140. }
  141. }
  142. public static DataTable ExcelToDataTable(string filePath, bool isColumnName)
  143. {
  144. DataTable dataTable = null;
  145. FileStream fs = null;
  146. DataColumn column = null;
  147. DataRow dataRow = null;
  148. IWorkbook workbook = null;
  149. ISheet sheet = null;
  150. IRow row = null;
  151. ICell cell = null;
  152. int startRow = 0;
  153. try
  154. {
  155. using (fs = File.OpenRead(filePath))
  156. {
  157. // 2007版本
  158. if (filePath.IndexOf(".xlsx") > 0)
  159. {
  160. workbook = new XSSFWorkbook(fs);
  161. }
  162. // 2003版本
  163. else if (filePath.IndexOf(".xls") > 0)
  164. {
  165. workbook = new HSSFWorkbook(fs);
  166. }
  167. if (workbook != null)
  168. {
  169. sheet = workbook.GetSheetAt(0);//读取第一个sheet,当然也可以循环读取每个sheet
  170. dataTable = new DataTable();
  171. if (sheet != null)
  172. {
  173. int rowCount = sheet.LastRowNum;//总行数
  174. if (rowCount > 0)
  175. {
  176. IRow firstRow = sheet.GetRow(0);//第一行
  177. int cellCount = firstRow.LastCellNum;//列数
  178. //构建datatable的列
  179. if (isColumnName)
  180. {
  181. startRow = 1;//如果第一行是列名,则从第二行开始读取
  182. for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
  183. {
  184. cell = firstRow.GetCell(i);
  185. if (cell != null)
  186. {
  187. if (cell.StringCellValue != null)
  188. {
  189. column = new DataColumn(cell.StringCellValue);
  190. dataTable.Columns.Add(column);
  191. }
  192. }
  193. }
  194. }
  195. else
  196. {
  197. for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
  198. {
  199. column = new DataColumn("column" + (i + 1));
  200. dataTable.Columns.Add(column);
  201. }
  202. }
  203. //填充行
  204. for (int i = startRow; i <= rowCount; ++i)
  205. {
  206. row = sheet.GetRow(i);
  207. if (row == null) continue;
  208. dataRow = dataTable.NewRow();
  209. for (int j = row.FirstCellNum; j < cellCount; ++j)
  210. {
  211. cell = row.GetCell(j);
  212. if (cell == null)
  213. {
  214. dataRow[j] = "";
  215. }
  216. else
  217. {
  218. //CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
  219. switch (cell.CellType)
  220. {
  221. case CellType.Blank:
  222. dataRow[j] = "";
  223. break;
  224. case CellType.Numeric:
  225. short format = cell.CellStyle.DataFormat;
  226. //对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
  227. if (format == 14 || format == 31 || format == 57 || format == 58)
  228. dataRow[j] = cell.DateCellValue;
  229. else
  230. dataRow[j] = cell.NumericCellValue;
  231. break;
  232. case CellType.String:
  233. dataRow[j] = cell.StringCellValue;
  234. break;
  235. }
  236. }
  237. }
  238. dataTable.Rows.Add(dataRow);
  239. }
  240. }
  241. }
  242. }
  243. }
  244. return dataTable;
  245. }
  246. catch (Exception)
  247. {
  248. if (fs != null)
  249. {
  250. fs.Close();
  251. }
  252. return null;
  253. }
  254. }
  255. int RowHeight = 12;
  256. /// <summary>
  257. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  258. /// </summary>
  259. /// <param name="DataTable"></param>
  260. /// <returns></returns>
  261. public MemoryStream DataTableToExcel(DataTable DataTable)
  262. {
  263. //创建内存流
  264. MemoryStream ms = new MemoryStream();
  265. //创建一个Book,相当于一个Excel文件
  266. HSSFWorkbook book = new HSSFWorkbook();
  267. //Excel中的Sheet
  268. ISheet sheet = book.CreateSheet("sheet1");
  269. //获取行数量和列数量
  270. int rowNum = DataTable.Rows.Count;
  271. int columnNum = DataTable.Columns.Count;
  272. //设置列的宽度,根据首行的列的内容的长度来设置
  273. for (int i = 0; i < columnNum; i++)
  274. {
  275. int dataLength;
  276. //如果内容比标题短则取标题长度
  277. if (DataTable.Rows[0][i].ToString().Length < DataTable.Columns[i].ColumnName.Length)
  278. {
  279. dataLength = DataTable.Columns[i].ColumnName.Length;
  280. dataLength = dataLength * 300;
  281. }
  282. else
  283. {
  284. dataLength = DataTable.Rows[0][i].ToString().Length;
  285. dataLength = dataLength * 300;
  286. }
  287. sheet.SetColumnWidth(i, dataLength);
  288. }
  289. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  290. IRow row = sheet.CreateRow(0);
  291. //冻结第一行
  292. sheet.CreateFreezePane(0, 1, 0, 1);
  293. ICellStyle style = book.CreateCellStyle();
  294. style.FillForegroundColor = HSSFColor.PaleBlue.Index;
  295. style.FillPattern = FillPattern.BigSpots;
  296. style.FillBackgroundColor = HSSFColor.LightGreen.Index;
  297. //设置边框
  298. style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  299. style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  300. style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  301. style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  302. row.HeightInPoints = 20;
  303. //固定第一行
  304. //row.RowStyle.IsLocked=true;
  305. //给第一行的标签赋值样式和值
  306. for (int j = 0; j < columnNum; j++)
  307. {
  308. row.CreateCell(j);
  309. row.Cells[j].CellStyle = style;
  310. row.Cells[j].CellStyle.VerticalAlignment = VerticalAlignment.Center;
  311. row.Cells[j].CellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  312. row.Cells[j].SetCellValue(DataTable.Columns[j].Caption);
  313. }
  314. //将DataTable的值循环赋值给book,Aligment设置居中
  315. //之前已经画了带颜色的第一行,所以从i=1开始画
  316. for (int i = 0; i < rowNum; i++)
  317. {
  318. IRow row1 = sheet.CreateRow(i + 1);
  319. row1.HeightInPoints = 20;
  320. for (int j = 0; j < columnNum; j++)
  321. {
  322. row1.CreateCell(j);
  323. row1.Cells[j].SetCellValue(DataTable.Rows[i][j].ToString());
  324. row1.GetCell(j).CellStyle.VerticalAlignment = VerticalAlignment.Center;
  325. }
  326. }
  327. //将book的内容写入内存流中返回
  328. book.Write(ms);
  329. return ms;
  330. }
  331. /// <summary>
  332. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  333. /// </summary>
  334. /// <param name="DataTable"></param>
  335. /// <returns></returns>
  336. public MemoryStream DataTableToExcel_Normal(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  337. {
  338. string 小计 = "";
  339. string 总计 = "";
  340. string 片 = "";
  341. string companyname = "";
  342. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype", "pi_inoutno='" + Inoutno + "'").ToString() == "Chinese")
  343. {
  344. 小计 = "小计";
  345. 总计 = "总计";
  346. companyname = "深爱半导体股份有限公司芯片出货清单";
  347. }
  348. else
  349. {
  350. 小计 = "total";
  351. 总计 = "total";
  352. companyname = "SHENZHEN SI SEMICONDUCTORS CO.,LTD";
  353. }
  354. //转换为序列
  355. CheckBox[] box = conditionbox.ToArray();
  356. //创建内存流
  357. MemoryStream ms = new MemoryStream();
  358. //创建一个Book,相当于一个Excel文件
  359. HSSFWorkbook book = new HSSFWorkbook();
  360. //Excel中的Sheet
  361. ISheet sheet = book.CreateSheet("分页");
  362. sheet.SetMargin(MarginType.TopMargin, 0.4);
  363. sheet.SetMargin(MarginType.BottomMargin, 0.4);
  364. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  365. sheet.SetMargin(MarginType.RightMargin, 0.4);
  366. sheet.FitToPage = true;
  367. sheet.PrintSetup.FitHeight = 200;
  368. //芯片号需要作为更新盒号的条件
  369. HSSFFont ffont = (HSSFFont)book.CreateFont();
  370. ffont.FontName = "宋体";
  371. //更新箱号
  372. List<string> pib_id = new List<string>();
  373. //系统打印箱号
  374. List<string> pib_outboxcode1 = new List<string>();
  375. int BoxCode = 1;
  376. ICellStyle style = book.CreateCellStyle();
  377. style.VerticalAlignment = VerticalAlignment.Center;
  378. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  379. style.SetFont(ffont);
  380. ICellStyle styleborder = book.CreateCellStyle();
  381. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  382. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  383. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  384. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  385. styleborder.VerticalAlignment = VerticalAlignment.Center;
  386. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  387. styleborder.SetFont(ffont);
  388. string pi_inoutno = "";
  389. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  390. ColumnTitle.FontName = "宋体";
  391. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  392. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  393. ColumnTitleStyle.SetFont(ColumnTitle);
  394. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  395. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  396. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  397. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  398. List<string> NotShowColumn = new List<string>();
  399. NotShowColumn.Add("ch_level");
  400. NotShowColumn.Add("pib_id");
  401. NotShowColumn.Add("chw_itemname1");
  402. NotShowColumn.Add("chw_itemname2");
  403. NotShowColumn.Add("chw_itemname3");
  404. NotShowColumn.Add("pd_ordercode");
  405. NotShowColumn.Add("pr_size");
  406. NotShowColumn.Add("me_desc");
  407. NotShowColumn.Add("pr_orispeccode");
  408. NotShowColumn.Add("pr_orispeccode1");
  409. NotShowColumn.Add("pi_title");
  410. NotShowColumn.Add("pi_chipouttype");
  411. NotShowColumn.Add("pi_date");
  412. int ShowColumnCount = 0;
  413. //展示的内容列
  414. //设置列的宽度,根据首行的列的内容的长度来设置
  415. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  416. {
  417. for (int j = 0; j < box.Length; j++)
  418. {
  419. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  420. {
  421. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  422. {
  423. DataTable.Columns.RemoveAt(i);
  424. break;
  425. }
  426. }
  427. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  428. {
  429. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  430. {
  431. DataTable.Columns.RemoveAt(i);
  432. break;
  433. }
  434. }
  435. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  436. {
  437. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  438. {
  439. DataTable.Columns.RemoveAt(i);
  440. break;
  441. }
  442. }
  443. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  444. {
  445. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  446. {
  447. DataTable.Columns.RemoveAt(i);
  448. break;
  449. }
  450. }
  451. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  452. {
  453. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  454. {
  455. DataTable.Columns.RemoveAt(i);
  456. break;
  457. }
  458. }
  459. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  460. {
  461. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  462. {
  463. DataTable.Columns.RemoveAt(i);
  464. break;
  465. }
  466. }
  467. if (box[j].Name.ToLower() == "ch_yield" && !box[j].Checked)
  468. {
  469. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_yield"))
  470. {
  471. DataTable.Columns.RemoveAt(i);
  472. break;
  473. }
  474. }
  475. }
  476. }
  477. //获取行数量和列数量
  478. int rowNum = DataTable.Rows.Count;
  479. int columnNum = DataTable.Columns.Count;
  480. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  481. IRow row = sheet.CreateRow(0);
  482. //冻结第一行
  483. sheet.CreateFreezePane(0, 1, 0, 1);
  484. row.HeightInPoints = RowHeight;
  485. //固定第一行
  486. //row.RowStyle.IsLocked=true;
  487. //给第一行的标签赋值样式和值
  488. // ffont.FontHeight = 13;
  489. row.CreateCell(0);
  490. row.Cells[0].SetCellValue(" " + companyname);
  491. row.GetCell(0).CellStyle.SetFont((ffont));
  492. //ffont.FontHeight = 10;
  493. //开始绘制的Index
  494. int PaintIndex = 1;
  495. int sumCount = 0;
  496. int totalCount = 0;
  497. switch (Type)
  498. {
  499. case "FixRow":
  500. //清理系统取出来的数据
  501. BaseUtil.CleanDataTableData(FirstDT);
  502. //首页参数拼接
  503. string First_OrderCode = "";
  504. string First_Prspec = "";
  505. string First_Batch = "";
  506. ArrayList<string> First_WID = new ArrayList<string>();
  507. for (int i = 0; i < rowNum; i++)
  508. {
  509. IRow row1 = sheet.CreateRow(PaintIndex);
  510. PaintIndex = PaintIndex + 1;
  511. row1.HeightInPoints = RowHeight;
  512. //不包含的订单号
  513. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  514. {
  515. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  516. }
  517. //不包含的物料型号
  518. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  519. {
  520. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  521. }
  522. //不包含扩撒批号
  523. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  524. {
  525. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  526. }
  527. //不包含Wafer_id
  528. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  529. {
  530. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  531. }
  532. if (i / PageSize >= 1 && i % PageSize == 0)
  533. {
  534. DataRow dr = FirstDT.NewRow();
  535. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  536. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  537. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  538. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  539. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  540. dr["pd_ordercode"] = First_OrderCode;
  541. dr["pr_orispeccode"] = First_Prspec;
  542. dr["ch_splitbatch"] = First_Batch;
  543. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  544. dr["num"] = PageSize;
  545. dr["io_qty"] = sumCount;
  546. FirstDT.Rows.Add(dr);
  547. First_OrderCode = "";
  548. First_Prspec = "";
  549. First_Batch = "";
  550. First_WID.Clear();
  551. BoxCode = BoxCode + 1;
  552. for (int j = 0; j < ShowColumnCount; j++)
  553. {
  554. row1.CreateCell(j);
  555. if (j == 0)
  556. {
  557. row1.Cells[j].SetCellValue(小计);
  558. }
  559. else if (j == ShowPieceIndex)
  560. {
  561. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i) + 片);
  562. row1.Cells[j].CellStyle = styleborder;
  563. }
  564. else if (j == ShowCountIndex)
  565. {
  566. row1.Cells[j].SetCellValue(sumCount);
  567. }
  568. row1.Cells[j].CellStyle = styleborder;
  569. }
  570. sumCount = 0;
  571. row1 = sheet.CreateRow(PaintIndex);
  572. sheet.SetRowBreak(PaintIndex - 1);
  573. sheet.Footer.Center = "第&P页,共&N页";
  574. PaintIndex = PaintIndex + 1;
  575. }
  576. //每次到了页数开始分页
  577. if (i % PageSize == 0 || i == rowNum - 1)
  578. {
  579. //第一行添加客户信息 rownum只有一行的情
  580. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  581. {
  582. for (int j = 0; j < columnNum - 3; j++)
  583. {
  584. if (j == 0)
  585. {
  586. row1.CreateCell(j);
  587. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  588. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  589. }
  590. else if (j == ShowDataIndex)
  591. {
  592. row1.CreateCell(j);
  593. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  594. }
  595. else
  596. {
  597. row1.CreateCell(j);
  598. }
  599. row1.GetCell(j).CellStyle = style;
  600. }
  601. row1 = sheet.CreateRow(PaintIndex);
  602. PaintIndex = PaintIndex + 1;
  603. //第二行添加型号
  604. for (int j = 0; j < columnNum - 3; j++)
  605. {
  606. if (j == 0)
  607. {
  608. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  609. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ")" + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  610. }
  611. else if (j == ShowSizeIndex)
  612. {
  613. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  614. }
  615. else if (j == ShowDataIndex)
  616. {
  617. row1.CreateCell(j).SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  618. }
  619. }
  620. //添加列名
  621. row1 = sheet.CreateRow(PaintIndex);
  622. PaintIndex = PaintIndex + 1;
  623. //计数列所在的索引
  624. int showcount = 0;
  625. for (int j = 4; j < columnNum; j++)
  626. {
  627. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  628. {
  629. showcount = showcount + 1;
  630. row1.CreateCell(j - 4);
  631. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  632. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  633. }
  634. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  635. {
  636. showcount = showcount + 1;
  637. row1.CreateCell(j - 4);
  638. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  639. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  640. }
  641. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  642. {
  643. showcount = showcount + 1;
  644. row1.CreateCell(j - 4);
  645. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  646. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  647. }
  648. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  649. {
  650. }
  651. else
  652. {
  653. showcount = showcount + 1;
  654. row1.CreateCell(j - 4);
  655. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  656. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  657. }
  658. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  659. {
  660. NumIndex = j;
  661. if (ShowCountIndex == NumIndex - 4)
  662. {
  663. ShowCountIndex = ShowCountIndex + 1;
  664. }
  665. }
  666. }
  667. ShowColumnCount = showcount;
  668. row1 = sheet.CreateRow(PaintIndex);
  669. PaintIndex = PaintIndex + 1;
  670. }
  671. }
  672. //添加数据内容
  673. for (int j = 4; j < columnNum; j++)
  674. {
  675. string Data = DataTable.Rows[i][j].ToString();
  676. row1.CreateCell(j - 4);
  677. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  678. {
  679. }
  680. else
  681. {
  682. row1.Cells[j - 4].SetCellValue(Data);
  683. row1.GetCell(j - 4).CellStyle = styleborder;
  684. }
  685. if (DataTable.Columns[j].ColumnName == "io_qty")
  686. {
  687. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  688. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  689. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  690. }
  691. if (DataTable.Columns[j].ColumnName == "rownum")
  692. {
  693. row1.Cells[j - 4].SetCellValue(i + 1);
  694. }
  695. if (DataTable.Columns[j].ColumnName == "ch_code")
  696. {
  697. sheet.AutoSizeColumn(j - 4);
  698. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  699. }
  700. }
  701. //固定行号分组的时候自动拼接新的DataTable
  702. if (i == rowNum - 1)
  703. {
  704. DataRow dr = FirstDT.NewRow();
  705. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  706. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  707. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  708. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  709. dr["pd_ordercode"] = First_OrderCode;
  710. dr["pr_orispeccode"] = First_Prspec;
  711. dr["ch_splitbatch"] = First_Batch;
  712. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  713. dr["num"] = (i % PageSize) + 1;
  714. dr["io_qty"] = sumCount;
  715. FirstDT.Rows.Add(dr);
  716. row1 = sheet.CreateRow(PaintIndex);
  717. PaintIndex = PaintIndex + 1;
  718. for (int j = 0; j < ShowColumnCount; j++)
  719. {
  720. row1.CreateCell(j);
  721. if (j == 0)
  722. {
  723. row1.Cells[j].SetCellValue(小计);
  724. }
  725. else if (j == ShowPieceIndex)
  726. {
  727. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize==0?PageSize:(rowNum % PageSize))+ 片);
  728. row1.Cells[j].CellStyle = styleborder;
  729. }
  730. else if (j == ShowCountIndex)
  731. {
  732. row1.Cells[j].SetCellValue(sumCount);
  733. }
  734. row1.Cells[j].CellStyle = styleborder;
  735. }
  736. row1 = sheet.CreateRow(PaintIndex);
  737. for (int j = 0; j < columnNum - 3; j++)
  738. {
  739. if (j == 0)
  740. {
  741. row1.CreateCell(j);
  742. row1.Cells[j].SetCellValue("备注");
  743. }
  744. else if (j == ShowCountIndex)
  745. {
  746. row1.CreateCell(j);
  747. row1.Cells[j].SetCellValue(totalCount);
  748. }
  749. else if (j == ShowRemarkPiece)
  750. {
  751. row1.CreateCell(j);
  752. row1.Cells[j].SetCellValue(rowNum + "片");
  753. }
  754. else
  755. {
  756. row1.CreateCell(j);
  757. }
  758. row1.Cells[j].CellStyle = style;
  759. }
  760. sheet.SetRowBreak(PaintIndex);
  761. sheet.Footer.Center = "第&P页,共&N页";
  762. PaintIndex = PaintIndex + 1;
  763. }
  764. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  765. pib_outboxcode1.Add(BoxCode.ToString());
  766. }
  767. break;
  768. case "BatchCode":
  769. string LastBatchCode = "";
  770. int PageNum = 0;
  771. for (int i = 0; i < rowNum; i++)
  772. {
  773. IRow row1 = sheet.CreateRow(PaintIndex);
  774. PaintIndex = PaintIndex + 1;
  775. row1.HeightInPoints = RowHeight;
  776. //如果批号不相等的时候
  777. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  778. {
  779. BoxCode = BoxCode + 1;
  780. for (int j = 0; j < ShowColumnCount; j++)
  781. {
  782. row1.CreateCell(j);
  783. if (j == 0)
  784. {
  785. row1.Cells[j].SetCellValue(小计);
  786. row1.Cells[j].CellStyle = styleborder;
  787. }
  788. else if (j == ShowPieceIndex)
  789. {
  790. row1.Cells[ShowPieceIndex].SetCellValue(PageNum - 1 + 片);
  791. row1.Cells[j].CellStyle = styleborder;
  792. }
  793. else if (j == ShowCountIndex)
  794. {
  795. row1.Cells[j].SetCellValue(sumCount);
  796. row1.Cells[j].CellStyle = styleborder;
  797. }
  798. else
  799. {
  800. row1.Cells[j].CellStyle = styleborder;
  801. }
  802. }
  803. sumCount = 0;
  804. row1 = sheet.CreateRow(PaintIndex);
  805. sheet.SetRowBreak(PaintIndex - 1);
  806. sheet.Footer.Center = "第&P页,共&N页";
  807. PaintIndex = PaintIndex + 1;
  808. PageNum = 0;
  809. }
  810. //每次到了页数开始分页
  811. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()) || i == rowNum - 1)
  812. {
  813. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  814. //第一行添加客户信息
  815. //if (i != rowNum - 1)
  816. {
  817. for (int j = 0; j < columnNum - 3; j++)
  818. {
  819. if (j == 0)
  820. {
  821. row1.CreateCell(j);
  822. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  823. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  824. }
  825. else if (j == ShowDataIndex)
  826. {
  827. row1.CreateCell(j);
  828. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  829. }
  830. else
  831. {
  832. row1.CreateCell(j);
  833. }
  834. row1.GetCell(j).CellStyle = style;
  835. }
  836. row1 = sheet.CreateRow(PaintIndex);
  837. PaintIndex = PaintIndex + 1;
  838. //第二行添加型号
  839. for (int j = 0; j < columnNum - 3; j++)
  840. {
  841. if (j == 0)
  842. {
  843. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  844. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ")" + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  845. }
  846. else if (j == ShowSizeIndex)
  847. {
  848. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  849. }
  850. else if (j == ShowDataIndex)
  851. {
  852. row1.CreateCell(j).SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  853. }
  854. }
  855. //添加列名
  856. row1 = sheet.CreateRow(PaintIndex);
  857. PaintIndex = PaintIndex + 1;
  858. int showcount = 0;
  859. for (int j = 4; j < columnNum; j++)
  860. {
  861. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  862. {
  863. showcount = showcount + 1;
  864. row1.CreateCell(j - 4);
  865. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  866. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  867. }
  868. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  869. {
  870. showcount = showcount + 1;
  871. row1.CreateCell(j - 4);
  872. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  873. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  874. }
  875. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  876. {
  877. showcount = showcount + 1;
  878. row1.CreateCell(j - 4);
  879. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  880. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  881. }
  882. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  883. {
  884. }
  885. else
  886. {
  887. showcount = showcount + 1;
  888. row1.CreateCell(j - 4);
  889. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  890. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  891. }
  892. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  893. {
  894. NumIndex = j;
  895. if (ShowCountIndex == NumIndex - 4)
  896. {
  897. ShowCountIndex = ShowCountIndex + 1;
  898. }
  899. }
  900. }
  901. ShowColumnCount = showcount;
  902. row1 = sheet.CreateRow(PaintIndex);
  903. PaintIndex = PaintIndex + 1;
  904. }
  905. }
  906. //添加数据内容
  907. for (int j = 4; j < columnNum; j++)
  908. {
  909. string Data = DataTable.Rows[i][j].ToString();
  910. row1.CreateCell(j - 4);
  911. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  912. {
  913. }
  914. else
  915. {
  916. row1.Cells[j - 4].SetCellValue(Data);
  917. row1.GetCell(j - 4).CellStyle = styleborder;
  918. }
  919. if (DataTable.Columns[j].ColumnName == "io_qty")
  920. {
  921. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  922. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  923. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  924. }
  925. if (DataTable.Columns[j].ColumnName == "rownum")
  926. {
  927. row1.Cells[j - 4].SetCellValue(i + 1);
  928. }
  929. if (DataTable.Columns[j].ColumnName == "ch_code")
  930. {
  931. sheet.AutoSizeColumn(j - 4);
  932. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  933. }
  934. }
  935. if (i == rowNum - 1)
  936. {
  937. row1 = sheet.CreateRow(PaintIndex);
  938. PaintIndex = PaintIndex + 1;
  939. for (int j = 0; j < ShowColumnCount; j++)
  940. {
  941. row1.CreateCell(j);
  942. if (j == 0)
  943. {
  944. row1.Cells[j].SetCellValue(小计);
  945. row1.Cells[j].CellStyle = styleborder;
  946. }
  947. else if (j == ShowPieceIndex)
  948. {
  949. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  950. row1.Cells[j].CellStyle = styleborder;
  951. }
  952. else if (j == ShowCountIndex)
  953. {
  954. row1.Cells[j].SetCellValue(sumCount);
  955. row1.Cells[j].CellStyle = styleborder;
  956. }
  957. else
  958. {
  959. row1.Cells[j].CellStyle = styleborder;
  960. }
  961. }
  962. //创建备注内容
  963. row1 = sheet.CreateRow(PaintIndex);
  964. for (int j = 0; j < columnNum - 3; j++)
  965. {
  966. if (j == 0)
  967. {
  968. row1.CreateCell(j);
  969. row1.Cells[j].SetCellValue("备注");
  970. }
  971. else if (j == ShowCountIndex)
  972. {
  973. row1.CreateCell(j);
  974. row1.Cells[j].SetCellValue(totalCount);
  975. }
  976. else if (j == ShowRemarkPiece)
  977. {
  978. row1.CreateCell(j);
  979. row1.Cells[j].SetCellValue(rowNum + "片");
  980. }
  981. else if (j == 4)
  982. {
  983. row1.CreateCell(j);
  984. row1.Cells[j].SetCellValue(片);
  985. }
  986. else
  987. {
  988. row1.CreateCell(j);
  989. }
  990. row1.Cells[j].CellStyle = style;
  991. }
  992. sheet.SetRowBreak(PaintIndex);
  993. sheet.Footer.Center = "第&P页,共&N页";
  994. PaintIndex = PaintIndex + 1;
  995. PageNum = 0;
  996. }
  997. PageNum = PageNum + 1;
  998. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  999. pib_outboxcode1.Add(BoxCode.ToString());
  1000. }
  1001. //for (int i = 0; i < sheet.LastRowNum; i++)
  1002. //{
  1003. // if (i != 0)
  1004. // {
  1005. // sheet.AutoSizeColumn(i);
  1006. // sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  1007. // }
  1008. //}
  1009. break;
  1010. case "BoxCode":
  1011. string LastBoxCode = "";
  1012. int PageNum1 = 0;
  1013. for (int i = 0; i < rowNum; i++)
  1014. {
  1015. IRow row1 = sheet.CreateRow(PaintIndex);
  1016. PaintIndex = PaintIndex + 1;
  1017. row1.HeightInPoints = RowHeight;
  1018. //如果批号不相等的时候
  1019. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  1020. {
  1021. BoxCode = BoxCode + 1;
  1022. for (int j = 0; j < ShowColumnCount; j++)
  1023. {
  1024. row1.CreateCell(j);
  1025. if (j == 0)
  1026. {
  1027. row1.Cells[j].SetCellValue(小计);
  1028. row1.Cells[j].CellStyle = styleborder;
  1029. }
  1030. else if (j == ShowPieceIndex)
  1031. {
  1032. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  1033. row1.Cells[j].CellStyle = styleborder;
  1034. }
  1035. else if (j == ShowCountIndex)
  1036. {
  1037. row1.Cells[j].SetCellValue(sumCount);
  1038. row1.Cells[j].CellStyle = styleborder;
  1039. }
  1040. else
  1041. {
  1042. row1.Cells[j].CellStyle = styleborder;
  1043. }
  1044. }
  1045. sumCount = 0;
  1046. row1 = sheet.CreateRow(PaintIndex);
  1047. sheet.SetRowBreak(PaintIndex - 1);
  1048. sheet.Footer.Center = "第&P页,共&N页";
  1049. PaintIndex = PaintIndex + 1;
  1050. PageNum1 = 0;
  1051. }
  1052. //每次到了页数开始分页
  1053. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  1054. {
  1055. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  1056. //第一行添加客户信息
  1057. //if (i != rowNum - 1)
  1058. {
  1059. for (int j = 0; j < columnNum - 3; j++)
  1060. {
  1061. if (j == 0)
  1062. {
  1063. row1.CreateCell(j);
  1064. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  1065. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  1066. }
  1067. else if (j == ShowDataIndex)
  1068. {
  1069. row1.CreateCell(j);
  1070. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  1071. }
  1072. else
  1073. {
  1074. row1.CreateCell(j);
  1075. }
  1076. row1.GetCell(j).CellStyle = style;
  1077. }
  1078. row1 = sheet.CreateRow(PaintIndex);
  1079. PaintIndex = PaintIndex + 1;
  1080. //第二行添加型号
  1081. for (int j = 0; j < columnNum - 3; j++)
  1082. {
  1083. if (j == 0)
  1084. {
  1085. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  1086. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ")" + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  1087. }
  1088. else if (j == ShowSizeIndex)
  1089. {
  1090. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  1091. }
  1092. else if (j == ShowDataIndex)
  1093. {
  1094. row1.CreateCell(j).SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  1095. }
  1096. }
  1097. //添加列名
  1098. row1 = sheet.CreateRow(PaintIndex);
  1099. PaintIndex = PaintIndex + 1;
  1100. int showcount = 0;
  1101. for (int j = 4; j < columnNum; j++)
  1102. {
  1103. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  1104. {
  1105. showcount = showcount + 1;
  1106. row1.CreateCell(j - 4);
  1107. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1108. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  1109. }
  1110. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  1111. {
  1112. showcount = showcount + 1;
  1113. row1.CreateCell(j - 4);
  1114. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1115. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  1116. }
  1117. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  1118. {
  1119. showcount = showcount + 1;
  1120. row1.CreateCell(j - 4);
  1121. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1122. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  1123. }
  1124. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1125. {
  1126. }
  1127. else
  1128. {
  1129. showcount = showcount + 1;
  1130. row1.CreateCell(j - 4);
  1131. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1132. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  1133. }
  1134. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  1135. {
  1136. NumIndex = j;
  1137. if (ShowCountIndex == NumIndex - 4)
  1138. {
  1139. ShowCountIndex = ShowCountIndex + 1;
  1140. }
  1141. }
  1142. }
  1143. ShowColumnCount = showcount;
  1144. row1 = sheet.CreateRow(PaintIndex);
  1145. PaintIndex = PaintIndex + 1;
  1146. }
  1147. }
  1148. //添加数据内容
  1149. for (int j = 4; j < columnNum; j++)
  1150. {
  1151. string Data = DataTable.Rows[i][j].ToString();
  1152. row1.CreateCell(j - 4);
  1153. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1154. {
  1155. }
  1156. else
  1157. {
  1158. row1.Cells[j - 4].SetCellValue(Data);
  1159. row1.GetCell(j - 4).CellStyle = styleborder;
  1160. }
  1161. if (DataTable.Columns[j].ColumnName == "io_qty")
  1162. {
  1163. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  1164. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  1165. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  1166. }
  1167. if (DataTable.Columns[j].ColumnName == "rownum")
  1168. {
  1169. row1.Cells[j - 4].SetCellValue(i + 1);
  1170. }
  1171. if (DataTable.Columns[j].ColumnName == "ch_code")
  1172. {
  1173. sheet.AutoSizeColumn(j - 4);
  1174. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  1175. }
  1176. }
  1177. if (i == rowNum - 1)
  1178. {
  1179. PageNum1 = PageNum1 + 1;
  1180. row1 = sheet.CreateRow(PaintIndex);
  1181. PaintIndex = PaintIndex + 1;
  1182. for (int j = 0; j < ShowColumnCount; j++)
  1183. {
  1184. row1.CreateCell(j);
  1185. if (j == 0)
  1186. {
  1187. row1.Cells[j].SetCellValue(小计);
  1188. row1.Cells[j].CellStyle = styleborder;
  1189. }
  1190. else if (j == ShowPieceIndex)
  1191. {
  1192. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  1193. row1.Cells[j].CellStyle = styleborder;
  1194. }
  1195. else if (j == ShowCountIndex)
  1196. {
  1197. row1.Cells[j].SetCellValue(sumCount);
  1198. row1.Cells[j].CellStyle = styleborder;
  1199. }
  1200. else
  1201. {
  1202. row1.Cells[j].CellStyle = styleborder;
  1203. }
  1204. }
  1205. row1 = sheet.CreateRow(PaintIndex);
  1206. for (int j = 0; j < columnNum - 3; j++)
  1207. {
  1208. if (j == 0)
  1209. {
  1210. row1.CreateCell(j);
  1211. row1.Cells[j].SetCellValue("备注");
  1212. }
  1213. else if (j == ShowCountIndex)
  1214. {
  1215. row1.CreateCell(j);
  1216. row1.Cells[j].SetCellValue(totalCount);
  1217. }
  1218. else if (j == ShowRemarkPiece)
  1219. {
  1220. row1.CreateCell(j);
  1221. row1.Cells[j].SetCellValue(rowNum + "片");
  1222. }
  1223. else
  1224. {
  1225. row1.CreateCell(j);
  1226. }
  1227. row1.Cells[j].CellStyle = style;
  1228. }
  1229. sheet.SetRowBreak(PaintIndex);
  1230. sheet.Footer.Center = "第&P页,共&N页";
  1231. PaintIndex = PaintIndex + 1;
  1232. PageNum1 = 0;
  1233. }
  1234. PageNum1 = PageNum1 + 1;
  1235. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  1236. pib_outboxcode1.Add(BoxCode.ToString());
  1237. }
  1238. //for (int i = 0; i < sheet.LastRowNum; i++)
  1239. //{
  1240. // if (i != 0)
  1241. // {
  1242. // sheet.AutoSizeColumn(i);
  1243. // sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  1244. // }
  1245. //}
  1246. break;
  1247. default:
  1248. break;
  1249. }
  1250. 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());
  1251. //删除下载链接再重新插入
  1252. HttpHandler.GenDownLoadLinK(Inoutno);
  1253. //填充首页
  1254. sumCount = 0;
  1255. totalCount = 0;
  1256. PaintIndex = 1;
  1257. ISheet sheet2 = book.CreateSheet("首页");
  1258. row = sheet2.CreateRow(0);
  1259. row.CreateCell(0);
  1260. row.Cells[0].SetCellValue(" " + companyname);
  1261. row.GetCell(0).CellStyle = style;
  1262. rowNum = FirstDT.Rows.Count;
  1263. //不需要显示的列移除
  1264. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  1265. {
  1266. for (int j = 0; j < box.Length; j++)
  1267. {
  1268. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  1269. {
  1270. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  1271. {
  1272. FirstDT.Columns.RemoveAt(i);
  1273. }
  1274. }
  1275. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  1276. {
  1277. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  1278. {
  1279. FirstDT.Columns.RemoveAt(i);
  1280. }
  1281. }
  1282. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  1283. {
  1284. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  1285. {
  1286. FirstDT.Columns.RemoveAt(i);
  1287. }
  1288. }
  1289. }
  1290. }
  1291. columnNum = FirstDT.Columns.Count;
  1292. for (int i = 0; i < rowNum; i++)
  1293. {
  1294. IRow row1 = sheet2.CreateRow(PaintIndex);
  1295. PaintIndex = PaintIndex + 1;
  1296. row1.HeightInPoints = RowHeight;
  1297. //只需要绘制一行
  1298. if (i == 0)
  1299. {
  1300. for (int j = 0; j < columnNum - 3; j++)
  1301. {
  1302. if (j == 0)
  1303. {
  1304. row1.CreateCell(j);
  1305. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString());
  1306. }
  1307. else if (j > 5 && j == columnNum - 5)
  1308. {
  1309. row1.CreateCell(j);
  1310. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  1311. }
  1312. else if (columnNum > 5 && j == columnNum - 5)
  1313. {
  1314. row1.CreateCell(j);
  1315. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  1316. }
  1317. else
  1318. {
  1319. row1.CreateCell(j);
  1320. }
  1321. row1.GetCell(j).CellStyle = style;
  1322. }
  1323. row1 = sheet2.CreateRow(PaintIndex);
  1324. PaintIndex = PaintIndex + 1;
  1325. //第二行添加型号
  1326. for (int j = 0; j < columnNum - 3; j++)
  1327. {
  1328. if (j == 0)
  1329. {
  1330. row1.CreateCell(j);
  1331. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString());
  1332. }
  1333. else if (j > 5 && j == columnNum - 5)
  1334. {
  1335. row1.CreateCell(j);
  1336. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  1337. }
  1338. else if (columnNum > 5 && j == columnNum - 5)
  1339. {
  1340. row1.CreateCell(j);
  1341. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  1342. }
  1343. else
  1344. {
  1345. row1.CreateCell(j);
  1346. }
  1347. row1.GetCell(j).CellStyle = style;
  1348. }
  1349. row1 = sheet2.CreateRow(PaintIndex);
  1350. PaintIndex = PaintIndex + 1;
  1351. //添加列名
  1352. for (int j = 4; j < columnNum; j++)
  1353. {
  1354. row1.CreateCell(j - 4);
  1355. row1.Cells[j - 4].CellStyle = styleborder;
  1356. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  1357. }
  1358. row1 = sheet2.CreateRow(PaintIndex);
  1359. PaintIndex = PaintIndex + 1;
  1360. }
  1361. //添加数据内容
  1362. for (int j = 4; j < columnNum; j++)
  1363. {
  1364. string Data = FirstDT.Rows[i][j].ToString();
  1365. row1.CreateCell(j - 4);
  1366. row1.Cells[j - 4].SetCellValue(Data);
  1367. row1.GetCell(j - 4).CellStyle = styleborder;
  1368. if (FirstDT.Columns[j].ColumnName == "num")
  1369. {
  1370. sumCount += int.Parse(Data);
  1371. }
  1372. if (FirstDT.Columns[j].ColumnName == "io_qty")
  1373. {
  1374. totalCount += int.Parse(Data);
  1375. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  1376. }
  1377. }
  1378. //添加总计行
  1379. if (i == rowNum - 1)
  1380. {
  1381. row1 = sheet2.CreateRow(PaintIndex);
  1382. PaintIndex = PaintIndex + 1;
  1383. for (int j = 0; j < columnNum - 4; j++)
  1384. {
  1385. if (j == 0)
  1386. {
  1387. row1.CreateCell(j);
  1388. row1.Cells[j].CellStyle = styleborder;
  1389. row1.Cells[j].SetCellValue(总计);
  1390. }
  1391. else if (j == columnNum - 6)
  1392. {
  1393. row1.CreateCell(j);
  1394. row1.Cells[j].CellStyle = styleborder;
  1395. row1.Cells[j].SetCellValue(sumCount);
  1396. }
  1397. else if (j == columnNum - 5)
  1398. {
  1399. row1.CreateCell(j);
  1400. row1.Cells[j].CellStyle = styleborder;
  1401. row1.Cells[j].SetCellValue(totalCount);
  1402. }
  1403. else
  1404. {
  1405. row1.CreateCell(j);
  1406. row1.Cells[j].CellStyle = styleborder;
  1407. }
  1408. }
  1409. }
  1410. }
  1411. for (int i = 0; i < sheet2.LastRowNum; i++)
  1412. {
  1413. if (i != 0)
  1414. {
  1415. sheet2.AutoSizeColumn(i);
  1416. sheet2.SetColumnWidth(i, sheet2.GetColumnWidth(i) + 1000);
  1417. }
  1418. }
  1419. //将book的内容写入内存流中返回
  1420. book.Write(ms);
  1421. return ms;
  1422. }
  1423. /// <summary>
  1424. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  1425. /// </summary>
  1426. /// <param name="DataTable"></param>
  1427. /// <returns></returns>
  1428. private MemoryStream DataTableToExcel_JINYUAN(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  1429. {
  1430. string 小计 = "";
  1431. string 总计 = "";
  1432. string 片 = "";
  1433. string companyname = "";
  1434. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype", "pi_inoutno='" + Inoutno + "'").ToString() == "Chinese")
  1435. {
  1436. 小计 = "小计";
  1437. 总计 = "总计";
  1438. 片 = "片";
  1439. companyname = "深爱半导体股份有限公司芯片出货清单";
  1440. }
  1441. else
  1442. {
  1443. 小计 = "total";
  1444. 总计 = "total";
  1445. 片 = "slice";
  1446. companyname = "SHENZHEN SI SEMICONDUCTORS CO.,LTD";
  1447. }
  1448. //转换为序列
  1449. CheckBox[] box = conditionbox.ToArray();
  1450. //创建内存流
  1451. MemoryStream ms = new MemoryStream();
  1452. //创建一个Book,相当于一个Excel文件
  1453. HSSFWorkbook book = new HSSFWorkbook();
  1454. //Excel中的Sheet
  1455. ISheet sheet = book.CreateSheet("分页");
  1456. sheet.SetMargin(MarginType.TopMargin, 0.4);
  1457. sheet.SetMargin(MarginType.BottomMargin, 0.4);
  1458. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  1459. sheet.SetMargin(MarginType.RightMargin, 0.4);
  1460. sheet.PrintSetup.NoColor = true;
  1461. sheet.PrintSetup.Landscape = true;
  1462. //芯片号需要作为更新盒号的条件
  1463. HSSFFont ffont = (HSSFFont)book.CreateFont();
  1464. ffont.FontName = "宋体";
  1465. //更新箱号
  1466. List<string> pib_id = new List<string>();
  1467. //系统打印箱号
  1468. List<string> pib_outboxcode1 = new List<string>();
  1469. int BoxCode = 1;
  1470. ICellStyle style = book.CreateCellStyle();
  1471. style.VerticalAlignment = VerticalAlignment.Center;
  1472. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  1473. style.SetFont(ffont);
  1474. ICellStyle styleborder = book.CreateCellStyle();
  1475. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1476. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1477. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1478. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1479. styleborder.VerticalAlignment = VerticalAlignment.Center;
  1480. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  1481. styleborder.SetFont(ffont);
  1482. string pi_inoutno = "";
  1483. List<string> NotShowColumn = new List<string>();
  1484. NotShowColumn.Add("ch_level");
  1485. NotShowColumn.Add("pib_id");
  1486. NotShowColumn.Add("chw_itemname1");
  1487. NotShowColumn.Add("chw_itemname2");
  1488. NotShowColumn.Add("chw_itemname3");
  1489. NotShowColumn.Add("pd_ordercode");
  1490. NotShowColumn.Add("pr_size");
  1491. NotShowColumn.Add("me_desc");
  1492. NotShowColumn.Add("pr_orispeccode");
  1493. NotShowColumn.Add("pr_orispeccode1");
  1494. NotShowColumn.Add("pi_title");
  1495. NotShowColumn.Add("pi_date");
  1496. NotShowColumn.Add("pi_chipouttype");
  1497. //设置列的宽度,根据首行的列的内容的长度来设置
  1498. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  1499. {
  1500. for (int j = 0; j < box.Length; j++)
  1501. {
  1502. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  1503. {
  1504. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  1505. {
  1506. DataTable.Columns.RemoveAt(i);
  1507. break;
  1508. }
  1509. }
  1510. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  1511. {
  1512. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  1513. {
  1514. DataTable.Columns.RemoveAt(i);
  1515. break;
  1516. }
  1517. }
  1518. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  1519. {
  1520. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  1521. {
  1522. DataTable.Columns.RemoveAt(i);
  1523. break;
  1524. }
  1525. }
  1526. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  1527. {
  1528. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  1529. {
  1530. DataTable.Columns.RemoveAt(i);
  1531. break;
  1532. }
  1533. }
  1534. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  1535. {
  1536. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  1537. {
  1538. DataTable.Columns.RemoveAt(i);
  1539. break;
  1540. }
  1541. }
  1542. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  1543. {
  1544. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  1545. {
  1546. DataTable.Columns.RemoveAt(i);
  1547. break;
  1548. }
  1549. }
  1550. if (box[j].Name.ToLower() == "ch_yield" && !box[j].Checked)
  1551. {
  1552. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_yield"))
  1553. {
  1554. DataTable.Columns.RemoveAt(i);
  1555. break;
  1556. }
  1557. }
  1558. }
  1559. }
  1560. //获取行数量和列数量
  1561. int rowNum = DataTable.Rows.Count;
  1562. int columnNum = DataTable.Columns.Count;
  1563. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  1564. //ffont.FontHeight = 10;
  1565. //开始绘制的Index
  1566. int PaintIndex = 0;
  1567. int sumCount = 0;
  1568. int totalCount = 0;
  1569. //Title的字体
  1570. HSSFFont titlefont = (HSSFFont)book.CreateFont();
  1571. titlefont.FontName = "宋体";
  1572. titlefont.FontHeight = 270;
  1573. titlefont.Boldweight = (short)FontBoldWeight.Bold;
  1574. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  1575. ColumnTitle.FontName = "宋体";
  1576. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  1577. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  1578. ColumnTitleStyle.SetFont(ColumnTitle);
  1579. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1580. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1581. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1582. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1583. ICellStyle TitleStyle = book.CreateCellStyle();
  1584. TitleStyle.SetFont(titlefont);
  1585. int ShowColumnCount = 0;
  1586. IRow row1 = null;
  1587. switch (Type)
  1588. {
  1589. case "FixRow":
  1590. //清理系统取出来的数据
  1591. BaseUtil.CleanDataTableData(FirstDT);
  1592. //首页参数拼接
  1593. string First_OrderCode = "";
  1594. string First_Prspec = "";
  1595. string First_Batch = "";
  1596. ArrayList<string> First_WID = new ArrayList<string>();
  1597. for (int i = 0; i < rowNum; i++)
  1598. {
  1599. if (PaintIndex != 0)
  1600. {
  1601. row1 = sheet.CreateRow(PaintIndex);
  1602. PaintIndex = PaintIndex + 1;
  1603. row1.HeightInPoints = RowHeight;
  1604. }
  1605. //不包含的订单号
  1606. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  1607. {
  1608. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  1609. }
  1610. //不包含的物料型号
  1611. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  1612. {
  1613. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  1614. }
  1615. //不包含扩撒批号
  1616. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  1617. {
  1618. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  1619. }
  1620. //不包含Wafer_id
  1621. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  1622. {
  1623. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  1624. }
  1625. if (i / PageSize >= 1 && i % PageSize == 0)
  1626. {
  1627. DataRow dr = FirstDT.NewRow();
  1628. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  1629. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  1630. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  1631. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  1632. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  1633. dr["pd_ordercode"] = First_OrderCode;
  1634. dr["pr_orispeccode"] = First_Prspec;
  1635. dr["ch_splitbatch"] = First_Batch;
  1636. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  1637. dr["num"] = PageSize;
  1638. dr["io_qty"] = sumCount;
  1639. FirstDT.Rows.Add(dr);
  1640. First_OrderCode = "";
  1641. First_Prspec = "";
  1642. First_Batch = "";
  1643. First_WID.Clear();
  1644. BoxCode = BoxCode + 1;
  1645. for (int j = 0; j < ShowColumnCount; j++)
  1646. {
  1647. row1.CreateCell(j);
  1648. if (j == 0)
  1649. {
  1650. row1.Cells[j].SetCellValue(小计);
  1651. }
  1652. else if (j == ShowPieceIndex)
  1653. {
  1654. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i) + 片);
  1655. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1656. }
  1657. else if (j == ShowCountIndex)
  1658. {
  1659. row1.Cells[j].SetCellValue(sumCount);
  1660. }
  1661. row1.Cells[j].CellStyle = styleborder;
  1662. }
  1663. sumCount = 0;
  1664. row1 = sheet.CreateRow(PaintIndex);
  1665. sheet.SetRowBreak(PaintIndex - 1);
  1666. sheet.Footer.Center = "第&P页,共&N页";
  1667. }
  1668. //每次到了页数开始分页
  1669. if (i % PageSize == 0 || i == rowNum - 1)
  1670. {
  1671. //第一行添加客户信息 rownum只有一行的情
  1672. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  1673. {
  1674. //抬头设置
  1675. row1 = sheet.CreateRow(PaintIndex);
  1676. PaintIndex = PaintIndex + 1;
  1677. row1.CreateCell(0).SetCellValue(" " + companyname);
  1678. row1.GetCell(0).CellStyle = TitleStyle;
  1679. row1 = sheet.CreateRow(PaintIndex);
  1680. PaintIndex = PaintIndex + 1;
  1681. for (int j = 0; j < columnNum - 3; j++)
  1682. {
  1683. if (j == 0)
  1684. {
  1685. row1.CreateCell(j);
  1686. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  1687. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  1688. }
  1689. else if (j == ShowDataIndex)
  1690. {
  1691. row1.CreateCell(j);
  1692. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  1693. }
  1694. else
  1695. {
  1696. row1.CreateCell(j);
  1697. }
  1698. row1.GetCell(j).CellStyle = style;
  1699. }
  1700. row1 = sheet.CreateRow(PaintIndex);
  1701. PaintIndex = PaintIndex + 1;
  1702. //第二行添加型号
  1703. for (int j = 0; j < columnNum - 3; j++)
  1704. {
  1705. if (j == 0)
  1706. {
  1707. row1.CreateCell(j);
  1708. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  1709. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  1710. }
  1711. else if (j == ShowSizeIndex)
  1712. {
  1713. row1.CreateCell(j);
  1714. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  1715. }
  1716. else if (j == ShowDataIndex)
  1717. {
  1718. row1.CreateCell(j);
  1719. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  1720. }
  1721. else
  1722. {
  1723. row1.CreateCell(j);
  1724. }
  1725. row1.GetCell(j).CellStyle = style;
  1726. }
  1727. //特殊客户添加一列空行
  1728. row1 = sheet.CreateRow(PaintIndex);
  1729. PaintIndex = PaintIndex + 1;
  1730. for (int j = 0; j < columnNum; j++)
  1731. {
  1732. row1.CreateCell(j).SetCellValue("");
  1733. }
  1734. //添加列名
  1735. row1 = sheet.CreateRow(PaintIndex);
  1736. PaintIndex = PaintIndex + 1;
  1737. //计数列所在的索引
  1738. int showcount = 0;
  1739. //前面有4列标题内容,数据库设置的,需要从4开始索引
  1740. for (int j = 4; j < columnNum; j++)
  1741. {
  1742. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  1743. {
  1744. showcount = showcount + 1;
  1745. row1.CreateCell(j - 4);
  1746. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1747. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  1748. }
  1749. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  1750. {
  1751. showcount = showcount + 1;
  1752. row1.CreateCell(j - 4);
  1753. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1754. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  1755. }
  1756. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  1757. {
  1758. showcount = showcount + 1;
  1759. row1.CreateCell(j - 4);
  1760. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1761. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  1762. }
  1763. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1764. {
  1765. }
  1766. else
  1767. {
  1768. showcount = showcount + 1;
  1769. row1.CreateCell(j - 4);
  1770. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1771. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  1772. }
  1773. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  1774. {
  1775. NumIndex = j;
  1776. if (ShowCountIndex == NumIndex - 4)
  1777. {
  1778. ShowCountIndex = ShowCountIndex + 1;
  1779. }
  1780. }
  1781. }
  1782. ShowColumnCount = showcount;
  1783. row1 = sheet.CreateRow(PaintIndex);
  1784. PaintIndex = PaintIndex + 1;
  1785. }
  1786. }
  1787. //添加数据内容
  1788. for (int j = 4; j < columnNum; j++)
  1789. {
  1790. string Data = DataTable.Rows[i][j].ToString();
  1791. row1.CreateCell(j - 4);
  1792. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1793. {
  1794. }
  1795. else
  1796. {
  1797. row1.Cells[j - 4].SetCellValue(Data);
  1798. row1.GetCell(j - 4).CellStyle = styleborder;
  1799. }
  1800. if (DataTable.Columns[j].ColumnName == "io_qty")
  1801. {
  1802. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  1803. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  1804. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  1805. }
  1806. if (DataTable.Columns[j].ColumnName == "rownum")
  1807. {
  1808. row1.Cells[j - 4].SetCellValue(i + 1);
  1809. }
  1810. if (DataTable.Columns[j].ColumnName == "ch_code")
  1811. {
  1812. sheet.AutoSizeColumn(j - 4);
  1813. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  1814. }
  1815. }
  1816. //固定行号分组的时候自动拼接新的DataTable
  1817. if (i == rowNum - 1)
  1818. {
  1819. DataRow dr = FirstDT.NewRow();
  1820. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  1821. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  1822. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  1823. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  1824. dr["pd_ordercode"] = First_OrderCode;
  1825. dr["pr_orispeccode"] = First_Prspec;
  1826. dr["ch_splitbatch"] = First_Batch;
  1827. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  1828. dr["num"] = (i % PageSize) + 1;
  1829. dr["io_qty"] = sumCount;
  1830. FirstDT.Rows.Add(dr);
  1831. row1 = sheet.CreateRow(PaintIndex);
  1832. PaintIndex = PaintIndex + 1;
  1833. for (int j = 0; j < ShowColumnCount; j++)
  1834. {
  1835. row1.CreateCell(j);
  1836. if (j == 0)
  1837. {
  1838. row1.Cells[j].SetCellValue(小计);
  1839. }
  1840. else if (j == ShowPieceIndex)
  1841. {
  1842. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize == 0 ? PageSize : (rowNum % PageSize)) + 片);
  1843. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1844. }
  1845. else if (j == ShowCountIndex)
  1846. {
  1847. row1.Cells[j].SetCellValue(sumCount);
  1848. }
  1849. row1.Cells[j].CellStyle = styleborder;
  1850. }
  1851. row1 = sheet.CreateRow(PaintIndex);
  1852. for (int j = 0; j < columnNum - 3; j++)
  1853. {
  1854. if (j == 0)
  1855. {
  1856. row1.CreateCell(j);
  1857. row1.Cells[j].SetCellValue("备注");
  1858. }
  1859. else if (j == ShowCountIndex)
  1860. {
  1861. row1.CreateCell(j);
  1862. row1.Cells[j].SetCellValue(totalCount);
  1863. }
  1864. else if (j == ShowRemarkPiece)
  1865. {
  1866. row1.CreateCell(j);
  1867. row1.Cells[j].SetCellValue(rowNum + 片);
  1868. }
  1869. else
  1870. {
  1871. row1.CreateCell(j);
  1872. }
  1873. row1.Cells[j].CellStyle = style;
  1874. }
  1875. sheet.SetRowBreak(PaintIndex);
  1876. sheet.Footer.Center = "第&P页,共&N页";
  1877. }
  1878. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  1879. pib_outboxcode1.Add(BoxCode.ToString());
  1880. }
  1881. //for (int i = 0; i < sheet.LastRowNum; i++)
  1882. //{
  1883. // if (i != 0)
  1884. // {
  1885. // sheet.AutoSizeColumn(i);
  1886. // sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  1887. // }
  1888. //}
  1889. break;
  1890. case "BatchCode":
  1891. string LastBatchCode = "";
  1892. int PageNum = 0;
  1893. for (int i = 0; i < rowNum; i++)
  1894. {
  1895. row1 = sheet.CreateRow(PaintIndex);
  1896. if (i != 0)
  1897. PaintIndex = PaintIndex + 1;
  1898. row1.HeightInPoints = RowHeight;
  1899. //如果批号不相等的时候
  1900. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  1901. {
  1902. BoxCode = BoxCode + 1;
  1903. for (int j = 0; j < ShowColumnCount; j++)
  1904. {
  1905. row1.CreateCell(j);
  1906. if (j == 0)
  1907. {
  1908. row1.Cells[j].SetCellValue(小计);
  1909. row1.Cells[j].CellStyle = styleborder;
  1910. }
  1911. else if (j == ShowPieceIndex)
  1912. {
  1913. row1.Cells[ShowPieceIndex].SetCellValue(PageNum - 1 + 片);
  1914. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1915. }
  1916. else if (j == ShowCountIndex)
  1917. {
  1918. row1.Cells[j].SetCellValue(sumCount);
  1919. row1.Cells[j].CellStyle = styleborder;
  1920. }
  1921. else
  1922. {
  1923. row1.Cells[j].CellStyle = styleborder;
  1924. }
  1925. }
  1926. sumCount = 0;
  1927. //row1 = sheet.CreateRow(PaintIndex);
  1928. //sheet.SetRowBreak(PaintIndex - 1);
  1929. sheet.Footer.Center = "第&P页,共&N页";
  1930. PageNum = 0;
  1931. }
  1932. //每次到了页数开始分页
  1933. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()))
  1934. {
  1935. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  1936. //第一行添加客户信息
  1937. row1 = sheet.CreateRow(PaintIndex);
  1938. PaintIndex = PaintIndex + 1;
  1939. row1.CreateCell(0).SetCellValue(" " + companyname);
  1940. row1.GetCell(0).CellStyle = TitleStyle;
  1941. row1 = sheet.CreateRow(PaintIndex);
  1942. PaintIndex = PaintIndex + 1;
  1943. //if (i != rowNum - 1)
  1944. {
  1945. for (int j = 0; j < columnNum - 3; j++)
  1946. {
  1947. if (j == 0)
  1948. {
  1949. row1.CreateCell(j);
  1950. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  1951. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  1952. }
  1953. else if (j == ShowDataIndex)
  1954. {
  1955. row1.CreateCell(j);
  1956. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  1957. }
  1958. else
  1959. {
  1960. row1.CreateCell(j);
  1961. }
  1962. row1.GetCell(j).CellStyle = style;
  1963. }
  1964. row1 = sheet.CreateRow(PaintIndex);
  1965. PaintIndex = PaintIndex + 1;
  1966. //第二行添加型号
  1967. for (int j = 0; j < columnNum - 3; j++)
  1968. {
  1969. if (j == 0)
  1970. {
  1971. row1.CreateCell(j);
  1972. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  1973. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  1974. }
  1975. else if (j == ShowSizeIndex)
  1976. {
  1977. row1.CreateCell(j);
  1978. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  1979. }
  1980. else if (j == ShowDataIndex)
  1981. {
  1982. row1.CreateCell(j);
  1983. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  1984. }
  1985. else
  1986. {
  1987. row1.CreateCell(j);
  1988. }
  1989. row1.GetCell(j).CellStyle = style;
  1990. }
  1991. //特殊客户添加一列空行
  1992. row1 = sheet.CreateRow(PaintIndex);
  1993. PaintIndex = PaintIndex + 1;
  1994. for (int j = 0; j < columnNum; j++)
  1995. {
  1996. row1.CreateCell(j).SetCellValue("");
  1997. }
  1998. //添加列名
  1999. row1 = sheet.CreateRow(PaintIndex);
  2000. PaintIndex = PaintIndex + 1;
  2001. int showcount = 0;
  2002. for (int j = 4; j < columnNum; j++)
  2003. {
  2004. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  2005. {
  2006. showcount = showcount + 1;
  2007. row1.CreateCell(j - 4);
  2008. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2009. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  2010. }
  2011. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2012. {
  2013. showcount = showcount + 1;
  2014. row1.CreateCell(j - 4);
  2015. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2016. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  2017. }
  2018. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  2019. {
  2020. showcount = showcount + 1;
  2021. row1.CreateCell(j - 4);
  2022. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2023. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  2024. }
  2025. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2026. {
  2027. }
  2028. else
  2029. {
  2030. showcount = showcount + 1;
  2031. row1.CreateCell(j - 4);
  2032. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2033. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  2034. }
  2035. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  2036. {
  2037. NumIndex = j;
  2038. if (ShowCountIndex == NumIndex - 4)
  2039. {
  2040. ShowCountIndex = ShowCountIndex + 1;
  2041. }
  2042. }
  2043. }
  2044. ShowColumnCount = showcount;
  2045. row1 = sheet.CreateRow(PaintIndex);
  2046. PaintIndex = PaintIndex + 1;
  2047. }
  2048. }
  2049. //添加数据内容
  2050. for (int j = 4; j < columnNum; j++)
  2051. {
  2052. string Data = DataTable.Rows[i][j].ToString();
  2053. row1.CreateCell(j - 4);
  2054. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2055. {
  2056. }
  2057. else
  2058. {
  2059. row1.Cells[j - 4].SetCellValue(Data);
  2060. row1.GetCell(j - 4).CellStyle = styleborder;
  2061. }
  2062. if (DataTable.Columns[j].ColumnName == "io_qty")
  2063. {
  2064. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2065. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  2066. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  2067. }
  2068. if (DataTable.Columns[j].ColumnName == "rownum")
  2069. {
  2070. row1.Cells[j - 4].SetCellValue(i + 1);
  2071. }
  2072. if (DataTable.Columns[j].ColumnName == "ch_code")
  2073. {
  2074. sheet.AutoSizeColumn(j - 4);
  2075. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  2076. }
  2077. }
  2078. if (i == rowNum - 1)
  2079. {
  2080. row1 = sheet.CreateRow(PaintIndex);
  2081. PaintIndex = PaintIndex + 1;
  2082. for (int j = 0; j < ShowColumnCount; j++)
  2083. {
  2084. row1.CreateCell(j);
  2085. if (j == 0)
  2086. {
  2087. row1.Cells[j].SetCellValue(小计);
  2088. row1.Cells[j].CellStyle = styleborder;
  2089. }
  2090. else if (j == ShowPieceIndex)
  2091. {
  2092. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  2093. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2094. }
  2095. else if (j == ShowCountIndex)
  2096. {
  2097. row1.Cells[j].SetCellValue(sumCount);
  2098. row1.Cells[j].CellStyle = styleborder;
  2099. }
  2100. else
  2101. {
  2102. row1.Cells[j].CellStyle = styleborder;
  2103. }
  2104. }
  2105. //创建备注内容
  2106. row1 = sheet.CreateRow(PaintIndex);
  2107. for (int j = 0; j < columnNum - 3; j++)
  2108. {
  2109. if (j == 0)
  2110. {
  2111. row1.CreateCell(j);
  2112. row1.Cells[j].SetCellValue("备注");
  2113. }
  2114. else if (j == ShowCountIndex)
  2115. {
  2116. row1.CreateCell(j);
  2117. row1.Cells[j].SetCellValue(totalCount);
  2118. }
  2119. else if (j == ShowRemarkPiece)
  2120. {
  2121. row1.CreateCell(j);
  2122. row1.Cells[j].SetCellValue(rowNum + 片);
  2123. }
  2124. else
  2125. {
  2126. row1.CreateCell(j);
  2127. }
  2128. row1.Cells[j].CellStyle = style;
  2129. }
  2130. sheet.SetRowBreak(PaintIndex);
  2131. sheet.Footer.Center = "第&P页,共&N页";
  2132. PageNum = 0;
  2133. }
  2134. PageNum = PageNum + 1;
  2135. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  2136. pib_outboxcode1.Add(BoxCode.ToString());
  2137. }
  2138. //for (int i = 0; i < sheet.LastRowNum; i++)
  2139. //{
  2140. // if (i != 0)
  2141. // {
  2142. // sheet.AutoSizeColumn(i);
  2143. // sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  2144. // }
  2145. //}
  2146. break;
  2147. case "BoxCode":
  2148. string LastBoxCode = "";
  2149. int PageNum1 = 0;
  2150. for (int i = 0; i < rowNum; i++)
  2151. {
  2152. row1 = sheet.CreateRow(PaintIndex);
  2153. if (i != 0)
  2154. PaintIndex = PaintIndex + 1;
  2155. row1.HeightInPoints = RowHeight;
  2156. //如果箱号不相等的时候
  2157. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  2158. {
  2159. BoxCode = BoxCode + 1;
  2160. for (int j = 0; j < ShowColumnCount; j++)
  2161. {
  2162. row1.CreateCell(j);
  2163. if (j == 0)
  2164. {
  2165. row1.Cells[j].SetCellValue(小计);
  2166. row1.Cells[j].CellStyle = styleborder;
  2167. }
  2168. else if (j == ShowPieceIndex)
  2169. {
  2170. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 - 1 + 片);
  2171. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2172. }
  2173. else if (j == ShowCountIndex)
  2174. {
  2175. row1.Cells[j].SetCellValue(sumCount);
  2176. row1.Cells[j].CellStyle = styleborder;
  2177. }
  2178. else
  2179. {
  2180. row1.Cells[j].CellStyle = styleborder;
  2181. }
  2182. }
  2183. sumCount = 0;
  2184. //row1 = sheet.CreateRow(PaintIndex);
  2185. //sheet.SetRowBreak(PaintIndex - 1);
  2186. sheet.Footer.Center = "第&P页,共&N页";
  2187. PageNum1 = 0;
  2188. }
  2189. //每次到了页数开始分页
  2190. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  2191. {
  2192. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  2193. row1 = sheet.CreateRow(PaintIndex);
  2194. PaintIndex = PaintIndex + 1;
  2195. row1.CreateCell(0).SetCellValue(" " + companyname);
  2196. row1.GetCell(0).CellStyle = TitleStyle;
  2197. row1 = sheet.CreateRow(PaintIndex);
  2198. PaintIndex = PaintIndex + 1;
  2199. //第一行添加客户信息
  2200. //if (i != rowNum - 1)
  2201. {
  2202. for (int j = 0; j < columnNum - 3; j++)
  2203. {
  2204. if (j == 0)
  2205. {
  2206. row1.CreateCell(j);
  2207. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  2208. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  2209. }
  2210. else if (j == ShowDataIndex)
  2211. {
  2212. row1.CreateCell(j);
  2213. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  2214. }
  2215. else
  2216. {
  2217. row1.CreateCell(j);
  2218. }
  2219. row1.GetCell(j).CellStyle = style;
  2220. }
  2221. row1 = sheet.CreateRow(PaintIndex);
  2222. PaintIndex = PaintIndex + 1;
  2223. //第二行添加型号
  2224. for (int j = 0; j < columnNum - 3; j++)
  2225. {
  2226. if (j == 0)
  2227. {
  2228. row1.CreateCell(j);
  2229. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  2230. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2231. }
  2232. else if (j == ShowSizeIndex)
  2233. {
  2234. row1.CreateCell(j);
  2235. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  2236. }
  2237. else if (j == ShowDataIndex)
  2238. {
  2239. row1.CreateCell(j);
  2240. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  2241. }
  2242. else
  2243. {
  2244. row1.CreateCell(j);
  2245. }
  2246. row1.GetCell(j).CellStyle = style;
  2247. }
  2248. //特殊客户添加一列空行
  2249. row1 = sheet.CreateRow(PaintIndex);
  2250. PaintIndex = PaintIndex + 1;
  2251. for (int j = 0; j < columnNum; j++)
  2252. {
  2253. row1.CreateCell(j).SetCellValue("");
  2254. }
  2255. //添加列名
  2256. row1 = sheet.CreateRow(PaintIndex);
  2257. PaintIndex = PaintIndex + 1;
  2258. int showcount = 0;
  2259. for (int j = 4; j < columnNum; j++)
  2260. {
  2261. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  2262. {
  2263. showcount = showcount + 1;
  2264. row1.CreateCell(j - 4);
  2265. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2266. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  2267. }
  2268. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2269. {
  2270. showcount = showcount + 1;
  2271. row1.CreateCell(j - 4);
  2272. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2273. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  2274. }
  2275. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  2276. {
  2277. showcount = showcount + 1;
  2278. row1.CreateCell(j - 4);
  2279. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2280. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  2281. }
  2282. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2283. {
  2284. }
  2285. else
  2286. {
  2287. showcount = showcount + 1;
  2288. row1.CreateCell(j - 4);
  2289. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2290. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  2291. }
  2292. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  2293. {
  2294. NumIndex = j;
  2295. if (ShowCountIndex == NumIndex - 4)
  2296. {
  2297. ShowCountIndex = ShowCountIndex + 1;
  2298. }
  2299. }
  2300. }
  2301. ShowColumnCount = showcount;
  2302. row1 = sheet.CreateRow(PaintIndex);
  2303. PaintIndex = PaintIndex + 1;
  2304. }
  2305. }
  2306. //添加数据内容
  2307. for (int j = 4; j < columnNum; j++)
  2308. {
  2309. string Data = DataTable.Rows[i][j].ToString();
  2310. row1.CreateCell(j - 4);
  2311. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2312. {
  2313. }
  2314. else
  2315. {
  2316. row1.Cells[j - 4].SetCellValue(Data);
  2317. row1.GetCell(j - 4).CellStyle = styleborder;
  2318. }
  2319. if (DataTable.Columns[j].ColumnName == "io_qty")
  2320. {
  2321. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2322. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  2323. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  2324. }
  2325. if (DataTable.Columns[j].ColumnName == "rownum")
  2326. {
  2327. row1.Cells[j - 4].SetCellValue(i + 1);
  2328. }
  2329. if (DataTable.Columns[j].ColumnName == "ch_code")
  2330. {
  2331. sheet.AutoSizeColumn(j - 4);
  2332. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  2333. }
  2334. }
  2335. if (i == rowNum - 1)
  2336. {
  2337. PageNum1 = PageNum1 + 1;
  2338. row1 = sheet.CreateRow(PaintIndex);
  2339. PaintIndex = PaintIndex + 1;
  2340. for (int j = 0; j < ShowColumnCount; j++)
  2341. {
  2342. row1.CreateCell(j);
  2343. if (j == 0)
  2344. {
  2345. row1.Cells[j].SetCellValue(小计);
  2346. row1.Cells[j].CellStyle = styleborder;
  2347. }
  2348. else if (j == ShowPieceIndex)
  2349. {
  2350. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  2351. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2352. }
  2353. else if (j == ShowCountIndex)
  2354. {
  2355. row1.Cells[j].SetCellValue(sumCount);
  2356. row1.Cells[j].CellStyle = styleborder;
  2357. }
  2358. else
  2359. {
  2360. row1.Cells[j].CellStyle = styleborder;
  2361. }
  2362. }
  2363. row1 = sheet.CreateRow(PaintIndex);
  2364. for (int j = 0; j < columnNum - 3; j++)
  2365. {
  2366. if (j == 0)
  2367. {
  2368. row1.CreateCell(j);
  2369. row1.Cells[j].SetCellValue("备注");
  2370. }
  2371. else if (j == ShowCountIndex)
  2372. {
  2373. row1.CreateCell(j);
  2374. row1.Cells[j].SetCellValue(totalCount);
  2375. }
  2376. else if (j == ShowRemarkPiece)
  2377. {
  2378. row1.CreateCell(j);
  2379. row1.Cells[j].SetCellValue(rowNum + 片);
  2380. }
  2381. else
  2382. {
  2383. row1.CreateCell(j);
  2384. }
  2385. row1.Cells[j].CellStyle = style;
  2386. }
  2387. sheet.SetRowBreak(PaintIndex);
  2388. sheet.Footer.Center = "第&P页,共&N页";
  2389. PageNum1 = 0;
  2390. }
  2391. PageNum1 = PageNum1 + 1;
  2392. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  2393. pib_outboxcode1.Add(BoxCode.ToString());
  2394. }
  2395. //for (int i = 0; i < sheet.LastRowNum; i++)
  2396. //{
  2397. // if (i != 0)
  2398. // {
  2399. // sheet.AutoSizeColumn(i);
  2400. // sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  2401. // }
  2402. //}
  2403. break;
  2404. default:
  2405. break;
  2406. }
  2407. 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());
  2408. //删除下载链接再重新插入
  2409. HttpHandler.GenDownLoadLinK(Inoutno);
  2410. //填充首页
  2411. sumCount = 0;
  2412. totalCount = 0;
  2413. PaintIndex = 0;
  2414. ISheet sheet2 = book.CreateSheet("首页");
  2415. IRow row = sheet2.CreateRow(0);
  2416. row.CreateCell(0);
  2417. row.Cells[0].SetCellValue(" " + companyname);
  2418. row.GetCell(0).CellStyle = style;
  2419. rowNum = FirstDT.Rows.Count;
  2420. //不需要显示的列移除
  2421. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  2422. {
  2423. for (int j = 0; j < box.Length; j++)
  2424. {
  2425. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  2426. {
  2427. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  2428. {
  2429. FirstDT.Columns.RemoveAt(i);
  2430. }
  2431. }
  2432. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  2433. {
  2434. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  2435. {
  2436. FirstDT.Columns.RemoveAt(i);
  2437. }
  2438. }
  2439. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  2440. {
  2441. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  2442. {
  2443. FirstDT.Columns.RemoveAt(i);
  2444. }
  2445. }
  2446. }
  2447. }
  2448. columnNum = FirstDT.Columns.Count;
  2449. for (int i = 0; i < rowNum; i++)
  2450. {
  2451. row1 = sheet2.CreateRow(PaintIndex);
  2452. PaintIndex = PaintIndex + 1;
  2453. row1.HeightInPoints = RowHeight;
  2454. //只需要绘制一行
  2455. if (i == 0)
  2456. {
  2457. for (int j = 0; j < columnNum - 3; j++)
  2458. {
  2459. if (j == 0)
  2460. {
  2461. row1.CreateCell(j);
  2462. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString());
  2463. }
  2464. else if (j > 5 && j == columnNum - 5)
  2465. {
  2466. row1.CreateCell(j);
  2467. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  2468. }
  2469. else if (columnNum > 5 && j == columnNum - 5)
  2470. {
  2471. row1.CreateCell(j);
  2472. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  2473. }
  2474. else
  2475. {
  2476. row1.CreateCell(j);
  2477. }
  2478. row1.GetCell(j).CellStyle = style;
  2479. }
  2480. row1 = sheet2.CreateRow(PaintIndex);
  2481. PaintIndex = PaintIndex + 1;
  2482. //第二行添加型号
  2483. for (int j = 0; j < columnNum - 3; j++)
  2484. {
  2485. if (j == 0)
  2486. {
  2487. row1.CreateCell(j);
  2488. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString());
  2489. }
  2490. else if (j > 5 && j == columnNum - 5)
  2491. {
  2492. row1.CreateCell(j);
  2493. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  2494. }
  2495. else if (columnNum > 5 && j == columnNum - 5)
  2496. {
  2497. row1.CreateCell(j);
  2498. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  2499. }
  2500. else
  2501. {
  2502. row1.CreateCell(j);
  2503. }
  2504. row1.GetCell(j).CellStyle = style;
  2505. }
  2506. row1 = sheet2.CreateRow(PaintIndex);
  2507. PaintIndex = PaintIndex + 1;
  2508. //添加列名
  2509. for (int j = 4; j < columnNum; j++)
  2510. {
  2511. row1.CreateCell(j - 4);
  2512. row1.Cells[j - 4].CellStyle = styleborder;
  2513. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  2514. }
  2515. row1 = sheet2.CreateRow(PaintIndex);
  2516. PaintIndex = PaintIndex + 1;
  2517. }
  2518. //添加数据内容
  2519. for (int j = 4; j < columnNum; j++)
  2520. {
  2521. string Data = FirstDT.Rows[i][j].ToString();
  2522. row1.CreateCell(j - 4);
  2523. row1.Cells[j - 4].SetCellValue(Data);
  2524. row1.GetCell(j - 4).CellStyle = styleborder;
  2525. if (FirstDT.Columns[j].ColumnName == "num")
  2526. {
  2527. sumCount += int.Parse(Data);
  2528. }
  2529. if (FirstDT.Columns[j].ColumnName == "io_qty")
  2530. {
  2531. totalCount += int.Parse(Data);
  2532. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2533. }
  2534. }
  2535. //添加总计行
  2536. if (i == rowNum - 1)
  2537. {
  2538. row1 = sheet2.CreateRow(PaintIndex);
  2539. PaintIndex = PaintIndex + 1;
  2540. for (int j = 0; j < columnNum - 4; j++)
  2541. {
  2542. if (j == 0)
  2543. {
  2544. row1.CreateCell(j);
  2545. row1.Cells[j].CellStyle = styleborder;
  2546. row1.Cells[j].SetCellValue(总计);
  2547. }
  2548. else if (j == columnNum - 6)
  2549. {
  2550. row1.CreateCell(j);
  2551. row1.Cells[j].CellStyle = styleborder;
  2552. row1.Cells[j].SetCellValue(sumCount);
  2553. }
  2554. else if (j == columnNum - 5)
  2555. {
  2556. row1.CreateCell(j);
  2557. row1.Cells[j].CellStyle = styleborder;
  2558. row1.Cells[j].SetCellValue(totalCount);
  2559. }
  2560. else
  2561. {
  2562. row1.CreateCell(j);
  2563. row1.Cells[j].CellStyle = styleborder;
  2564. }
  2565. }
  2566. }
  2567. }
  2568. for (int i = 0; i < sheet2.LastRowNum; i++)
  2569. {
  2570. if (i != 0)
  2571. {
  2572. sheet2.AutoSizeColumn(i);
  2573. sheet2.SetColumnWidth(i, sheet2.GetColumnWidth(i) + 1000);
  2574. }
  2575. }
  2576. //将book的内容写入内存流中返回
  2577. book.Write(ms);
  2578. return ms;
  2579. }
  2580. /// <summary>
  2581. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  2582. /// </summary>
  2583. /// <param name="DataTable"></param>
  2584. /// <returns></returns>
  2585. private MemoryStream DataTableToExcel_LIPUXIN(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  2586. {
  2587. string 小计 = "";
  2588. string 批小计 = "";
  2589. string 总计 = "";
  2590. string 片 = "";
  2591. string companyname = "";
  2592. int ShowBoxIndex = 0;
  2593. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype", "pi_inoutno='" + Inoutno + "'").ToString() == "Chinese")
  2594. {
  2595. 小计 = "小计";
  2596. 总计 = "总计";
  2597. 批小计 = "批小计";
  2598. companyname = "深爱半导体股份有限公司芯片出货清单";
  2599. }
  2600. else
  2601. {
  2602. 批小计 = "BatchTotal";
  2603. 小计 = "total";
  2604. 总计 = "total";
  2605. companyname = "SHENZHEN SI SEMICONDUCTORS CO.,LTD";
  2606. }
  2607. //转换为序列
  2608. CheckBox[] box = conditionbox.ToArray();
  2609. //创建内存流
  2610. MemoryStream ms = new MemoryStream();
  2611. //创建一个Book,相当于一个Excel文件
  2612. HSSFWorkbook book = new HSSFWorkbook();
  2613. //Excel中的Sheet
  2614. ISheet sheet = book.CreateSheet("分页");
  2615. sheet.SetMargin(MarginType.TopMargin, 0.4);
  2616. sheet.SetMargin(MarginType.BottomMargin, 0.4);
  2617. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  2618. sheet.SetMargin(MarginType.RightMargin, 0.4);
  2619. sheet.FitToPage = true;
  2620. sheet.PrintSetup.FitHeight = 200;
  2621. //芯片号需要作为更新盒号的条件
  2622. HSSFFont ffont = (HSSFFont)book.CreateFont();
  2623. ffont.FontName = "宋体";
  2624. //更新箱号
  2625. List<string> pib_id = new List<string>();
  2626. //系统打印箱号
  2627. List<string> pib_outboxcode1 = new List<string>();
  2628. int BoxCode = 1;
  2629. ICellStyle style = book.CreateCellStyle();
  2630. style.VerticalAlignment = VerticalAlignment.Center;
  2631. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  2632. style.SetFont(ffont);
  2633. ICellStyle styleborder = book.CreateCellStyle();
  2634. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2635. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2636. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2637. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2638. styleborder.VerticalAlignment = VerticalAlignment.Center;
  2639. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  2640. styleborder.SetFont(ffont);
  2641. string pi_inoutno = "";
  2642. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  2643. ColumnTitle.FontName = "宋体";
  2644. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  2645. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  2646. ColumnTitleStyle.SetFont(ColumnTitle);
  2647. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2648. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2649. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2650. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2651. List<string> NotShowColumn = new List<string>();
  2652. NotShowColumn.Add("ch_level");
  2653. NotShowColumn.Add("pib_id");
  2654. NotShowColumn.Add("chw_itemname1");
  2655. NotShowColumn.Add("chw_itemname2");
  2656. NotShowColumn.Add("chw_itemname3");
  2657. NotShowColumn.Add("pd_ordercode");
  2658. NotShowColumn.Add("pr_size");
  2659. NotShowColumn.Add("me_desc");
  2660. NotShowColumn.Add("pr_orispeccode");
  2661. NotShowColumn.Add("pr_orispeccode1");
  2662. NotShowColumn.Add("pi_title");
  2663. NotShowColumn.Add("pi_chipouttype");
  2664. NotShowColumn.Add("pi_date");
  2665. int ShowColumnCount = 0;
  2666. //展示的内容列
  2667. //设置列的宽度,根据首行的列的内容的长度来设置
  2668. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  2669. {
  2670. for (int j = 0; j < box.Length; j++)
  2671. {
  2672. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  2673. {
  2674. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  2675. {
  2676. DataTable.Columns.RemoveAt(i);
  2677. break;
  2678. }
  2679. }
  2680. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  2681. {
  2682. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  2683. {
  2684. DataTable.Columns.RemoveAt(i);
  2685. break;
  2686. }
  2687. }
  2688. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  2689. {
  2690. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  2691. {
  2692. DataTable.Columns.RemoveAt(i);
  2693. break;
  2694. }
  2695. }
  2696. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  2697. {
  2698. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  2699. {
  2700. DataTable.Columns.RemoveAt(i);
  2701. break;
  2702. }
  2703. }
  2704. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  2705. {
  2706. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  2707. {
  2708. DataTable.Columns.RemoveAt(i);
  2709. break;
  2710. }
  2711. }
  2712. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  2713. {
  2714. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  2715. {
  2716. DataTable.Columns.RemoveAt(i);
  2717. break;
  2718. }
  2719. }
  2720. if (box[j].Name.ToLower() == "ch_yield" && !box[j].Checked)
  2721. {
  2722. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_yield"))
  2723. {
  2724. DataTable.Columns.RemoveAt(i);
  2725. break;
  2726. }
  2727. }
  2728. }
  2729. }
  2730. //获取行数量和列数量
  2731. int rowNum = DataTable.Rows.Count;
  2732. int columnNum = DataTable.Columns.Count;
  2733. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  2734. IRow row = sheet.CreateRow(0);
  2735. //冻结第一行
  2736. sheet.CreateFreezePane(0, 1, 0, 1);
  2737. row.HeightInPoints = RowHeight;
  2738. //固定第一行
  2739. //row.RowStyle.IsLocked=true;
  2740. //给第一行的标签赋值样式和值
  2741. // ffont.FontHeight = 13;
  2742. row.CreateCell(0);
  2743. row.Cells[0].SetCellValue(" " + companyname);
  2744. row.GetCell(0).CellStyle.SetFont((ffont));
  2745. //ffont.FontHeight = 10;
  2746. //开始绘制的Index
  2747. int PaintIndex = 1;
  2748. int sumCount = 0;
  2749. int totalCount = 0;
  2750. switch (Type)
  2751. {
  2752. case "FixRow":
  2753. //清理系统取出来的数据
  2754. BaseUtil.CleanDataTableData(FirstDT);
  2755. //首页参数拼接
  2756. string First_OrderCode = "";
  2757. string First_Prspec = "";
  2758. string First_Batch = "";
  2759. int NumIndex = 0;
  2760. ArrayList<string> First_WID = new ArrayList<string>();
  2761. for (int i = 0; i < rowNum; i++)
  2762. {
  2763. IRow row1 = sheet.CreateRow(PaintIndex);
  2764. PaintIndex = PaintIndex + 1;
  2765. row1.HeightInPoints = RowHeight;
  2766. //不包含的订单号
  2767. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  2768. {
  2769. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  2770. }
  2771. //不包含的物料型号
  2772. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  2773. {
  2774. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  2775. }
  2776. //不包含扩撒批号
  2777. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  2778. {
  2779. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  2780. }
  2781. //不包含Wafer_id
  2782. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  2783. {
  2784. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  2785. }
  2786. if (i / PageSize >= 1 && i % PageSize == 0)
  2787. {
  2788. DataRow dr = FirstDT.NewRow();
  2789. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  2790. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  2791. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  2792. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  2793. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  2794. dr["pd_ordercode"] = First_OrderCode;
  2795. dr["pr_orispeccode"] = First_Prspec;
  2796. dr["ch_splitbatch"] = First_Batch;
  2797. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  2798. dr["num"] = PageSize;
  2799. dr["io_qty"] = sumCount;
  2800. FirstDT.Rows.Add(dr);
  2801. First_OrderCode = "";
  2802. First_Prspec = "";
  2803. First_Batch = "";
  2804. First_WID.Clear();
  2805. BoxCode = BoxCode + 1;
  2806. for (int j = 0; j < ShowColumnCount; j++)
  2807. {
  2808. row1.CreateCell(j);
  2809. if (j == 0)
  2810. {
  2811. row1.Cells[j].SetCellValue(批小计);
  2812. }
  2813. else if (j == ShowPieceIndex)
  2814. {
  2815. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i) + 片);
  2816. row1.Cells[j].CellStyle = styleborder;
  2817. }
  2818. else if (j == ShowCountIndex)
  2819. {
  2820. row1.Cells[j].SetCellValue(sumCount);
  2821. }
  2822. else if (j == ShowBoxIndex)
  2823. {
  2824. row1.Cells[j].SetCellValue(DataTable.Rows[i]["ch_pbcode"].ToString());
  2825. row1.Cells[j].CellStyle = styleborder;
  2826. }
  2827. row1.Cells[j].CellStyle = styleborder;
  2828. }
  2829. row1 = sheet.CreateRow(PaintIndex);
  2830. PaintIndex = PaintIndex + 1;
  2831. for (int j = 0; j < ShowColumnCount; j++)
  2832. {
  2833. row1.CreateCell(j);
  2834. if (j == 0)
  2835. {
  2836. row1.Cells[j].SetCellValue(小计);
  2837. }
  2838. else if (j == ShowPieceIndex)
  2839. {
  2840. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i) + 片);
  2841. }
  2842. else if (j == ShowCountIndex)
  2843. {
  2844. row1.Cells[j].SetCellValue(sumCount);
  2845. }
  2846. else if (j == ShowBoxIndex)
  2847. {
  2848. row1.Cells[j].SetCellValue(DataTable.Rows[i]["ch_pbcode"].ToString());
  2849. row1.Cells[j].CellStyle = styleborder;
  2850. }
  2851. row1.Cells[j].CellStyle = styleborder;
  2852. }
  2853. sumCount = 0;
  2854. row1 = sheet.CreateRow(PaintIndex);
  2855. sheet.SetRowBreak(PaintIndex - 1);
  2856. sheet.Footer.Center = "第&P页,共&N页";
  2857. PaintIndex = PaintIndex + 1;
  2858. }
  2859. //每次到了页数开始分页
  2860. if (i % PageSize == 0 || i == rowNum - 1)
  2861. {
  2862. //第一行添加客户信息 rownum只有一行的情
  2863. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  2864. {
  2865. for (int j = 0; j < columnNum - 3; j++)
  2866. {
  2867. if (j == 0)
  2868. {
  2869. row1.CreateCell(j);
  2870. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  2871. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  2872. }
  2873. else if (j == ShowDataIndex)
  2874. {
  2875. row1.CreateCell(j);
  2876. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  2877. }
  2878. else
  2879. {
  2880. row1.CreateCell(j);
  2881. }
  2882. row1.GetCell(j).CellStyle = style;
  2883. }
  2884. row1 = sheet.CreateRow(PaintIndex);
  2885. PaintIndex = PaintIndex + 1;
  2886. //第二行添加型号
  2887. for (int j = 0; j < columnNum - 3; j++)
  2888. {
  2889. if (j == 0)
  2890. {
  2891. row1.CreateCell(j);
  2892. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString()
  2893. + "_(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2894. }
  2895. else if (j == ShowSizeIndex)
  2896. {
  2897. row1.CreateCell(j);
  2898. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  2899. }
  2900. else if (j == ShowDataIndex)
  2901. {
  2902. row1.CreateCell(j);
  2903. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  2904. }
  2905. else
  2906. {
  2907. row1.CreateCell(j);
  2908. }
  2909. row1.GetCell(j).CellStyle = style;
  2910. }
  2911. //添加列名
  2912. row1 = sheet.CreateRow(PaintIndex);
  2913. PaintIndex = PaintIndex + 1;
  2914. //计数列所在的索引
  2915. int showcount = 0;
  2916. for (int j = 4; j < columnNum; j++)
  2917. {
  2918. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  2919. {
  2920. showcount = showcount + 1;
  2921. row1.CreateCell(j - 4);
  2922. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2923. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  2924. }
  2925. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2926. {
  2927. showcount = showcount + 1;
  2928. row1.CreateCell(j - 4);
  2929. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2930. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  2931. }
  2932. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  2933. {
  2934. showcount = showcount + 1;
  2935. row1.CreateCell(j - 4);
  2936. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2937. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  2938. }
  2939. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2940. {
  2941. }
  2942. else
  2943. {
  2944. showcount = showcount + 1;
  2945. row1.CreateCell(j - 4);
  2946. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2947. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  2948. }
  2949. if (DataTable.Columns[j].ColumnName.ToString() == "ch_pbcode")
  2950. {
  2951. ShowBoxIndex = j;
  2952. }
  2953. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  2954. {
  2955. NumIndex = j;
  2956. if (ShowCountIndex == NumIndex - 4)
  2957. {
  2958. ShowCountIndex = ShowCountIndex + 1;
  2959. }
  2960. }
  2961. }
  2962. ShowColumnCount = showcount;
  2963. row1 = sheet.CreateRow(PaintIndex);
  2964. PaintIndex = PaintIndex + 1;
  2965. }
  2966. }
  2967. //添加数据内容
  2968. for (int j = 4; j < columnNum; j++)
  2969. {
  2970. string Data = DataTable.Rows[i][j].ToString();
  2971. row1.CreateCell(j - 4);
  2972. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2973. {
  2974. }
  2975. else
  2976. {
  2977. row1.Cells[j - 4].SetCellValue(Data);
  2978. row1.GetCell(j - 4).CellStyle = styleborder;
  2979. }
  2980. if (DataTable.Columns[j].ColumnName == "io_qty")
  2981. {
  2982. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2983. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  2984. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  2985. }
  2986. if (DataTable.Columns[j].ColumnName == "rownum")
  2987. {
  2988. row1.Cells[j - 4].SetCellValue(i + 1);
  2989. }
  2990. if (DataTable.Columns[j].ColumnName == "ch_code")
  2991. {
  2992. sheet.AutoSizeColumn(j - 4);
  2993. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  2994. }
  2995. }
  2996. //固定行号分组的时候自动拼接新的DataTable
  2997. if (i == rowNum - 1)
  2998. {
  2999. DataRow dr = FirstDT.NewRow();
  3000. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  3001. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  3002. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  3003. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  3004. dr["pd_ordercode"] = First_OrderCode;
  3005. dr["pr_orispeccode"] = First_Prspec;
  3006. dr["ch_splitbatch"] = First_Batch;
  3007. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  3008. dr["num"] = (i % PageSize) + 1;
  3009. dr["io_qty"] = sumCount;
  3010. FirstDT.Rows.Add(dr);
  3011. row1 = sheet.CreateRow(PaintIndex);
  3012. PaintIndex = PaintIndex + 1;
  3013. for (int j = 0; j < ShowColumnCount; j++)
  3014. {
  3015. row1.CreateCell(j);
  3016. if (j == 0)
  3017. {
  3018. row1.Cells[j].SetCellValue(批小计);
  3019. }
  3020. else if (j == ShowPieceIndex)
  3021. {
  3022. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize == 0 ? PageSize : (rowNum % PageSize)) + 片);
  3023. row1.Cells[j].CellStyle = styleborder;
  3024. }
  3025. else if (j == ShowBoxIndex)
  3026. {
  3027. row1.Cells[j].SetCellValue(DataTable.Rows[i]["ch_pbcode"].ToString());
  3028. row1.Cells[j].CellStyle = styleborder;
  3029. }
  3030. else if (j == ShowCountIndex)
  3031. {
  3032. row1.Cells[j].SetCellValue(sumCount);
  3033. }
  3034. row1.Cells[j].CellStyle = styleborder;
  3035. }
  3036. row1 = sheet.CreateRow(PaintIndex);
  3037. PaintIndex = PaintIndex + 1;
  3038. for (int j = 0; j < ShowColumnCount; j++)
  3039. {
  3040. row1.CreateCell(j);
  3041. if (j == 0)
  3042. {
  3043. row1.Cells[j].SetCellValue(小计);
  3044. }
  3045. else if (j == ShowPieceIndex)
  3046. {
  3047. row1.Cells[ShowPieceIndex].SetCellValue(rowNum % PageSize + 片);
  3048. row1.Cells[j].CellStyle = styleborder;
  3049. }
  3050. else if (j == ShowBoxIndex)
  3051. {
  3052. row1.Cells[j].SetCellValue(DataTable.Rows[i]["ch_pbcode"].ToString());
  3053. row1.Cells[j].CellStyle = styleborder;
  3054. }
  3055. else if (j == ShowCountIndex)
  3056. {
  3057. row1.Cells[j].SetCellValue(sumCount);
  3058. }
  3059. row1.Cells[j].CellStyle = styleborder;
  3060. }
  3061. row1 = sheet.CreateRow(PaintIndex);
  3062. for (int j = 0; j < columnNum - 3; j++)
  3063. {
  3064. if (j == 0)
  3065. {
  3066. row1.CreateCell(j);
  3067. row1.Cells[j].SetCellValue("备注");
  3068. }
  3069. else if (j == ShowCountIndex)
  3070. {
  3071. row1.CreateCell(j);
  3072. row1.Cells[j].SetCellValue(totalCount);
  3073. }
  3074. else if (j == ShowRemarkPiece)
  3075. {
  3076. row1.CreateCell(j);
  3077. row1.Cells[j].SetCellValue(rowNum + 片);
  3078. }
  3079. else
  3080. {
  3081. row1.CreateCell(j);
  3082. }
  3083. row1.Cells[j].CellStyle = style;
  3084. }
  3085. sheet.SetRowBreak(PaintIndex);
  3086. sheet.Footer.Center = "第&P页,共&N页";
  3087. PaintIndex = PaintIndex + 1;
  3088. }
  3089. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3090. pib_outboxcode1.Add(BoxCode.ToString());
  3091. }
  3092. //for (int i = 0; i < sheet.LastRowNum; i++)
  3093. //{
  3094. // if (i != 0)
  3095. // {
  3096. // sheet.AutoSizeColumn(i);
  3097. // sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  3098. // }
  3099. //}
  3100. break;
  3101. case "BatchCode":
  3102. string LastBatchCode = "";
  3103. int PageNum = 0;
  3104. for (int i = 0; i < rowNum; i++)
  3105. {
  3106. IRow row1 = sheet.CreateRow(PaintIndex);
  3107. PaintIndex = PaintIndex + 1;
  3108. row1.HeightInPoints = RowHeight;
  3109. //如果批号不相等的时候
  3110. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  3111. {
  3112. BoxCode = BoxCode + 1;
  3113. for (int j = 0; j < ShowColumnCount; j++)
  3114. {
  3115. row1.CreateCell(j);
  3116. if (j == 0)
  3117. {
  3118. row1.Cells[j].SetCellValue(批小计);
  3119. row1.Cells[j].CellStyle = styleborder;
  3120. }
  3121. else if (j == ShowPieceIndex)
  3122. {
  3123. row1.Cells[ShowPieceIndex].SetCellValue(PageNum - 1 + 片);
  3124. row1.Cells[j].CellStyle = styleborder;
  3125. }
  3126. else if (j == ShowCountIndex)
  3127. {
  3128. row1.Cells[j].SetCellValue(sumCount);
  3129. row1.Cells[j].CellStyle = styleborder;
  3130. }
  3131. else if (j == ShowBoxIndex)
  3132. {
  3133. row1.Cells[j].SetCellValue(DataTable.Rows[i]["ch_pbcode"].ToString());
  3134. row1.Cells[j].CellStyle = styleborder;
  3135. }
  3136. else
  3137. {
  3138. row1.Cells[j].CellStyle = styleborder;
  3139. }
  3140. }
  3141. row1 = sheet.CreateRow(PaintIndex);
  3142. PaintIndex = PaintIndex + 1;
  3143. for (int j = 0; j < ShowColumnCount; j++)
  3144. {
  3145. row1.CreateCell(j);
  3146. if (j == 0)
  3147. {
  3148. row1.Cells[j].SetCellValue(小计);
  3149. row1.Cells[j].CellStyle = styleborder;
  3150. }
  3151. else if (j == ShowPieceIndex)
  3152. {
  3153. row1.Cells[ShowPieceIndex].SetCellValue(PageNum - 1 + 片);
  3154. row1.Cells[j].CellStyle = styleborder;
  3155. }
  3156. else if (j == ShowCountIndex)
  3157. {
  3158. row1.Cells[j].SetCellValue(sumCount);
  3159. row1.Cells[j].CellStyle = styleborder;
  3160. }
  3161. else if (j == ShowBoxIndex)
  3162. {
  3163. row1.Cells[j].SetCellValue(DataTable.Rows[i]["ch_pbcode"].ToString());
  3164. row1.Cells[j].CellStyle = styleborder;
  3165. }
  3166. else
  3167. {
  3168. row1.Cells[j].CellStyle = styleborder;
  3169. }
  3170. }
  3171. sumCount = 0;
  3172. row1 = sheet.CreateRow(PaintIndex);
  3173. sheet.SetRowBreak(PaintIndex - 1);
  3174. sheet.Footer.Center = "第&P页,共&N页";
  3175. PaintIndex = PaintIndex + 1;
  3176. PageNum = 0;
  3177. }
  3178. //每次到了页数开始分页
  3179. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()) || i == rowNum - 1)
  3180. {
  3181. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  3182. //第一行添加客户信息
  3183. //if (i != rowNum - 1)
  3184. {
  3185. for (int j = 0; j < columnNum - 3; j++)
  3186. {
  3187. if (j == 0)
  3188. {
  3189. row1.CreateCell(j);
  3190. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  3191. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  3192. }
  3193. else if (j == ShowDataIndex)
  3194. {
  3195. row1.CreateCell(j);
  3196. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  3197. }
  3198. else
  3199. {
  3200. row1.CreateCell(j);
  3201. }
  3202. row1.GetCell(j).CellStyle = style;
  3203. }
  3204. row1 = sheet.CreateRow(PaintIndex);
  3205. PaintIndex = PaintIndex + 1;
  3206. //第二行添加型号
  3207. for (int j = 0; j < columnNum - 3; j++)
  3208. {
  3209. if (j == 0)
  3210. {
  3211. row1.CreateCell(j);
  3212. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  3213. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  3214. }
  3215. else if (j == ShowSizeIndex)
  3216. {
  3217. row1.CreateCell(j);
  3218. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  3219. }
  3220. else if (j == ShowDataIndex)
  3221. {
  3222. row1.CreateCell(j);
  3223. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  3224. }
  3225. else
  3226. {
  3227. row1.CreateCell(j);
  3228. }
  3229. row1.GetCell(j).CellStyle = style;
  3230. }
  3231. //添加列名
  3232. row1 = sheet.CreateRow(PaintIndex);
  3233. PaintIndex = PaintIndex + 1;
  3234. int showcount = 0;
  3235. for (int j = 4; j < columnNum; j++)
  3236. {
  3237. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  3238. {
  3239. showcount = showcount + 1;
  3240. row1.CreateCell(j - 4);
  3241. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3242. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  3243. }
  3244. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  3245. {
  3246. showcount = showcount + 1;
  3247. row1.CreateCell(j - 4);
  3248. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3249. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  3250. }
  3251. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  3252. {
  3253. showcount = showcount + 1;
  3254. row1.CreateCell(j - 4);
  3255. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3256. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  3257. }
  3258. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3259. {
  3260. }
  3261. else
  3262. {
  3263. showcount = showcount + 1;
  3264. row1.CreateCell(j - 4);
  3265. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3266. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  3267. }
  3268. if (DataTable.Columns[j].ColumnName.ToString() == "ch_pbcode")
  3269. {
  3270. ShowBoxIndex = j;
  3271. }
  3272. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  3273. {
  3274. NumIndex = j;
  3275. if (ShowCountIndex == NumIndex - 4)
  3276. {
  3277. ShowCountIndex = ShowCountIndex + 1;
  3278. }
  3279. }
  3280. }
  3281. ShowColumnCount = showcount;
  3282. row1 = sheet.CreateRow(PaintIndex);
  3283. PaintIndex = PaintIndex + 1;
  3284. }
  3285. }
  3286. //添加数据内容
  3287. for (int j = 4; j < columnNum; j++)
  3288. {
  3289. string Data = DataTable.Rows[i][j].ToString();
  3290. row1.CreateCell(j - 4);
  3291. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3292. {
  3293. }
  3294. else
  3295. {
  3296. row1.Cells[j - 4].SetCellValue(Data);
  3297. row1.GetCell(j - 4).CellStyle = styleborder;
  3298. }
  3299. if (DataTable.Columns[j].ColumnName == "io_qty")
  3300. {
  3301. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3302. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  3303. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  3304. }
  3305. if (DataTable.Columns[j].ColumnName == "rownum")
  3306. {
  3307. row1.Cells[j - 4].SetCellValue(i + 1);
  3308. }
  3309. if (DataTable.Columns[j].ColumnName == "ch_code")
  3310. {
  3311. sheet.AutoSizeColumn(j - 4);
  3312. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  3313. }
  3314. }
  3315. if (i == rowNum - 1)
  3316. {
  3317. row1 = sheet.CreateRow(PaintIndex);
  3318. PaintIndex = PaintIndex + 1;
  3319. for (int j = 0; j < ShowColumnCount; j++)
  3320. {
  3321. row1.CreateCell(j);
  3322. if (j == 0)
  3323. {
  3324. row1.Cells[j].SetCellValue(批小计);
  3325. row1.Cells[j].CellStyle = styleborder;
  3326. }
  3327. else if (j == ShowPieceIndex)
  3328. {
  3329. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  3330. row1.Cells[j].CellStyle = styleborder;
  3331. }
  3332. else if (j == ShowCountIndex)
  3333. {
  3334. row1.Cells[j].SetCellValue(sumCount);
  3335. row1.Cells[j].CellStyle = styleborder;
  3336. }
  3337. else
  3338. {
  3339. row1.Cells[j].CellStyle = styleborder;
  3340. }
  3341. }
  3342. row1 = sheet.CreateRow(PaintIndex);
  3343. PaintIndex = PaintIndex + 1;
  3344. for (int j = 0; j < ShowColumnCount; j++)
  3345. {
  3346. row1.CreateCell(j);
  3347. if (j == 0)
  3348. {
  3349. row1.Cells[j].SetCellValue(小计);
  3350. row1.Cells[j].CellStyle = styleborder;
  3351. }
  3352. else if (j == ShowPieceIndex)
  3353. {
  3354. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  3355. row1.Cells[j].CellStyle = styleborder;
  3356. }
  3357. else if (j == ShowCountIndex)
  3358. {
  3359. row1.Cells[j].SetCellValue(sumCount);
  3360. row1.Cells[j].CellStyle = styleborder;
  3361. }
  3362. else
  3363. {
  3364. row1.Cells[j].CellStyle = styleborder;
  3365. }
  3366. }
  3367. //创建备注内容
  3368. row1 = sheet.CreateRow(PaintIndex);
  3369. for (int j = 0; j < columnNum - 3; j++)
  3370. {
  3371. if (j == 0)
  3372. {
  3373. row1.CreateCell(j);
  3374. row1.Cells[j].SetCellValue("备注");
  3375. }
  3376. else if (j == ShowCountIndex)
  3377. {
  3378. row1.CreateCell(j);
  3379. row1.Cells[j].SetCellValue(totalCount);
  3380. }
  3381. else if (j == ShowRemarkPiece)
  3382. {
  3383. row1.CreateCell(j);
  3384. row1.Cells[j].SetCellValue(rowNum + 片);
  3385. }
  3386. else
  3387. {
  3388. row1.CreateCell(j);
  3389. }
  3390. row1.Cells[j].CellStyle = style;
  3391. }
  3392. sheet.SetRowBreak(PaintIndex);
  3393. sheet.Footer.Center = "第&P页,共&N页";
  3394. PaintIndex = PaintIndex + 1;
  3395. PageNum = 0;
  3396. }
  3397. PageNum = PageNum + 1;
  3398. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3399. pib_outboxcode1.Add(BoxCode.ToString());
  3400. }
  3401. //for (int i = 0; i < sheet.LastRowNum; i++)
  3402. //{
  3403. // if (i != 0)
  3404. // {
  3405. // sheet.AutoSizeColumn(i);
  3406. // sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  3407. // }
  3408. //}
  3409. break;
  3410. case "BoxCode":
  3411. string LastBoxCode = "";
  3412. int PageNum1 = 0;
  3413. for (int i = 0; i < rowNum; i++)
  3414. {
  3415. IRow row1 = sheet.CreateRow(PaintIndex);
  3416. PaintIndex = PaintIndex + 1;
  3417. row1.HeightInPoints = RowHeight;
  3418. //如果批号不相等的时候
  3419. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  3420. {
  3421. BoxCode = BoxCode + 1;
  3422. for (int j = 0; j < ShowColumnCount; j++)
  3423. {
  3424. row1.CreateCell(j);
  3425. if (j == 0)
  3426. {
  3427. row1.Cells[j].SetCellValue(批小计);
  3428. row1.Cells[j].CellStyle = styleborder;
  3429. }
  3430. else if (j == ShowPieceIndex)
  3431. {
  3432. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3433. row1.Cells[j].CellStyle = styleborder;
  3434. }
  3435. else if (j == ShowCountIndex)
  3436. {
  3437. row1.Cells[j].SetCellValue(sumCount);
  3438. row1.Cells[j].CellStyle = styleborder;
  3439. }
  3440. else if (j == ShowBoxIndex)
  3441. {
  3442. row1.Cells[j].SetCellValue(DataTable.Rows[i]["ch_pbcode"].ToString());
  3443. row1.Cells[j].CellStyle = styleborder;
  3444. }
  3445. else
  3446. {
  3447. row1.Cells[j].CellStyle = styleborder;
  3448. }
  3449. }
  3450. row1 = sheet.CreateRow(PaintIndex);
  3451. PaintIndex = PaintIndex + 1;
  3452. for (int j = 0; j < ShowColumnCount; j++)
  3453. {
  3454. row1.CreateCell(j);
  3455. if (j == 0)
  3456. {
  3457. row1.Cells[j].SetCellValue(小计);
  3458. row1.Cells[j].CellStyle = styleborder;
  3459. }
  3460. else if (j == ShowPieceIndex)
  3461. {
  3462. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3463. row1.Cells[j].CellStyle = styleborder;
  3464. }
  3465. else if (j == ShowCountIndex)
  3466. {
  3467. row1.Cells[j].SetCellValue(sumCount);
  3468. row1.Cells[j].CellStyle = styleborder;
  3469. }
  3470. else if (j == ShowBoxIndex)
  3471. {
  3472. row1.Cells[j].SetCellValue(DataTable.Rows[i]["ch_pbcode"].ToString());
  3473. row1.Cells[j].CellStyle = styleborder;
  3474. }
  3475. else
  3476. {
  3477. row1.Cells[j].CellStyle = styleborder;
  3478. }
  3479. }
  3480. sumCount = 0;
  3481. row1 = sheet.CreateRow(PaintIndex);
  3482. sheet.SetRowBreak(PaintIndex - 1);
  3483. sheet.Footer.Center = "第&P页,共&N页";
  3484. PaintIndex = PaintIndex + 1;
  3485. PageNum1 = 0;
  3486. }
  3487. //每次到了页数开始分页
  3488. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  3489. {
  3490. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  3491. //第一行添加客户信息
  3492. //if (i != rowNum - 1)
  3493. {
  3494. for (int j = 0; j < columnNum - 3; j++)
  3495. {
  3496. if (j == 0)
  3497. {
  3498. row1.CreateCell(j);
  3499. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  3500. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  3501. }
  3502. else if (j == ShowDataIndex)
  3503. {
  3504. row1.CreateCell(j);
  3505. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  3506. }
  3507. else
  3508. {
  3509. row1.CreateCell(j);
  3510. }
  3511. row1.GetCell(j).CellStyle = style;
  3512. }
  3513. row1 = sheet.CreateRow(PaintIndex);
  3514. PaintIndex = PaintIndex + 1;
  3515. //第二行添加型号
  3516. for (int j = 0; j < columnNum - 3; j++)
  3517. {
  3518. if (j == 0)
  3519. {
  3520. row1.CreateCell(j);
  3521. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  3522. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  3523. }
  3524. else if (j == ShowSizeIndex)
  3525. {
  3526. row1.CreateCell(j);
  3527. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  3528. }
  3529. else if (j == ShowDataIndex)
  3530. {
  3531. row1.CreateCell(j);
  3532. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  3533. }
  3534. else
  3535. {
  3536. row1.CreateCell(j);
  3537. }
  3538. }
  3539. //添加列名
  3540. row1 = sheet.CreateRow(PaintIndex);
  3541. PaintIndex = PaintIndex + 1;
  3542. int showcount = 0;
  3543. for (int j = 4; j < columnNum; j++)
  3544. {
  3545. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  3546. {
  3547. showcount = showcount + 1;
  3548. row1.CreateCell(j - 4);
  3549. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3550. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  3551. }
  3552. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  3553. {
  3554. showcount = showcount + 1;
  3555. row1.CreateCell(j - 4);
  3556. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3557. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  3558. }
  3559. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  3560. {
  3561. showcount = showcount + 1;
  3562. row1.CreateCell(j - 4);
  3563. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3564. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  3565. }
  3566. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3567. {
  3568. }
  3569. else
  3570. {
  3571. showcount = showcount + 1;
  3572. row1.CreateCell(j - 4);
  3573. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3574. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  3575. }
  3576. if (DataTable.Columns[j].ColumnName.ToString() == "ch_pbcode")
  3577. {
  3578. ShowBoxIndex = j;
  3579. }
  3580. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  3581. {
  3582. NumIndex = j;
  3583. if (ShowCountIndex == NumIndex - 4)
  3584. {
  3585. ShowCountIndex = ShowCountIndex + 1;
  3586. }
  3587. }
  3588. }
  3589. ShowColumnCount = showcount;
  3590. row1 = sheet.CreateRow(PaintIndex);
  3591. PaintIndex = PaintIndex + 1;
  3592. }
  3593. }
  3594. //添加数据内容
  3595. for (int j = 4; j < columnNum; j++)
  3596. {
  3597. string Data = DataTable.Rows[i][j].ToString();
  3598. row1.CreateCell(j - 4);
  3599. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3600. {
  3601. }
  3602. else
  3603. {
  3604. row1.Cells[j - 4].SetCellValue(Data);
  3605. row1.GetCell(j - 4).CellStyle = styleborder;
  3606. }
  3607. if (DataTable.Columns[j].ColumnName == "io_qty")
  3608. {
  3609. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3610. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  3611. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  3612. }
  3613. if (DataTable.Columns[j].ColumnName == "rownum")
  3614. {
  3615. row1.Cells[j - 4].SetCellValue(i + 1);
  3616. }
  3617. if (DataTable.Columns[j].ColumnName == "ch_code")
  3618. {
  3619. sheet.AutoSizeColumn(j - 4);
  3620. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  3621. }
  3622. }
  3623. if (i == rowNum - 1)
  3624. {
  3625. PageNum1 = PageNum1 + 1;
  3626. row1 = sheet.CreateRow(PaintIndex);
  3627. PaintIndex = PaintIndex + 1;
  3628. for (int j = 0; j < ShowColumnCount; j++)
  3629. {
  3630. row1.CreateCell(j);
  3631. if (j == 0)
  3632. {
  3633. row1.Cells[j].SetCellValue(批小计);
  3634. row1.Cells[j].CellStyle = styleborder;
  3635. }
  3636. else if (j == ShowPieceIndex)
  3637. {
  3638. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3639. row1.Cells[j].CellStyle = styleborder;
  3640. }
  3641. else if (j == ShowCountIndex)
  3642. {
  3643. row1.Cells[j].SetCellValue(sumCount);
  3644. row1.Cells[j].CellStyle = styleborder;
  3645. }
  3646. else if (j == ShowBoxIndex)
  3647. {
  3648. row1.Cells[j].SetCellValue(DataTable.Rows[i]["ch_pbcode"].ToString());
  3649. row1.Cells[j].CellStyle = styleborder;
  3650. }
  3651. else
  3652. {
  3653. row1.Cells[j].CellStyle = styleborder;
  3654. }
  3655. }
  3656. row1 = sheet.CreateRow(PaintIndex);
  3657. PaintIndex = PaintIndex + 1;
  3658. for (int j = 0; j < ShowColumnCount; j++)
  3659. {
  3660. row1.CreateCell(j);
  3661. if (j == 0)
  3662. {
  3663. row1.Cells[j].SetCellValue(小计);
  3664. row1.Cells[j].CellStyle = styleborder;
  3665. }
  3666. else if (j == ShowPieceIndex)
  3667. {
  3668. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3669. row1.Cells[j].CellStyle = styleborder;
  3670. }
  3671. else if (j == ShowCountIndex)
  3672. {
  3673. row1.Cells[j].SetCellValue(sumCount);
  3674. row1.Cells[j].CellStyle = styleborder;
  3675. }
  3676. else if (j == ShowBoxIndex)
  3677. {
  3678. row1.Cells[j].SetCellValue(DataTable.Rows[i]["ch_pbcode"].ToString());
  3679. row1.Cells[j].CellStyle = styleborder;
  3680. }
  3681. else
  3682. {
  3683. row1.Cells[j].CellStyle = styleborder;
  3684. }
  3685. }
  3686. row1 = sheet.CreateRow(PaintIndex);
  3687. for (int j = 0; j < columnNum - 3; j++)
  3688. {
  3689. if (j == 0)
  3690. {
  3691. row1.CreateCell(j);
  3692. row1.Cells[j].SetCellValue("备注");
  3693. }
  3694. else if (j == ShowCountIndex)
  3695. {
  3696. row1.CreateCell(j);
  3697. row1.Cells[j].SetCellValue(totalCount);
  3698. }
  3699. else if (j == ShowRemarkPiece)
  3700. {
  3701. row1.CreateCell(j);
  3702. row1.Cells[j].SetCellValue(rowNum + 片);
  3703. }
  3704. else
  3705. {
  3706. row1.CreateCell(j);
  3707. }
  3708. row1.Cells[j].CellStyle = style;
  3709. }
  3710. sheet.SetRowBreak(PaintIndex);
  3711. sheet.Footer.Center = "第&P页,共&N页";
  3712. PaintIndex = PaintIndex + 1;
  3713. PageNum1 = 0;
  3714. }
  3715. PageNum1 = PageNum1 + 1;
  3716. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3717. pib_outboxcode1.Add(BoxCode.ToString());
  3718. }
  3719. //for (int i = 0; i < sheet.LastRowNum; i++)
  3720. //{
  3721. // if (i != 0)
  3722. // {
  3723. // sheet.AutoSizeColumn(i);
  3724. // sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  3725. // }
  3726. //}
  3727. break;
  3728. default:
  3729. break;
  3730. }
  3731. 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());
  3732. //删除下载链接再重新插入
  3733. HttpHandler.GenDownLoadLinK(Inoutno);
  3734. //填充首页
  3735. sumCount = 0;
  3736. totalCount = 0;
  3737. PaintIndex = 1;
  3738. ISheet sheet2 = book.CreateSheet("首页");
  3739. row = sheet2.CreateRow(0);
  3740. row.CreateCell(0);
  3741. row.Cells[0].SetCellValue(" " + companyname);
  3742. row.GetCell(0).CellStyle = style;
  3743. rowNum = FirstDT.Rows.Count;
  3744. //不需要显示的列移除
  3745. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  3746. {
  3747. for (int j = 0; j < box.Length; j++)
  3748. {
  3749. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  3750. {
  3751. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  3752. {
  3753. FirstDT.Columns.RemoveAt(i);
  3754. }
  3755. }
  3756. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  3757. {
  3758. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  3759. {
  3760. FirstDT.Columns.RemoveAt(i);
  3761. }
  3762. }
  3763. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  3764. {
  3765. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  3766. {
  3767. FirstDT.Columns.RemoveAt(i);
  3768. }
  3769. }
  3770. }
  3771. }
  3772. columnNum = FirstDT.Columns.Count;
  3773. for (int i = 0; i < rowNum; i++)
  3774. {
  3775. IRow row1 = sheet2.CreateRow(PaintIndex);
  3776. PaintIndex = PaintIndex + 1;
  3777. row1.HeightInPoints = RowHeight;
  3778. //只需要绘制一行
  3779. if (i == 0)
  3780. {
  3781. for (int j = 0; j < columnNum - 3; j++)
  3782. {
  3783. if (j == 0)
  3784. {
  3785. row1.CreateCell(j);
  3786. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString());
  3787. }
  3788. else if (j > 5 && j == columnNum - 5)
  3789. {
  3790. row1.CreateCell(j);
  3791. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  3792. }
  3793. else if (columnNum > 5 && j == columnNum - 5)
  3794. {
  3795. row1.CreateCell(j);
  3796. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  3797. }
  3798. else
  3799. {
  3800. row1.CreateCell(j);
  3801. }
  3802. row1.GetCell(j).CellStyle = style;
  3803. }
  3804. row1 = sheet2.CreateRow(PaintIndex);
  3805. PaintIndex = PaintIndex + 1;
  3806. //第二行添加型号
  3807. for (int j = 0; j < columnNum - 3; j++)
  3808. {
  3809. if (j == 0)
  3810. {
  3811. row1.CreateCell(j);
  3812. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString());
  3813. }
  3814. else if (j > 5 && j == columnNum - 5)
  3815. {
  3816. row1.CreateCell(j);
  3817. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  3818. }
  3819. else if (columnNum > 5 && j == columnNum - 5)
  3820. {
  3821. row1.CreateCell(j);
  3822. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  3823. }
  3824. else
  3825. {
  3826. row1.CreateCell(j);
  3827. }
  3828. row1.GetCell(j).CellStyle = style;
  3829. }
  3830. row1 = sheet2.CreateRow(PaintIndex);
  3831. PaintIndex = PaintIndex + 1;
  3832. //添加列名
  3833. for (int j = 4; j < columnNum; j++)
  3834. {
  3835. row1.CreateCell(j - 4);
  3836. row1.Cells[j - 4].CellStyle = styleborder;
  3837. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  3838. }
  3839. row1 = sheet2.CreateRow(PaintIndex);
  3840. PaintIndex = PaintIndex + 1;
  3841. }
  3842. //添加数据内容
  3843. for (int j = 4; j < columnNum; j++)
  3844. {
  3845. string Data = FirstDT.Rows[i][j].ToString();
  3846. row1.CreateCell(j - 4);
  3847. row1.Cells[j - 4].SetCellValue(Data);
  3848. row1.GetCell(j - 4).CellStyle = styleborder;
  3849. if (FirstDT.Columns[j].ColumnName == "num")
  3850. {
  3851. sumCount += int.Parse(Data);
  3852. }
  3853. if (FirstDT.Columns[j].ColumnName == "io_qty")
  3854. {
  3855. totalCount += int.Parse(Data);
  3856. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3857. }
  3858. }
  3859. //添加总计行
  3860. if (i == rowNum - 1)
  3861. {
  3862. row1 = sheet2.CreateRow(PaintIndex);
  3863. PaintIndex = PaintIndex + 1;
  3864. for (int j = 0; j < columnNum - 4; j++)
  3865. {
  3866. if (j == 0)
  3867. {
  3868. row1.CreateCell(j);
  3869. row1.Cells[j].CellStyle = styleborder;
  3870. row1.Cells[j].SetCellValue(总计);
  3871. }
  3872. else if (j == columnNum - 6)
  3873. {
  3874. row1.CreateCell(j);
  3875. row1.Cells[j].CellStyle = styleborder;
  3876. row1.Cells[j].SetCellValue(sumCount);
  3877. }
  3878. else if (j == columnNum - 5)
  3879. {
  3880. row1.CreateCell(j);
  3881. row1.Cells[j].CellStyle = styleborder;
  3882. row1.Cells[j].SetCellValue(totalCount);
  3883. }
  3884. else
  3885. {
  3886. row1.CreateCell(j);
  3887. row1.Cells[j].CellStyle = styleborder;
  3888. }
  3889. }
  3890. }
  3891. }
  3892. for (int i = 0; i < sheet2.LastRowNum; i++)
  3893. {
  3894. if (i != 0)
  3895. {
  3896. sheet2.AutoSizeColumn(i);
  3897. sheet2.SetColumnWidth(i, sheet2.GetColumnWidth(i) + 1000);
  3898. }
  3899. }
  3900. //将book的内容写入内存流中返回
  3901. book.Write(ms);
  3902. return ms;
  3903. }
  3904. }
  3905. }