ExcelHandler.cs 225 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318
  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["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  536. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  537. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  538. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  539. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  540. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  541. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  542. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  543. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  544. dr["pd_ordercode"] = First_OrderCode;
  545. dr["pr_orispeccode"] = First_Prspec;
  546. dr["ch_splitbatch"] = First_Batch;
  547. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  548. dr["num"] = PageSize;
  549. dr["io_qty"] = sumCount;
  550. FirstDT.Rows.Add(dr);
  551. First_OrderCode = "";
  552. First_Prspec = "";
  553. First_Batch = "";
  554. First_WID.Clear();
  555. BoxCode = BoxCode + 1;
  556. for (int j = 0; j < ShowColumnCount; j++)
  557. {
  558. row1.CreateCell(j);
  559. if (j == 0)
  560. {
  561. row1.Cells[j].SetCellValue(小计);
  562. }
  563. else if (j == ShowPieceIndex)
  564. {
  565. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i));
  566. row1.Cells[j].CellStyle = styleborder;
  567. }
  568. else if (j == ShowCountIndex)
  569. {
  570. row1.Cells[j].SetCellValue(sumCount);
  571. }
  572. row1.Cells[j].CellStyle = styleborder;
  573. }
  574. sumCount = 0;
  575. row1 = sheet.CreateRow(PaintIndex);
  576. sheet.SetRowBreak(PaintIndex - 1);
  577. sheet.Footer.Center = "第&P页,共&N页";
  578. PaintIndex = PaintIndex + 1;
  579. }
  580. //每次到了页数开始分页
  581. if (i % PageSize == 0 || i == rowNum - 1)
  582. {
  583. //第一行添加客户信息 rownum只有一行的情
  584. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  585. {
  586. for (int j = 0; j < columnNum - 3; j++)
  587. {
  588. if (j == 0)
  589. {
  590. row1.CreateCell(j);
  591. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  592. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  593. }
  594. else if (j == ShowDataIndex)
  595. {
  596. row1.CreateCell(j);
  597. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  598. }
  599. else
  600. {
  601. row1.CreateCell(j);
  602. }
  603. row1.GetCell(j).CellStyle = style;
  604. }
  605. row1 = sheet.CreateRow(PaintIndex);
  606. PaintIndex = PaintIndex + 1;
  607. //第二行添加型号
  608. for (int j = 0; j < columnNum - 3; j++)
  609. {
  610. if (j == 0)
  611. {
  612. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  613. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ")" + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  614. }
  615. else if (j == ShowSizeIndex)
  616. {
  617. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  618. }
  619. else if (j == ShowDataIndex)
  620. {
  621. row1.CreateCell(j).SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  622. }
  623. }
  624. //添加列名
  625. row1 = sheet.CreateRow(PaintIndex);
  626. PaintIndex = PaintIndex + 1;
  627. //计数列所在的索引
  628. int showcount = 0;
  629. for (int j = 4; j < columnNum; j++)
  630. {
  631. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  632. {
  633. showcount = showcount + 1;
  634. row1.CreateCell(j - 4);
  635. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  636. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  637. }
  638. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  639. {
  640. showcount = showcount + 1;
  641. row1.CreateCell(j - 4);
  642. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  643. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  644. }
  645. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  646. {
  647. showcount = showcount + 1;
  648. row1.CreateCell(j - 4);
  649. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  650. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  651. }
  652. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  653. {
  654. }
  655. else
  656. {
  657. showcount = showcount + 1;
  658. row1.CreateCell(j - 4);
  659. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  660. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  661. }
  662. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  663. {
  664. NumIndex = j;
  665. if (ShowCountIndex == NumIndex - 4)
  666. {
  667. ShowCountIndex = ShowCountIndex + 1;
  668. }
  669. }
  670. }
  671. ShowColumnCount = showcount;
  672. row1 = sheet.CreateRow(PaintIndex);
  673. PaintIndex = PaintIndex + 1;
  674. }
  675. }
  676. //添加数据内容
  677. for (int j = 4; j < columnNum; j++)
  678. {
  679. string Data = DataTable.Rows[i][j].ToString();
  680. row1.CreateCell(j - 4);
  681. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  682. {
  683. }
  684. else
  685. {
  686. double Num = 0;
  687. if (double.TryParse(Data, out Num))
  688. {
  689. row1.Cells[j - 4].SetCellValue(Num);
  690. }
  691. else
  692. {
  693. row1.Cells[j - 4].SetCellValue(Data);
  694. }
  695. row1.Cells[j - 4].CellStyle = styleborder;
  696. }
  697. if (DataTable.Columns[j].ColumnName == "io_qty")
  698. {
  699. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  700. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  701. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  702. }
  703. if (DataTable.Columns[j].ColumnName == "rownum")
  704. {
  705. row1.Cells[j - 4].SetCellValue(i + 1);
  706. }
  707. if (DataTable.Columns[j].ColumnName == "ch_code")
  708. {
  709. sheet.AutoSizeColumn(j - 4);
  710. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  711. }
  712. }
  713. //固定行号分组的时候自动拼接新的DataTable
  714. if (i == rowNum - 1)
  715. {
  716. DataRow dr = FirstDT.NewRow();
  717. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  718. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  719. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  720. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  721. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  722. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  723. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  724. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  725. dr["pd_ordercode"] = First_OrderCode;
  726. dr["pr_orispeccode"] = First_Prspec;
  727. dr["ch_splitbatch"] = First_Batch;
  728. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  729. dr["num"] = (i % PageSize) + 1;
  730. dr["io_qty"] = sumCount;
  731. FirstDT.Rows.Add(dr);
  732. row1 = sheet.CreateRow(PaintIndex);
  733. PaintIndex = PaintIndex + 1;
  734. for (int j = 0; j < ShowColumnCount; j++)
  735. {
  736. row1.CreateCell(j);
  737. if (j == 0)
  738. {
  739. row1.Cells[j].SetCellValue(小计);
  740. }
  741. else if (j == ShowPieceIndex)
  742. {
  743. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize == 0 ? PageSize : (rowNum % PageSize)));
  744. row1.Cells[j].CellStyle = styleborder;
  745. }
  746. else if (j == ShowCountIndex)
  747. {
  748. row1.Cells[j].SetCellValue(sumCount);
  749. }
  750. row1.Cells[j].CellStyle = styleborder;
  751. }
  752. row1 = sheet.CreateRow(PaintIndex);
  753. for (int j = 0; j < columnNum - 3; j++)
  754. {
  755. if (j == 0)
  756. {
  757. row1.CreateCell(j);
  758. row1.Cells[j].SetCellValue("备注");
  759. }
  760. else if (j == ShowCountIndex)
  761. {
  762. row1.CreateCell(j);
  763. row1.Cells[j].SetCellValue(totalCount);
  764. }
  765. else if (j == ShowRemarkPiece)
  766. {
  767. row1.CreateCell(j);
  768. row1.Cells[j].SetCellValue(rowNum + "片");
  769. }
  770. else
  771. {
  772. row1.CreateCell(j);
  773. }
  774. row1.Cells[j].CellStyle = style;
  775. }
  776. sheet.SetRowBreak(PaintIndex);
  777. sheet.Footer.Center = "第&P页,共&N页";
  778. PaintIndex = PaintIndex + 1;
  779. }
  780. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  781. pib_outboxcode1.Add(BoxCode.ToString());
  782. }
  783. break;
  784. case "BatchCode":
  785. string LastBatchCode = "";
  786. int PageNum = 0;
  787. for (int i = 0; i < rowNum; i++)
  788. {
  789. IRow row1 = sheet.CreateRow(PaintIndex);
  790. PaintIndex = PaintIndex + 1;
  791. row1.HeightInPoints = RowHeight;
  792. //如果批号不相等的时候
  793. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  794. {
  795. BoxCode = BoxCode + 1;
  796. for (int j = 0; j < ShowColumnCount; j++)
  797. {
  798. row1.CreateCell(j);
  799. if (j == 0)
  800. {
  801. row1.Cells[j].SetCellValue(小计);
  802. row1.Cells[j].CellStyle = styleborder;
  803. }
  804. else if (j == ShowPieceIndex)
  805. {
  806. row1.Cells[ShowPieceIndex].SetCellValue(PageNum - 1);
  807. row1.Cells[j].CellStyle = styleborder;
  808. }
  809. else if (j == ShowCountIndex)
  810. {
  811. row1.Cells[j].SetCellValue(sumCount);
  812. row1.Cells[j].CellStyle = styleborder;
  813. }
  814. else
  815. {
  816. row1.Cells[j].CellStyle = styleborder;
  817. }
  818. }
  819. sumCount = 0;
  820. row1 = sheet.CreateRow(PaintIndex);
  821. sheet.SetRowBreak(PaintIndex - 1);
  822. sheet.Footer.Center = "第&P页,共&N页";
  823. PaintIndex = PaintIndex + 1;
  824. PageNum = 0;
  825. }
  826. //每次到了页数开始分页
  827. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()) || i == rowNum - 1)
  828. {
  829. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  830. //第一行添加客户信息
  831. //if (i != rowNum - 1)
  832. {
  833. for (int j = 0; j < columnNum - 3; j++)
  834. {
  835. if (j == 0)
  836. {
  837. row1.CreateCell(j);
  838. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  839. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  840. }
  841. else if (j == ShowDataIndex)
  842. {
  843. row1.CreateCell(j);
  844. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  845. }
  846. else
  847. {
  848. row1.CreateCell(j);
  849. }
  850. row1.GetCell(j).CellStyle = style;
  851. }
  852. row1 = sheet.CreateRow(PaintIndex);
  853. PaintIndex = PaintIndex + 1;
  854. //第二行添加型号
  855. for (int j = 0; j < columnNum - 3; j++)
  856. {
  857. if (j == 0)
  858. {
  859. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  860. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ")" + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  861. }
  862. else if (j == ShowSizeIndex)
  863. {
  864. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  865. }
  866. else if (j == ShowDataIndex)
  867. {
  868. row1.CreateCell(j).SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  869. }
  870. }
  871. //添加列名
  872. row1 = sheet.CreateRow(PaintIndex);
  873. PaintIndex = PaintIndex + 1;
  874. int showcount = 0;
  875. for (int j = 4; j < columnNum; j++)
  876. {
  877. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  878. {
  879. showcount = showcount + 1;
  880. row1.CreateCell(j - 4);
  881. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  882. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  883. }
  884. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  885. {
  886. showcount = showcount + 1;
  887. row1.CreateCell(j - 4);
  888. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  889. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  890. }
  891. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  892. {
  893. showcount = showcount + 1;
  894. row1.CreateCell(j - 4);
  895. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  896. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  897. }
  898. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  899. {
  900. }
  901. else
  902. {
  903. showcount = showcount + 1;
  904. row1.CreateCell(j - 4);
  905. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  906. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  907. }
  908. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  909. {
  910. NumIndex = j;
  911. if (ShowCountIndex == NumIndex - 4)
  912. {
  913. ShowCountIndex = ShowCountIndex + 1;
  914. }
  915. }
  916. }
  917. ShowColumnCount = showcount;
  918. row1 = sheet.CreateRow(PaintIndex);
  919. PaintIndex = PaintIndex + 1;
  920. }
  921. }
  922. //添加数据内容
  923. for (int j = 4; j < columnNum; j++)
  924. {
  925. string Data = DataTable.Rows[i][j].ToString();
  926. row1.CreateCell(j - 4);
  927. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  928. {
  929. }
  930. else
  931. {
  932. double Num = 0;
  933. if (double.TryParse(Data, out Num))
  934. {
  935. row1.Cells[j - 4].SetCellValue(Num);
  936. }
  937. else
  938. {
  939. row1.Cells[j - 4].SetCellValue(Data);
  940. }
  941. row1.Cells[j - 4].CellStyle = styleborder;
  942. }
  943. if (DataTable.Columns[j].ColumnName == "io_qty")
  944. {
  945. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  946. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  947. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  948. }
  949. if (DataTable.Columns[j].ColumnName == "rownum")
  950. {
  951. row1.Cells[j - 4].SetCellValue(i + 1);
  952. }
  953. if (DataTable.Columns[j].ColumnName == "ch_code")
  954. {
  955. sheet.AutoSizeColumn(j - 4);
  956. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  957. }
  958. }
  959. if (i == rowNum - 1)
  960. {
  961. row1 = sheet.CreateRow(PaintIndex);
  962. PaintIndex = PaintIndex + 1;
  963. for (int j = 0; j < ShowColumnCount; j++)
  964. {
  965. row1.CreateCell(j);
  966. if (j == 0)
  967. {
  968. row1.Cells[j].SetCellValue(小计);
  969. row1.Cells[j].CellStyle = styleborder;
  970. }
  971. else if (j == ShowPieceIndex)
  972. {
  973. row1.Cells[ShowPieceIndex].SetCellValue(PageNum);
  974. row1.Cells[j].CellStyle = styleborder;
  975. }
  976. else if (j == ShowCountIndex)
  977. {
  978. row1.Cells[j].SetCellValue(sumCount);
  979. row1.Cells[j].CellStyle = styleborder;
  980. }
  981. else
  982. {
  983. row1.Cells[j].CellStyle = styleborder;
  984. }
  985. }
  986. //创建备注内容
  987. row1 = sheet.CreateRow(PaintIndex);
  988. for (int j = 0; j < columnNum - 3; j++)
  989. {
  990. if (j == 0)
  991. {
  992. row1.CreateCell(j);
  993. row1.Cells[j].SetCellValue("备注");
  994. }
  995. else if (j == ShowCountIndex)
  996. {
  997. row1.CreateCell(j);
  998. row1.Cells[j].SetCellValue(totalCount);
  999. }
  1000. else if (j == ShowRemarkPiece)
  1001. {
  1002. row1.CreateCell(j);
  1003. row1.Cells[j].SetCellValue(rowNum + "片");
  1004. }
  1005. else if (j == 4)
  1006. {
  1007. row1.CreateCell(j);
  1008. row1.Cells[j].SetCellValue(片);
  1009. }
  1010. else
  1011. {
  1012. row1.CreateCell(j);
  1013. }
  1014. row1.Cells[j].CellStyle = style;
  1015. }
  1016. sheet.SetRowBreak(PaintIndex);
  1017. sheet.Footer.Center = "第&P页,共&N页";
  1018. PaintIndex = PaintIndex + 1;
  1019. PageNum = 0;
  1020. }
  1021. PageNum = PageNum + 1;
  1022. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  1023. pib_outboxcode1.Add(BoxCode.ToString());
  1024. }
  1025. //for (int i = 0; i < sheet.LastRowNum; i++)
  1026. //{
  1027. // if (i != 0)
  1028. // {
  1029. // sheet.AutoSizeColumn(i);
  1030. // sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  1031. // }
  1032. //}
  1033. break;
  1034. case "BoxCode":
  1035. string LastBoxCode = "";
  1036. int PageNum1 = 0;
  1037. for (int i = 0; i < rowNum; i++)
  1038. {
  1039. IRow row1 = sheet.CreateRow(PaintIndex);
  1040. PaintIndex = PaintIndex + 1;
  1041. row1.HeightInPoints = RowHeight;
  1042. //如果批号不相等的时候
  1043. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  1044. {
  1045. BoxCode = BoxCode + 1;
  1046. for (int j = 0; j < ShowColumnCount; j++)
  1047. {
  1048. row1.CreateCell(j);
  1049. if (j == 0)
  1050. {
  1051. row1.Cells[j].SetCellValue(小计);
  1052. row1.Cells[j].CellStyle = styleborder;
  1053. }
  1054. else if (j == ShowPieceIndex)
  1055. {
  1056. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  1057. row1.Cells[j].CellStyle = styleborder;
  1058. }
  1059. else if (j == ShowCountIndex)
  1060. {
  1061. row1.Cells[j].SetCellValue(sumCount);
  1062. row1.Cells[j].CellStyle = styleborder;
  1063. }
  1064. else
  1065. {
  1066. row1.Cells[j].CellStyle = styleborder;
  1067. }
  1068. }
  1069. sumCount = 0;
  1070. row1 = sheet.CreateRow(PaintIndex);
  1071. sheet.SetRowBreak(PaintIndex - 1);
  1072. sheet.Footer.Center = "第&P页,共&N页";
  1073. PaintIndex = PaintIndex + 1;
  1074. PageNum1 = 0;
  1075. }
  1076. //每次到了页数开始分页
  1077. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  1078. {
  1079. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  1080. //第一行添加客户信息
  1081. //if (i != rowNum - 1)
  1082. {
  1083. for (int j = 0; j < columnNum - 3; j++)
  1084. {
  1085. if (j == 0)
  1086. {
  1087. row1.CreateCell(j);
  1088. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  1089. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  1090. }
  1091. else if (j == ShowDataIndex)
  1092. {
  1093. row1.CreateCell(j);
  1094. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  1095. }
  1096. else
  1097. {
  1098. row1.CreateCell(j);
  1099. }
  1100. row1.GetCell(j).CellStyle = style;
  1101. }
  1102. row1 = sheet.CreateRow(PaintIndex);
  1103. PaintIndex = PaintIndex + 1;
  1104. //第二行添加型号
  1105. for (int j = 0; j < columnNum - 3; j++)
  1106. {
  1107. if (j == 0)
  1108. {
  1109. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  1110. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ")" + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  1111. }
  1112. else if (j == ShowSizeIndex)
  1113. {
  1114. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  1115. }
  1116. else if (j == ShowDataIndex)
  1117. {
  1118. row1.CreateCell(j).SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  1119. }
  1120. }
  1121. //添加列名
  1122. row1 = sheet.CreateRow(PaintIndex);
  1123. PaintIndex = PaintIndex + 1;
  1124. int showcount = 0;
  1125. for (int j = 4; j < columnNum; j++)
  1126. {
  1127. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  1128. {
  1129. showcount = showcount + 1;
  1130. row1.CreateCell(j - 4);
  1131. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1132. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  1133. }
  1134. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  1135. {
  1136. showcount = showcount + 1;
  1137. row1.CreateCell(j - 4);
  1138. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1139. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  1140. }
  1141. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  1142. {
  1143. showcount = showcount + 1;
  1144. row1.CreateCell(j - 4);
  1145. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1146. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  1147. }
  1148. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1149. {
  1150. }
  1151. else
  1152. {
  1153. showcount = showcount + 1;
  1154. row1.CreateCell(j - 4);
  1155. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1156. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  1157. }
  1158. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  1159. {
  1160. NumIndex = j;
  1161. if (ShowCountIndex == NumIndex - 4)
  1162. {
  1163. ShowCountIndex = ShowCountIndex + 1;
  1164. }
  1165. }
  1166. }
  1167. ShowColumnCount = showcount;
  1168. row1 = sheet.CreateRow(PaintIndex);
  1169. PaintIndex = PaintIndex + 1;
  1170. }
  1171. }
  1172. //添加数据内容
  1173. for (int j = 4; j < columnNum; j++)
  1174. {
  1175. string Data = DataTable.Rows[i][j].ToString();
  1176. row1.CreateCell(j - 4);
  1177. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1178. {
  1179. }
  1180. else
  1181. {
  1182. double Num = 0;
  1183. if (double.TryParse(Data, out Num))
  1184. {
  1185. row1.Cells[j - 4].SetCellValue(Num);
  1186. }
  1187. else
  1188. {
  1189. row1.Cells[j - 4].SetCellValue(Data);
  1190. }
  1191. row1.Cells[j - 4].CellStyle = styleborder;
  1192. }
  1193. if (DataTable.Columns[j].ColumnName == "io_qty")
  1194. {
  1195. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  1196. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  1197. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  1198. }
  1199. if (DataTable.Columns[j].ColumnName == "rownum")
  1200. {
  1201. row1.Cells[j - 4].SetCellValue(i + 1);
  1202. }
  1203. if (DataTable.Columns[j].ColumnName == "ch_code")
  1204. {
  1205. sheet.AutoSizeColumn(j - 4);
  1206. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  1207. }
  1208. }
  1209. if (i == rowNum - 1)
  1210. {
  1211. PageNum1 = PageNum1 + 1;
  1212. row1 = sheet.CreateRow(PaintIndex);
  1213. PaintIndex = PaintIndex + 1;
  1214. for (int j = 0; j < ShowColumnCount; j++)
  1215. {
  1216. row1.CreateCell(j);
  1217. if (j == 0)
  1218. {
  1219. row1.Cells[j].SetCellValue(小计);
  1220. row1.Cells[j].CellStyle = styleborder;
  1221. }
  1222. else if (j == ShowPieceIndex)
  1223. {
  1224. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  1225. row1.Cells[j].CellStyle = styleborder;
  1226. }
  1227. else if (j == ShowCountIndex)
  1228. {
  1229. row1.Cells[j].SetCellValue(sumCount);
  1230. row1.Cells[j].CellStyle = styleborder;
  1231. }
  1232. else
  1233. {
  1234. row1.Cells[j].CellStyle = styleborder;
  1235. }
  1236. }
  1237. row1 = sheet.CreateRow(PaintIndex);
  1238. for (int j = 0; j < columnNum - 3; j++)
  1239. {
  1240. if (j == 0)
  1241. {
  1242. row1.CreateCell(j);
  1243. row1.Cells[j].SetCellValue("备注");
  1244. }
  1245. else if (j == ShowCountIndex)
  1246. {
  1247. row1.CreateCell(j);
  1248. row1.Cells[j].SetCellValue(totalCount);
  1249. }
  1250. else if (j == ShowRemarkPiece)
  1251. {
  1252. row1.CreateCell(j);
  1253. row1.Cells[j].SetCellValue(rowNum + "片");
  1254. }
  1255. else
  1256. {
  1257. row1.CreateCell(j);
  1258. }
  1259. row1.Cells[j].CellStyle = style;
  1260. }
  1261. sheet.SetRowBreak(PaintIndex);
  1262. sheet.Footer.Center = "第&P页,共&N页";
  1263. PaintIndex = PaintIndex + 1;
  1264. PageNum1 = 0;
  1265. }
  1266. PageNum1 = PageNum1 + 1;
  1267. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  1268. pib_outboxcode1.Add(BoxCode.ToString());
  1269. }
  1270. //for (int i = 0; i < sheet.LastRowNum; i++)
  1271. //{
  1272. // if (i != 0)
  1273. // {
  1274. // sheet.AutoSizeColumn(i);
  1275. // sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  1276. // }
  1277. //}
  1278. break;
  1279. default:
  1280. break;
  1281. }
  1282. 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());
  1283. //删除下载链接再重新插入
  1284. HttpHandler.GenDownLoadLinK(Inoutno);
  1285. //填充首页
  1286. sumCount = 0;
  1287. totalCount = 0;
  1288. PaintIndex = 1;
  1289. ISheet sheet2 = book.CreateSheet("首页");
  1290. row = sheet2.CreateRow(0);
  1291. row.CreateCell(0);
  1292. row.Cells[0].SetCellValue(" " + companyname);
  1293. row.GetCell(0).CellStyle = style;
  1294. rowNum = FirstDT.Rows.Count;
  1295. //不需要显示的列移除
  1296. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  1297. {
  1298. for (int j = 0; j < box.Length; j++)
  1299. {
  1300. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  1301. {
  1302. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  1303. {
  1304. FirstDT.Columns.RemoveAt(i);
  1305. }
  1306. }
  1307. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  1308. {
  1309. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  1310. {
  1311. FirstDT.Columns.RemoveAt(i);
  1312. }
  1313. }
  1314. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  1315. {
  1316. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  1317. {
  1318. FirstDT.Columns.RemoveAt(i);
  1319. }
  1320. }
  1321. if (box[j].Name == "FirstPage_BOXCODE" && !box[j].Checked)
  1322. {
  1323. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  1324. {
  1325. FirstDT.Columns.RemoveAt(i);
  1326. }
  1327. }
  1328. }
  1329. }
  1330. columnNum = FirstDT.Columns.Count;
  1331. for (int i = 0; i < rowNum; i++)
  1332. {
  1333. IRow row1 = sheet2.CreateRow(PaintIndex);
  1334. PaintIndex = PaintIndex + 1;
  1335. row1.HeightInPoints = RowHeight;
  1336. //只需要绘制一行
  1337. if (i == 0)
  1338. {
  1339. for (int j = 0; j < columnNum - 3; j++)
  1340. {
  1341. if (j == 0)
  1342. {
  1343. row1.CreateCell(j);
  1344. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString() + " "
  1345. + FirstDT.Columns["ch_level"].Caption + ":" + FirstDT.Rows[i]["ch_level"].ToString());
  1346. }
  1347. else if (j > 5 && j == columnNum - 5)
  1348. {
  1349. row1.CreateCell(j);
  1350. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  1351. }
  1352. else if (columnNum > 5 && j == columnNum - 5)
  1353. {
  1354. row1.CreateCell(j);
  1355. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  1356. }
  1357. else
  1358. {
  1359. row1.CreateCell(j);
  1360. }
  1361. row1.GetCell(j).CellStyle = style;
  1362. }
  1363. row1 = sheet2.CreateRow(PaintIndex);
  1364. PaintIndex = PaintIndex + 1;
  1365. //第二行添加型号
  1366. for (int j = 0; j < columnNum - 3; j++)
  1367. {
  1368. if (j == 0)
  1369. {
  1370. row1.CreateCell(j).SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString() + " "
  1371. + "(" + FirstDT.Rows[i]["me_desc"].ToString() + ")" + FirstDT.Columns["pi_chipouttype"].Caption + ":" + FirstDT.Rows[i]["pi_chipouttype"].ToString());
  1372. }
  1373. else if (j == ShowSizeIndex)
  1374. {
  1375. row1.CreateCell(j);
  1376. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_size"].Caption + ":" + FirstDT.Rows[i]["pr_size"].ToString());
  1377. }
  1378. else if (j > 5 && j == columnNum - 5)
  1379. {
  1380. row1.CreateCell(j);
  1381. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  1382. }
  1383. else if (columnNum > 5 && j == columnNum - 5)
  1384. {
  1385. row1.CreateCell(j);
  1386. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  1387. }
  1388. else
  1389. {
  1390. row1.CreateCell(j);
  1391. }
  1392. row1.GetCell(j).CellStyle = style;
  1393. }
  1394. row1 = sheet2.CreateRow(PaintIndex);
  1395. PaintIndex = PaintIndex + 1;
  1396. //添加列名
  1397. for (int j = 4; j < columnNum; j++)
  1398. {
  1399. row1.CreateCell(j - 4);
  1400. if (NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  1401. {
  1402. }
  1403. else
  1404. {
  1405. row1.Cells[j - 4].CellStyle = styleborder;
  1406. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  1407. }
  1408. }
  1409. row1 = sheet2.CreateRow(PaintIndex);
  1410. PaintIndex = PaintIndex + 1;
  1411. }
  1412. //添加数据内容
  1413. ShowColumnCount = 0;
  1414. for (int j = 4; j < columnNum; j++)
  1415. {
  1416. row1.CreateCell(j - 4);
  1417. if (!NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  1418. {
  1419. string Data = FirstDT.Rows[i][j].ToString();
  1420. row1.Cells[j - 4].SetCellValue(Data);
  1421. row1.GetCell(j - 4).CellStyle = styleborder;
  1422. if (FirstDT.Columns[j].ColumnName == "num")
  1423. {
  1424. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  1425. sumCount += int.Parse(Data);
  1426. }
  1427. if (FirstDT.Columns[j].ColumnName == "io_qty")
  1428. {
  1429. totalCount += int.Parse(Data);
  1430. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  1431. }
  1432. ShowColumnCount = ShowColumnCount + 1;
  1433. }
  1434. else
  1435. {
  1436. }
  1437. }
  1438. //添加总计行
  1439. if (i == rowNum - 1)
  1440. {
  1441. row1 = sheet2.CreateRow(PaintIndex);
  1442. PaintIndex = PaintIndex + 1;
  1443. for (int j = 0; j < ShowColumnCount; j++)
  1444. {
  1445. if (j == 0)
  1446. {
  1447. row1.CreateCell(j);
  1448. row1.Cells[j].CellStyle = styleborder;
  1449. row1.Cells[j].SetCellValue(总计);
  1450. }
  1451. else if (j == ShowColumnCount - 2)
  1452. {
  1453. row1.CreateCell(j);
  1454. row1.Cells[j].CellStyle = styleborder;
  1455. row1.Cells[j].SetCellValue(sumCount);
  1456. }
  1457. else if (j == ShowColumnCount - 1)
  1458. {
  1459. row1.CreateCell(j);
  1460. row1.Cells[j].CellStyle = styleborder;
  1461. row1.Cells[j].SetCellValue(totalCount);
  1462. }
  1463. else
  1464. {
  1465. row1.CreateCell(j);
  1466. row1.Cells[j].CellStyle = styleborder;
  1467. }
  1468. }
  1469. }
  1470. }
  1471. for (int i = 0; i < sheet2.LastRowNum; i++)
  1472. {
  1473. if (i != 0)
  1474. {
  1475. sheet2.AutoSizeColumn(i);
  1476. sheet2.SetColumnWidth(i, sheet2.GetColumnWidth(i) + 1000);
  1477. }
  1478. }
  1479. //将book的内容写入内存流中返回
  1480. book.Write(ms);
  1481. return ms;
  1482. }
  1483. /// <summary>
  1484. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  1485. /// </summary>
  1486. /// <param name="DataTable"></param>
  1487. /// <returns></returns>
  1488. private MemoryStream DataTableToExcel_JINYUAN(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  1489. {
  1490. string 小计 = "";
  1491. string 总计 = "";
  1492. string 片 = "";
  1493. string companyname = "";
  1494. //晶源的需要显示在数量列下面
  1495. int ShowCountIndex = 2;
  1496. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype", "pi_inoutno='" + Inoutno + "'").ToString() == "Chinese")
  1497. {
  1498. 小计 = "小计";
  1499. 总计 = "总计";
  1500. 片 = "片";
  1501. companyname = "深爱半导体股份有限公司芯片出货清单";
  1502. }
  1503. else
  1504. {
  1505. 小计 = "total";
  1506. 总计 = "total";
  1507. 片 = "slice";
  1508. companyname = "SHENZHEN SI SEMICONDUCTORS CO.,LTD";
  1509. }
  1510. //转换为序列
  1511. CheckBox[] box = conditionbox.ToArray();
  1512. //创建内存流
  1513. MemoryStream ms = new MemoryStream();
  1514. //创建一个Book,相当于一个Excel文件
  1515. HSSFWorkbook book = new HSSFWorkbook();
  1516. //Excel中的Sheet
  1517. ISheet sheet = book.CreateSheet("分页");
  1518. sheet.SetMargin(MarginType.TopMargin, 0.4);
  1519. sheet.SetMargin(MarginType.BottomMargin, 0.1);
  1520. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  1521. sheet.SetMargin(MarginType.RightMargin, 0.4);
  1522. sheet.PrintSetup.NoColor = true;
  1523. sheet.PrintSetup.Landscape = true;
  1524. //芯片号需要作为更新盒号的条件
  1525. HSSFFont ffont = (HSSFFont)book.CreateFont();
  1526. ffont.FontName = "宋体";
  1527. //更新箱号
  1528. List<string> pib_id = new List<string>();
  1529. //系统打印箱号
  1530. List<string> pib_outboxcode1 = new List<string>();
  1531. int BoxCode = 1;
  1532. ICellStyle style = book.CreateCellStyle();
  1533. style.VerticalAlignment = VerticalAlignment.Center;
  1534. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  1535. style.SetFont(ffont);
  1536. ICellStyle styleborder = book.CreateCellStyle();
  1537. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1538. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1539. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1540. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1541. styleborder.VerticalAlignment = VerticalAlignment.Center;
  1542. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  1543. styleborder.SetFont(ffont);
  1544. string pi_inoutno = "";
  1545. List<string> NotShowColumn = new List<string>();
  1546. NotShowColumn.Add("ch_level");
  1547. NotShowColumn.Add("pib_id");
  1548. NotShowColumn.Add("chw_itemname1");
  1549. NotShowColumn.Add("chw_itemname2");
  1550. NotShowColumn.Add("chw_itemname3");
  1551. NotShowColumn.Add("pd_ordercode");
  1552. NotShowColumn.Add("pr_size");
  1553. NotShowColumn.Add("me_desc");
  1554. NotShowColumn.Add("pr_orispeccode");
  1555. NotShowColumn.Add("pr_orispeccode1");
  1556. NotShowColumn.Add("pi_title");
  1557. NotShowColumn.Add("pi_date");
  1558. NotShowColumn.Add("pi_chipouttype");
  1559. //设置列的宽度,根据首行的列的内容的长度来设置
  1560. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  1561. {
  1562. for (int j = 0; j < box.Length; j++)
  1563. {
  1564. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  1565. {
  1566. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  1567. {
  1568. DataTable.Columns.RemoveAt(i);
  1569. break;
  1570. }
  1571. }
  1572. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  1573. {
  1574. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  1575. {
  1576. DataTable.Columns.RemoveAt(i);
  1577. break;
  1578. }
  1579. }
  1580. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  1581. {
  1582. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  1583. {
  1584. DataTable.Columns.RemoveAt(i);
  1585. break;
  1586. }
  1587. }
  1588. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  1589. {
  1590. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  1591. {
  1592. DataTable.Columns.RemoveAt(i);
  1593. break;
  1594. }
  1595. }
  1596. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  1597. {
  1598. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  1599. {
  1600. DataTable.Columns.RemoveAt(i);
  1601. break;
  1602. }
  1603. }
  1604. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  1605. {
  1606. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  1607. {
  1608. DataTable.Columns.RemoveAt(i);
  1609. break;
  1610. }
  1611. }
  1612. if (box[j].Name.ToLower() == "ch_yield" && !box[j].Checked)
  1613. {
  1614. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_yield"))
  1615. {
  1616. DataTable.Columns.RemoveAt(i);
  1617. break;
  1618. }
  1619. }
  1620. }
  1621. }
  1622. //获取行数量和列数量
  1623. int rowNum = DataTable.Rows.Count;
  1624. int columnNum = DataTable.Columns.Count;
  1625. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  1626. //ffont.FontHeight = 10;
  1627. //开始绘制的Index
  1628. int PaintIndex = 0;
  1629. int sumCount = 0;
  1630. int totalCount = 0;
  1631. //Title的字体
  1632. HSSFFont titlefont = (HSSFFont)book.CreateFont();
  1633. titlefont.FontName = "宋体";
  1634. titlefont.FontHeight = 270;
  1635. titlefont.Boldweight = (short)FontBoldWeight.Bold;
  1636. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  1637. ColumnTitle.FontName = "宋体";
  1638. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  1639. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  1640. ColumnTitleStyle.SetFont(ColumnTitle);
  1641. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1642. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1643. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1644. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1645. ICellStyle TitleStyle = book.CreateCellStyle();
  1646. TitleStyle.SetFont(titlefont);
  1647. int ShowColumnCount = 0;
  1648. IRow row1 = null;
  1649. switch (Type)
  1650. {
  1651. case "FixRow":
  1652. //清理系统取出来的数据
  1653. BaseUtil.CleanDataTableData(FirstDT);
  1654. //首页参数拼接
  1655. string First_OrderCode = "";
  1656. string First_Prspec = "";
  1657. string First_Batch = "";
  1658. ArrayList<string> First_WID = new ArrayList<string>();
  1659. for (int i = 0; i < rowNum; i++)
  1660. {
  1661. if (PaintIndex != 0)
  1662. {
  1663. row1 = sheet.CreateRow(PaintIndex);
  1664. PaintIndex = PaintIndex + 1;
  1665. row1.HeightInPoints = RowHeight;
  1666. }
  1667. //不包含的订单号
  1668. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  1669. {
  1670. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  1671. }
  1672. //不包含的物料型号
  1673. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  1674. {
  1675. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  1676. }
  1677. //不包含扩撒批号
  1678. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  1679. {
  1680. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  1681. }
  1682. //不包含Wafer_id
  1683. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  1684. {
  1685. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  1686. }
  1687. if (i / PageSize >= 1 && i % PageSize == 0)
  1688. {
  1689. DataRow dr = FirstDT.NewRow();
  1690. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  1691. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  1692. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  1693. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  1694. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  1695. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  1696. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  1697. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  1698. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  1699. dr["pd_ordercode"] = First_OrderCode;
  1700. dr["pr_orispeccode"] = First_Prspec;
  1701. dr["ch_splitbatch"] = First_Batch;
  1702. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  1703. dr["num"] = PageSize;
  1704. dr["io_qty"] = sumCount;
  1705. FirstDT.Rows.Add(dr);
  1706. First_OrderCode = "";
  1707. First_Prspec = "";
  1708. First_Batch = "";
  1709. First_WID.Clear();
  1710. BoxCode = BoxCode + 1;
  1711. for (int j = 0; j < ShowColumnCount; j++)
  1712. {
  1713. row1.CreateCell(j);
  1714. if (j == 0)
  1715. {
  1716. row1.Cells[j].SetCellValue(小计);
  1717. }
  1718. else if (j == ShowPieceIndex)
  1719. {
  1720. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i));
  1721. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1722. }
  1723. else if (j == ShowCountIndex)
  1724. {
  1725. row1.Cells[j].SetCellValue(sumCount);
  1726. }
  1727. row1.Cells[j].CellStyle = styleborder;
  1728. }
  1729. sumCount = 0;
  1730. row1 = sheet.CreateRow(PaintIndex);
  1731. sheet.SetRowBreak(PaintIndex - 1);
  1732. sheet.Footer.Center = "第&P页,共&N页";
  1733. }
  1734. //每次到了页数开始分页
  1735. if (i % PageSize == 0 || i == rowNum - 1)
  1736. {
  1737. //第一行添加客户信息 rownum只有一行的情
  1738. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  1739. {
  1740. //抬头设置
  1741. row1 = sheet.CreateRow(PaintIndex);
  1742. PaintIndex = PaintIndex + 1;
  1743. row1.CreateCell(0).SetCellValue(" " + companyname);
  1744. row1.GetCell(0).CellStyle = TitleStyle;
  1745. row1 = sheet.CreateRow(PaintIndex);
  1746. PaintIndex = PaintIndex + 1;
  1747. for (int j = 0; j < columnNum - 3; j++)
  1748. {
  1749. if (j == 0)
  1750. {
  1751. row1.CreateCell(j);
  1752. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  1753. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  1754. }
  1755. else if (j == ShowDataIndex)
  1756. {
  1757. row1.CreateCell(j);
  1758. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  1759. }
  1760. else
  1761. {
  1762. row1.CreateCell(j);
  1763. }
  1764. row1.GetCell(j).CellStyle = style;
  1765. }
  1766. row1 = sheet.CreateRow(PaintIndex);
  1767. PaintIndex = PaintIndex + 1;
  1768. //第二行添加型号
  1769. for (int j = 0; j < columnNum - 3; j++)
  1770. {
  1771. if (j == 0)
  1772. {
  1773. row1.CreateCell(j);
  1774. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  1775. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  1776. }
  1777. else if (j == ShowSizeIndex)
  1778. {
  1779. row1.CreateCell(j);
  1780. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  1781. }
  1782. else if (j == ShowDataIndex)
  1783. {
  1784. row1.CreateCell(j);
  1785. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  1786. }
  1787. else
  1788. {
  1789. row1.CreateCell(j);
  1790. }
  1791. row1.GetCell(j).CellStyle = style;
  1792. }
  1793. //特殊客户添加一列空行
  1794. row1 = sheet.CreateRow(PaintIndex);
  1795. PaintIndex = PaintIndex + 1;
  1796. for (int j = 0; j < columnNum; j++)
  1797. {
  1798. row1.CreateCell(j).SetCellValue("");
  1799. }
  1800. //添加列名
  1801. row1 = sheet.CreateRow(PaintIndex);
  1802. PaintIndex = PaintIndex + 1;
  1803. //计数列所在的索引
  1804. int showcount = 0;
  1805. //前面有4列标题内容,数据库设置的,需要从4开始索引
  1806. for (int j = 4; j < columnNum; j++)
  1807. {
  1808. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  1809. {
  1810. showcount = showcount + 1;
  1811. row1.CreateCell(j - 4);
  1812. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1813. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  1814. }
  1815. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  1816. {
  1817. showcount = showcount + 1;
  1818. row1.CreateCell(j - 4);
  1819. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1820. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  1821. }
  1822. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  1823. {
  1824. showcount = showcount + 1;
  1825. row1.CreateCell(j - 4);
  1826. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1827. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  1828. }
  1829. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1830. {
  1831. }
  1832. else
  1833. {
  1834. showcount = showcount + 1;
  1835. row1.CreateCell(j - 4);
  1836. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1837. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  1838. }
  1839. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  1840. {
  1841. NumIndex = j - 4;
  1842. }
  1843. }
  1844. ShowColumnCount = showcount;
  1845. row1 = sheet.CreateRow(PaintIndex);
  1846. PaintIndex = PaintIndex + 1;
  1847. }
  1848. }
  1849. //添加数据内容
  1850. for (int j = 4; j < columnNum; j++)
  1851. {
  1852. string Data = DataTable.Rows[i][j].ToString();
  1853. row1.CreateCell(j - 4);
  1854. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1855. {
  1856. }
  1857. else
  1858. {
  1859. double Num = 0;
  1860. if (double.TryParse(Data, out Num))
  1861. {
  1862. row1.Cells[j - 4].SetCellValue(Num);
  1863. }
  1864. else
  1865. {
  1866. row1.Cells[j - 4].SetCellValue(Data);
  1867. }
  1868. row1.Cells[j - 4].CellStyle = styleborder;
  1869. }
  1870. if (DataTable.Columns[j].ColumnName == "io_qty")
  1871. {
  1872. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  1873. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  1874. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  1875. }
  1876. if (DataTable.Columns[j].ColumnName == "rownum")
  1877. {
  1878. row1.Cells[j - 4].SetCellValue(i + 1);
  1879. }
  1880. if (DataTable.Columns[j].ColumnName == "ch_code")
  1881. {
  1882. sheet.AutoSizeColumn(j - 4);
  1883. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  1884. }
  1885. }
  1886. //固定行号分组的时候自动拼接新的DataTable
  1887. if (i == rowNum - 1)
  1888. {
  1889. DataRow dr = FirstDT.NewRow();
  1890. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  1891. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  1892. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  1893. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  1894. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  1895. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  1896. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  1897. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  1898. dr["pd_ordercode"] = First_OrderCode;
  1899. dr["pr_orispeccode"] = First_Prspec;
  1900. dr["ch_splitbatch"] = First_Batch;
  1901. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  1902. dr["num"] = (i % PageSize) + 1;
  1903. dr["io_qty"] = sumCount;
  1904. FirstDT.Rows.Add(dr);
  1905. row1 = sheet.CreateRow(PaintIndex);
  1906. PaintIndex = PaintIndex + 1;
  1907. for (int j = 0; j < ShowColumnCount; j++)
  1908. {
  1909. row1.CreateCell(j);
  1910. if (j == 0)
  1911. {
  1912. row1.Cells[j].SetCellValue(小计);
  1913. }
  1914. else if (j == ShowPieceIndex)
  1915. {
  1916. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize == 0 ? PageSize : (rowNum % PageSize)) + 片);
  1917. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1918. }
  1919. else if (j == ShowCountIndex)
  1920. {
  1921. row1.Cells[j].SetCellValue(sumCount);
  1922. }
  1923. row1.Cells[j].CellStyle = styleborder;
  1924. }
  1925. row1 = sheet.CreateRow(PaintIndex);
  1926. for (int j = 0; j < columnNum - 3; j++)
  1927. {
  1928. if (j == 0)
  1929. {
  1930. row1.CreateCell(j);
  1931. row1.Cells[j].SetCellValue("备注");
  1932. }
  1933. else if (j == ShowCountIndex)
  1934. {
  1935. row1.CreateCell(j);
  1936. row1.Cells[j].SetCellValue(totalCount);
  1937. }
  1938. else if (j == ShowRemarkPiece)
  1939. {
  1940. row1.CreateCell(j);
  1941. row1.Cells[j].SetCellValue(rowNum + 片);
  1942. }
  1943. else
  1944. {
  1945. row1.CreateCell(j);
  1946. }
  1947. row1.Cells[j].CellStyle = style;
  1948. }
  1949. sheet.SetRowBreak(PaintIndex);
  1950. sheet.Footer.Center = "第&P页,共&N页";
  1951. }
  1952. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  1953. pib_outboxcode1.Add(BoxCode.ToString());
  1954. }
  1955. break;
  1956. case "BatchCode":
  1957. string LastBatchCode = "";
  1958. int PageNum = 0;
  1959. for (int i = 0; i < rowNum; i++)
  1960. {
  1961. row1 = sheet.CreateRow(PaintIndex);
  1962. if (i != 0)
  1963. PaintIndex = PaintIndex + 1;
  1964. row1.HeightInPoints = RowHeight;
  1965. //如果批号不相等的时候
  1966. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  1967. {
  1968. BoxCode = BoxCode + 1;
  1969. for (int j = 0; j < ShowColumnCount; j++)
  1970. {
  1971. row1.CreateCell(j);
  1972. if (j == 0)
  1973. {
  1974. row1.Cells[j].SetCellValue(小计);
  1975. row1.Cells[j].CellStyle = styleborder;
  1976. }
  1977. else if (j == ShowPieceIndex)
  1978. {
  1979. row1.Cells[ShowPieceIndex].SetCellValue(PageNum);
  1980. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1981. }
  1982. else if (j == ShowCountIndex)
  1983. {
  1984. row1.Cells[j].SetCellValue(sumCount);
  1985. row1.Cells[j].CellStyle = styleborder;
  1986. }
  1987. else
  1988. {
  1989. row1.Cells[j].CellStyle = styleborder;
  1990. }
  1991. }
  1992. sumCount = 0;
  1993. //row1 = sheet.CreateRow(PaintIndex);
  1994. sheet.SetRowBreak(PaintIndex - 1);
  1995. sheet.Footer.Center = "第&P页,共&N页";
  1996. PageNum = 0;
  1997. }
  1998. //每次到了页数开始分页
  1999. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()))
  2000. {
  2001. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  2002. //第一行添加客户信息
  2003. row1 = sheet.CreateRow(PaintIndex);
  2004. PaintIndex = PaintIndex + 1;
  2005. row1.CreateCell(0).SetCellValue(" " + companyname);
  2006. row1.GetCell(0).CellStyle = TitleStyle;
  2007. row1 = sheet.CreateRow(PaintIndex);
  2008. PaintIndex = PaintIndex + 1;
  2009. //if (i != rowNum - 1)
  2010. {
  2011. for (int j = 0; j < columnNum - 3; j++)
  2012. {
  2013. if (j == 0)
  2014. {
  2015. row1.CreateCell(j);
  2016. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  2017. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  2018. }
  2019. else if (j == ShowDataIndex)
  2020. {
  2021. row1.CreateCell(j);
  2022. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  2023. }
  2024. else
  2025. {
  2026. row1.CreateCell(j);
  2027. }
  2028. row1.GetCell(j).CellStyle = style;
  2029. }
  2030. row1 = sheet.CreateRow(PaintIndex);
  2031. PaintIndex = PaintIndex + 1;
  2032. //第二行添加型号
  2033. for (int j = 0; j < columnNum - 3; j++)
  2034. {
  2035. if (j == 0)
  2036. {
  2037. row1.CreateCell(j);
  2038. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  2039. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2040. }
  2041. else if (j == ShowSizeIndex)
  2042. {
  2043. row1.CreateCell(j);
  2044. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  2045. }
  2046. else if (j == ShowDataIndex)
  2047. {
  2048. row1.CreateCell(j);
  2049. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  2050. }
  2051. else
  2052. {
  2053. row1.CreateCell(j);
  2054. }
  2055. row1.GetCell(j).CellStyle = style;
  2056. }
  2057. //特殊客户添加一列空行
  2058. row1 = sheet.CreateRow(PaintIndex);
  2059. PaintIndex = PaintIndex + 1;
  2060. for (int j = 0; j < columnNum; j++)
  2061. {
  2062. row1.CreateCell(j).SetCellValue("");
  2063. }
  2064. //添加列名
  2065. row1 = sheet.CreateRow(PaintIndex);
  2066. PaintIndex = PaintIndex + 1;
  2067. int showcount = 0;
  2068. for (int j = 4; j < columnNum; j++)
  2069. {
  2070. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  2071. {
  2072. showcount = showcount + 1;
  2073. row1.CreateCell(j - 4);
  2074. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2075. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  2076. }
  2077. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2078. {
  2079. showcount = showcount + 1;
  2080. row1.CreateCell(j - 4);
  2081. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2082. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  2083. }
  2084. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  2085. {
  2086. showcount = showcount + 1;
  2087. row1.CreateCell(j - 4);
  2088. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2089. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  2090. }
  2091. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2092. {
  2093. }
  2094. else
  2095. {
  2096. showcount = showcount + 1;
  2097. row1.CreateCell(j - 4);
  2098. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2099. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  2100. }
  2101. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  2102. {
  2103. NumIndex = j - 4;
  2104. }
  2105. }
  2106. ShowColumnCount = showcount;
  2107. row1 = sheet.CreateRow(PaintIndex);
  2108. PaintIndex = PaintIndex + 1;
  2109. }
  2110. }
  2111. //添加数据内容
  2112. for (int j = 4; j < columnNum; j++)
  2113. {
  2114. string Data = DataTable.Rows[i][j].ToString();
  2115. row1.CreateCell(j - 4);
  2116. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2117. {
  2118. }
  2119. else
  2120. {
  2121. double Num = 0;
  2122. if (double.TryParse(Data, out Num))
  2123. {
  2124. row1.Cells[j - 4].SetCellValue(Num);
  2125. }
  2126. else
  2127. {
  2128. row1.Cells[j - 4].SetCellValue(Data);
  2129. }
  2130. row1.Cells[j - 4].CellStyle = styleborder;
  2131. }
  2132. if (DataTable.Columns[j].ColumnName == "io_qty")
  2133. {
  2134. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2135. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  2136. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  2137. }
  2138. if (DataTable.Columns[j].ColumnName == "rownum")
  2139. {
  2140. row1.Cells[j - 4].SetCellValue(i + 1);
  2141. }
  2142. if (DataTable.Columns[j].ColumnName == "ch_code")
  2143. {
  2144. sheet.AutoSizeColumn(j - 4);
  2145. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  2146. }
  2147. }
  2148. if (i == rowNum - 1)
  2149. {
  2150. row1 = sheet.CreateRow(PaintIndex);
  2151. PaintIndex = PaintIndex + 1;
  2152. for (int j = 0; j < ShowColumnCount; j++)
  2153. {
  2154. row1.CreateCell(j);
  2155. if (j == 0)
  2156. {
  2157. row1.Cells[j].SetCellValue(小计);
  2158. row1.Cells[j].CellStyle = styleborder;
  2159. }
  2160. else if (j == ShowPieceIndex)
  2161. {
  2162. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  2163. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2164. }
  2165. else if (j == ShowCountIndex)
  2166. {
  2167. row1.Cells[j].SetCellValue(sumCount);
  2168. row1.Cells[j].CellStyle = styleborder;
  2169. }
  2170. else
  2171. {
  2172. row1.Cells[j].CellStyle = styleborder;
  2173. }
  2174. }
  2175. //创建备注内容
  2176. row1 = sheet.CreateRow(PaintIndex);
  2177. for (int j = 0; j < columnNum - 3; j++)
  2178. {
  2179. if (j == 0)
  2180. {
  2181. row1.CreateCell(j);
  2182. row1.Cells[j].SetCellValue("备注");
  2183. }
  2184. else if (j == ShowCountIndex)
  2185. {
  2186. row1.CreateCell(j);
  2187. row1.Cells[j].SetCellValue(totalCount);
  2188. }
  2189. else if (j == ShowRemarkPiece)
  2190. {
  2191. row1.CreateCell(j);
  2192. row1.Cells[j].SetCellValue(rowNum + 片);
  2193. }
  2194. else
  2195. {
  2196. row1.CreateCell(j);
  2197. }
  2198. row1.Cells[j].CellStyle = style;
  2199. }
  2200. sheet.SetRowBreak(PaintIndex);
  2201. sheet.Footer.Center = "第&P页,共&N页";
  2202. PageNum = 0;
  2203. }
  2204. PageNum = PageNum + 1;
  2205. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  2206. pib_outboxcode1.Add(BoxCode.ToString());
  2207. }
  2208. break;
  2209. case "BoxCode":
  2210. string LastBoxCode = "";
  2211. int PageNum1 = 0;
  2212. for (int i = 0; i < rowNum; i++)
  2213. {
  2214. row1 = sheet.CreateRow(PaintIndex);
  2215. if (i != 0)
  2216. PaintIndex = PaintIndex + 1;
  2217. row1.HeightInPoints = RowHeight;
  2218. //如果箱号不相等的时候
  2219. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  2220. {
  2221. BoxCode = BoxCode + 1;
  2222. for (int j = 0; j < ShowColumnCount; j++)
  2223. {
  2224. row1.CreateCell(j);
  2225. if (j == 0)
  2226. {
  2227. row1.Cells[j].SetCellValue(小计);
  2228. row1.Cells[j].CellStyle = styleborder;
  2229. }
  2230. else if (j == ShowPieceIndex)
  2231. {
  2232. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  2233. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2234. }
  2235. else if (j == ShowCountIndex)
  2236. {
  2237. row1.Cells[j].SetCellValue(sumCount);
  2238. row1.Cells[j].CellStyle = styleborder;
  2239. }
  2240. else
  2241. {
  2242. row1.Cells[j].CellStyle = styleborder;
  2243. }
  2244. }
  2245. sumCount = 0;
  2246. //row1 = sheet.CreateRow(PaintIndex);
  2247. sheet.SetRowBreak(PaintIndex - 1);
  2248. sheet.Footer.Center = "第&P页,共&N页";
  2249. PageNum1 = 0;
  2250. }
  2251. //每次到了页数开始分页
  2252. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  2253. {
  2254. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  2255. row1 = sheet.CreateRow(PaintIndex);
  2256. PaintIndex = PaintIndex + 1;
  2257. row1.CreateCell(0).SetCellValue(" " + companyname);
  2258. row1.GetCell(0).CellStyle = TitleStyle;
  2259. row1 = sheet.CreateRow(PaintIndex);
  2260. PaintIndex = PaintIndex + 1;
  2261. //第一行添加客户信息
  2262. //if (i != rowNum - 1)
  2263. {
  2264. for (int j = 0; j < columnNum - 3; j++)
  2265. {
  2266. if (j == 0)
  2267. {
  2268. row1.CreateCell(j);
  2269. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  2270. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  2271. }
  2272. else if (j == ShowDataIndex)
  2273. {
  2274. row1.CreateCell(j);
  2275. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  2276. }
  2277. else
  2278. {
  2279. row1.CreateCell(j);
  2280. }
  2281. row1.GetCell(j).CellStyle = style;
  2282. }
  2283. row1 = sheet.CreateRow(PaintIndex);
  2284. PaintIndex = PaintIndex + 1;
  2285. //第二行添加型号
  2286. for (int j = 0; j < columnNum - 3; j++)
  2287. {
  2288. if (j == 0)
  2289. {
  2290. row1.CreateCell(j);
  2291. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  2292. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2293. }
  2294. else if (j == ShowSizeIndex)
  2295. {
  2296. row1.CreateCell(j);
  2297. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  2298. }
  2299. else if (j == ShowDataIndex)
  2300. {
  2301. row1.CreateCell(j);
  2302. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  2303. }
  2304. else
  2305. {
  2306. row1.CreateCell(j);
  2307. }
  2308. row1.GetCell(j).CellStyle = style;
  2309. }
  2310. //特殊客户添加一列空行
  2311. row1 = sheet.CreateRow(PaintIndex);
  2312. PaintIndex = PaintIndex + 1;
  2313. for (int j = 0; j < columnNum; j++)
  2314. {
  2315. row1.CreateCell(j).SetCellValue("");
  2316. }
  2317. //添加列名
  2318. row1 = sheet.CreateRow(PaintIndex);
  2319. PaintIndex = PaintIndex + 1;
  2320. int showcount = 0;
  2321. for (int j = 4; j < columnNum; j++)
  2322. {
  2323. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  2324. {
  2325. showcount = showcount + 1;
  2326. row1.CreateCell(j - 4);
  2327. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2328. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  2329. }
  2330. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2331. {
  2332. showcount = showcount + 1;
  2333. row1.CreateCell(j - 4);
  2334. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2335. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  2336. }
  2337. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  2338. {
  2339. showcount = showcount + 1;
  2340. row1.CreateCell(j - 4);
  2341. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2342. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  2343. }
  2344. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2345. {
  2346. }
  2347. else
  2348. {
  2349. showcount = showcount + 1;
  2350. row1.CreateCell(j - 4);
  2351. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2352. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  2353. }
  2354. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  2355. {
  2356. NumIndex = j - 4;
  2357. }
  2358. }
  2359. ShowColumnCount = showcount;
  2360. row1 = sheet.CreateRow(PaintIndex);
  2361. PaintIndex = PaintIndex + 1;
  2362. }
  2363. }
  2364. //添加数据内容
  2365. for (int j = 4; j < columnNum; j++)
  2366. {
  2367. string Data = DataTable.Rows[i][j].ToString();
  2368. row1.CreateCell(j - 4);
  2369. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2370. {
  2371. }
  2372. else
  2373. {
  2374. double Num = 0;
  2375. if (double.TryParse(Data, out Num))
  2376. {
  2377. row1.Cells[j - 4].SetCellValue(Num);
  2378. }
  2379. else
  2380. {
  2381. row1.Cells[j - 4].SetCellValue(Data);
  2382. }
  2383. row1.Cells[j - 4].CellStyle = styleborder;
  2384. }
  2385. if (DataTable.Columns[j].ColumnName == "io_qty")
  2386. {
  2387. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2388. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  2389. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  2390. }
  2391. if (DataTable.Columns[j].ColumnName == "rownum")
  2392. {
  2393. row1.Cells[j - 4].SetCellValue(i + 1);
  2394. }
  2395. if (DataTable.Columns[j].ColumnName == "ch_code")
  2396. {
  2397. sheet.AutoSizeColumn(j - 4);
  2398. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  2399. }
  2400. }
  2401. if (i == rowNum - 1)
  2402. {
  2403. PageNum1 = PageNum1 + 1;
  2404. row1 = sheet.CreateRow(PaintIndex);
  2405. PaintIndex = PaintIndex + 1;
  2406. for (int j = 0; j < ShowColumnCount; j++)
  2407. {
  2408. row1.CreateCell(j);
  2409. if (j == 0)
  2410. {
  2411. row1.Cells[j].SetCellValue(小计);
  2412. row1.Cells[j].CellStyle = styleborder;
  2413. }
  2414. else if (j == ShowPieceIndex)
  2415. {
  2416. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  2417. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2418. }
  2419. else if (j == ShowCountIndex)
  2420. {
  2421. row1.Cells[j].SetCellValue(sumCount);
  2422. row1.Cells[j].CellStyle = styleborder;
  2423. }
  2424. else
  2425. {
  2426. row1.Cells[j].CellStyle = styleborder;
  2427. }
  2428. }
  2429. row1 = sheet.CreateRow(PaintIndex);
  2430. for (int j = 0; j < columnNum - 3; j++)
  2431. {
  2432. if (j == 0)
  2433. {
  2434. row1.CreateCell(j);
  2435. row1.Cells[j].SetCellValue("备注");
  2436. }
  2437. else if (j == ShowCountIndex)
  2438. {
  2439. row1.CreateCell(j);
  2440. row1.Cells[j].SetCellValue(totalCount);
  2441. }
  2442. else if (j == ShowRemarkPiece)
  2443. {
  2444. row1.CreateCell(j);
  2445. row1.Cells[j].SetCellValue(rowNum + 片);
  2446. }
  2447. else
  2448. {
  2449. row1.CreateCell(j);
  2450. }
  2451. row1.Cells[j].CellStyle = style;
  2452. }
  2453. sheet.SetRowBreak(PaintIndex);
  2454. sheet.Footer.Center = "第&P页,共&N页";
  2455. PageNum1 = 0;
  2456. }
  2457. PageNum1 = PageNum1 + 1;
  2458. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  2459. pib_outboxcode1.Add(BoxCode.ToString());
  2460. }
  2461. break;
  2462. default:
  2463. break;
  2464. }
  2465. 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());
  2466. //删除下载链接再重新插入
  2467. HttpHandler.GenDownLoadLinK(Inoutno);
  2468. //填充首页
  2469. sumCount = 0;
  2470. totalCount = 0;
  2471. PaintIndex = 0;
  2472. ISheet sheet2 = book.CreateSheet("首页");
  2473. IRow row = sheet2.CreateRow(0);
  2474. row.CreateCell(0);
  2475. row.Cells[0].SetCellValue(" " + companyname);
  2476. row.GetCell(0).CellStyle = style;
  2477. rowNum = FirstDT.Rows.Count;
  2478. //不需要显示的列移除
  2479. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  2480. {
  2481. for (int j = 0; j < box.Length; j++)
  2482. {
  2483. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  2484. {
  2485. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  2486. {
  2487. FirstDT.Columns.RemoveAt(i);
  2488. }
  2489. }
  2490. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  2491. {
  2492. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  2493. {
  2494. FirstDT.Columns.RemoveAt(i);
  2495. }
  2496. }
  2497. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  2498. {
  2499. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  2500. {
  2501. FirstDT.Columns.RemoveAt(i);
  2502. }
  2503. }
  2504. if (box[j].Name == "FirstPage_BOXCODE" && !box[j].Checked)
  2505. {
  2506. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  2507. {
  2508. FirstDT.Columns.RemoveAt(i);
  2509. }
  2510. }
  2511. }
  2512. }
  2513. columnNum = FirstDT.Columns.Count;
  2514. for (int i = 0; i < rowNum; i++)
  2515. {
  2516. row1 = sheet2.CreateRow(PaintIndex);
  2517. PaintIndex = PaintIndex + 1;
  2518. row1.HeightInPoints = RowHeight;
  2519. //只需要绘制一行
  2520. if (i == 0)
  2521. {
  2522. for (int j = 0; j < columnNum - 3; j++)
  2523. {
  2524. if (j == 0)
  2525. {
  2526. row1.CreateCell(j);
  2527. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString() + " "
  2528. + FirstDT.Columns["ch_level"].Caption + ":" + FirstDT.Rows[i]["ch_level"].ToString());
  2529. }
  2530. else if (j > 5 && j == columnNum - 5)
  2531. {
  2532. row1.CreateCell(j);
  2533. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  2534. }
  2535. else if (columnNum > 5 && j == columnNum - 5)
  2536. {
  2537. row1.CreateCell(j);
  2538. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  2539. }
  2540. else
  2541. {
  2542. row1.CreateCell(j);
  2543. }
  2544. row1.GetCell(j).CellStyle = style;
  2545. }
  2546. row1 = sheet2.CreateRow(PaintIndex);
  2547. PaintIndex = PaintIndex + 1;
  2548. //第二行添加型号
  2549. for (int j = 0; j < columnNum - 3; j++)
  2550. {
  2551. if (j == 0)
  2552. {
  2553. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  2554. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ")" + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2555. }
  2556. else if (j == ShowSizeIndex)
  2557. {
  2558. row1.CreateCell(j);
  2559. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_size"].Caption + ":" + FirstDT.Rows[i]["pr_size"].ToString());
  2560. }
  2561. else if (j > 5 && j == columnNum - 5)
  2562. {
  2563. row1.CreateCell(j);
  2564. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  2565. }
  2566. else if (columnNum > 5 && j == columnNum - 5)
  2567. {
  2568. row1.CreateCell(j);
  2569. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  2570. }
  2571. else
  2572. {
  2573. row1.CreateCell(j);
  2574. }
  2575. row1.GetCell(j).CellStyle = style;
  2576. }
  2577. row1 = sheet2.CreateRow(PaintIndex);
  2578. PaintIndex = PaintIndex + 1;
  2579. //添加列名
  2580. for (int j = 4; j < columnNum; j++)
  2581. {
  2582. row1.CreateCell(j - 4);
  2583. if (NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  2584. {
  2585. }
  2586. else
  2587. {
  2588. row1.Cells[j - 4].CellStyle = styleborder;
  2589. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  2590. }
  2591. }
  2592. row1 = sheet2.CreateRow(PaintIndex);
  2593. PaintIndex = PaintIndex + 1;
  2594. }
  2595. //添加数据内容
  2596. ShowColumnCount = 0;
  2597. for (int j = 4; j < columnNum; j++)
  2598. {
  2599. row1.CreateCell(j - 4);
  2600. if (!NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  2601. {
  2602. string Data = FirstDT.Rows[i][j].ToString();
  2603. row1.Cells[j - 4].SetCellValue(Data);
  2604. row1.GetCell(j - 4).CellStyle = styleborder;
  2605. if (FirstDT.Columns[j].ColumnName == "num")
  2606. {
  2607. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2608. sumCount += int.Parse(Data);
  2609. }
  2610. if (FirstDT.Columns[j].ColumnName == "io_qty")
  2611. {
  2612. totalCount += int.Parse(Data);
  2613. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2614. }
  2615. ShowColumnCount = ShowColumnCount + 1;
  2616. }
  2617. else
  2618. {
  2619. }
  2620. }
  2621. //添加总计行
  2622. if (i == rowNum - 1)
  2623. {
  2624. row1 = sheet2.CreateRow(PaintIndex);
  2625. PaintIndex = PaintIndex + 1;
  2626. for (int j = 0; j < ShowColumnCount; j++)
  2627. {
  2628. if (j == 0)
  2629. {
  2630. row1.CreateCell(j);
  2631. row1.Cells[j].CellStyle = styleborder;
  2632. row1.Cells[j].SetCellValue(总计);
  2633. }
  2634. else if (j == ShowColumnCount - 2)
  2635. {
  2636. row1.CreateCell(j);
  2637. row1.Cells[j].CellStyle = styleborder;
  2638. row1.Cells[j].SetCellValue(sumCount);
  2639. }
  2640. else if (j == ShowColumnCount - 1)
  2641. {
  2642. row1.CreateCell(j);
  2643. row1.Cells[j].CellStyle = styleborder;
  2644. row1.Cells[j].SetCellValue(totalCount);
  2645. }
  2646. else
  2647. {
  2648. row1.CreateCell(j);
  2649. row1.Cells[j].CellStyle = styleborder;
  2650. }
  2651. }
  2652. }
  2653. }
  2654. for (int i = 0; i < sheet2.LastRowNum; i++)
  2655. {
  2656. if (i != 0)
  2657. {
  2658. sheet2.AutoSizeColumn(i);
  2659. sheet2.SetColumnWidth(i, sheet2.GetColumnWidth(i) + 1000);
  2660. }
  2661. }
  2662. //将book的内容写入内存流中返回
  2663. book.Write(ms);
  2664. return ms;
  2665. }
  2666. /// <summary>
  2667. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  2668. /// </summary>
  2669. /// <param name="DataTable"></param>
  2670. /// <returns></returns>
  2671. private MemoryStream DataTableToExcel_LIPUXIN(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  2672. {
  2673. string 小计 = "";
  2674. string 批小计 = "";
  2675. string 总计 = "";
  2676. string 片 = "";
  2677. string companyname = "";
  2678. int ShowBoxIndex = 0;
  2679. //用于小计的盒号
  2680. string LastBox = "";
  2681. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype", "pi_inoutno='" + Inoutno + "'").ToString() == "Chinese")
  2682. {
  2683. 小计 = "小计";
  2684. 总计 = "总计";
  2685. 批小计 = "批小计";
  2686. companyname = "深爱半导体股份有限公司芯片出货清单";
  2687. }
  2688. else
  2689. {
  2690. 批小计 = "BatchTotal";
  2691. 小计 = "total";
  2692. 总计 = "total";
  2693. companyname = "SHENZHEN SI SEMICONDUCTORS CO.,LTD";
  2694. }
  2695. //转换为序列
  2696. CheckBox[] box = conditionbox.ToArray();
  2697. //创建内存流
  2698. MemoryStream ms = new MemoryStream();
  2699. //创建一个Book,相当于一个Excel文件
  2700. HSSFWorkbook book = new HSSFWorkbook();
  2701. //Excel中的Sheet
  2702. ISheet sheet = book.CreateSheet("分页");
  2703. sheet.SetMargin(MarginType.TopMargin, 0.4);
  2704. sheet.SetMargin(MarginType.BottomMargin, 0.4);
  2705. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  2706. sheet.SetMargin(MarginType.RightMargin, 0.4);
  2707. sheet.FitToPage = true;
  2708. sheet.PrintSetup.FitHeight = 200;
  2709. //芯片号需要作为更新盒号的条件
  2710. HSSFFont ffont = (HSSFFont)book.CreateFont();
  2711. ffont.FontName = "宋体";
  2712. //更新箱号
  2713. List<string> pib_id = new List<string>();
  2714. //系统打印箱号
  2715. List<string> pib_outboxcode1 = new List<string>();
  2716. int BoxCode = 1;
  2717. ICellStyle style = book.CreateCellStyle();
  2718. style.VerticalAlignment = VerticalAlignment.Center;
  2719. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  2720. style.SetFont(ffont);
  2721. ICellStyle styleborder = book.CreateCellStyle();
  2722. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2723. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2724. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2725. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2726. styleborder.VerticalAlignment = VerticalAlignment.Center;
  2727. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  2728. styleborder.SetFont(ffont);
  2729. string pi_inoutno = "";
  2730. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  2731. ColumnTitle.FontName = "宋体";
  2732. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  2733. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  2734. ColumnTitleStyle.SetFont(ColumnTitle);
  2735. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2736. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2737. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2738. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2739. List<string> NotShowColumn = new List<string>();
  2740. NotShowColumn.Add("ch_level");
  2741. NotShowColumn.Add("pib_id");
  2742. NotShowColumn.Add("chw_itemname1");
  2743. NotShowColumn.Add("chw_itemname2");
  2744. NotShowColumn.Add("chw_itemname3");
  2745. NotShowColumn.Add("pd_ordercode");
  2746. NotShowColumn.Add("pr_size");
  2747. NotShowColumn.Add("me_desc");
  2748. NotShowColumn.Add("pr_orispeccode");
  2749. NotShowColumn.Add("pr_orispeccode1");
  2750. NotShowColumn.Add("pi_title");
  2751. NotShowColumn.Add("pi_chipouttype");
  2752. NotShowColumn.Add("pi_date");
  2753. int ShowColumnCount = 0;
  2754. //展示的内容列
  2755. //设置列的宽度,根据首行的列的内容的长度来设置
  2756. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  2757. {
  2758. for (int j = 0; j < box.Length; j++)
  2759. {
  2760. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  2761. {
  2762. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  2763. {
  2764. DataTable.Columns.RemoveAt(i);
  2765. break;
  2766. }
  2767. }
  2768. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  2769. {
  2770. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  2771. {
  2772. DataTable.Columns.RemoveAt(i);
  2773. break;
  2774. }
  2775. }
  2776. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  2777. {
  2778. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  2779. {
  2780. DataTable.Columns.RemoveAt(i);
  2781. break;
  2782. }
  2783. }
  2784. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  2785. {
  2786. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  2787. {
  2788. DataTable.Columns.RemoveAt(i);
  2789. break;
  2790. }
  2791. }
  2792. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  2793. {
  2794. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  2795. {
  2796. DataTable.Columns.RemoveAt(i);
  2797. break;
  2798. }
  2799. }
  2800. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  2801. {
  2802. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  2803. {
  2804. DataTable.Columns.RemoveAt(i);
  2805. break;
  2806. }
  2807. }
  2808. if (box[j].Name.ToLower() == "ch_yield" && !box[j].Checked)
  2809. {
  2810. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_yield"))
  2811. {
  2812. DataTable.Columns.RemoveAt(i);
  2813. break;
  2814. }
  2815. }
  2816. }
  2817. }
  2818. //获取行数量和列数量
  2819. int rowNum = DataTable.Rows.Count;
  2820. int columnNum = DataTable.Columns.Count;
  2821. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  2822. IRow row = sheet.CreateRow(0);
  2823. //冻结第一行
  2824. sheet.CreateFreezePane(0, 1, 0, 1);
  2825. row.HeightInPoints = RowHeight;
  2826. //固定第一行
  2827. //row.RowStyle.IsLocked=true;
  2828. //给第一行的标签赋值样式和值
  2829. // ffont.FontHeight = 13;
  2830. row.CreateCell(0);
  2831. row.Cells[0].SetCellValue(" " + companyname);
  2832. row.GetCell(0).CellStyle.SetFont((ffont));
  2833. //ffont.FontHeight = 10;
  2834. //开始绘制的Index
  2835. int PaintIndex = 1;
  2836. int sumCount = 0;
  2837. int totalCount = 0;
  2838. switch (Type)
  2839. {
  2840. case "FixRow":
  2841. //清理系统取出来的数据
  2842. BaseUtil.CleanDataTableData(FirstDT);
  2843. //首页参数拼接
  2844. string First_OrderCode = "";
  2845. string First_Prspec = "";
  2846. string First_Batch = "";
  2847. int NumIndex = 0;
  2848. ArrayList<string> First_WID = new ArrayList<string>();
  2849. for (int i = 0; i < rowNum; i++)
  2850. {
  2851. IRow row1 = sheet.CreateRow(PaintIndex);
  2852. PaintIndex = PaintIndex + 1;
  2853. row1.HeightInPoints = RowHeight;
  2854. //不包含的订单号
  2855. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  2856. {
  2857. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  2858. }
  2859. //不包含的物料型号
  2860. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  2861. {
  2862. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  2863. }
  2864. //不包含扩撒批号
  2865. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  2866. {
  2867. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  2868. }
  2869. //不包含Wafer_id
  2870. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  2871. {
  2872. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  2873. }
  2874. if (i / PageSize >= 1 && i % PageSize == 0)
  2875. {
  2876. DataRow dr = FirstDT.NewRow();
  2877. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  2878. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  2879. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  2880. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  2881. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  2882. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  2883. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  2884. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  2885. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  2886. dr["pd_ordercode"] = First_OrderCode;
  2887. dr["pr_orispeccode"] = First_Prspec;
  2888. dr["ch_splitbatch"] = First_Batch;
  2889. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  2890. dr["num"] = PageSize;
  2891. dr["io_qty"] = sumCount;
  2892. FirstDT.Rows.Add(dr);
  2893. First_OrderCode = "";
  2894. First_Prspec = "";
  2895. First_Batch = "";
  2896. First_WID.Clear();
  2897. BoxCode = BoxCode + 1;
  2898. for (int j = 0; j < ShowColumnCount; j++)
  2899. {
  2900. row1.CreateCell(j);
  2901. if (j == 0)
  2902. {
  2903. row1.Cells[j].SetCellValue(小计);
  2904. }
  2905. else if (j == ShowPieceIndex)
  2906. {
  2907. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i) + 片);
  2908. }
  2909. else if (j == ShowCountIndex)
  2910. {
  2911. row1.Cells[j].SetCellValue(sumCount);
  2912. }
  2913. else if (j == ShowBoxIndex - 4)
  2914. {
  2915. row1.Cells[j].SetCellValue(LastBox);
  2916. row1.Cells[j].CellStyle = styleborder;
  2917. }
  2918. row1.Cells[j].CellStyle = styleborder;
  2919. }
  2920. sumCount = 0;
  2921. row1 = sheet.CreateRow(PaintIndex);
  2922. sheet.SetRowBreak(PaintIndex - 1);
  2923. sheet.Footer.Center = "第&P页,共&N页";
  2924. PaintIndex = PaintIndex + 1;
  2925. }
  2926. //每次到了页数开始分页
  2927. if (i % PageSize == 0 || i == rowNum - 1)
  2928. {
  2929. //第一行添加客户信息 rownum只有一行的情
  2930. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  2931. {
  2932. for (int j = 0; j < columnNum - 3; j++)
  2933. {
  2934. if (j == 0)
  2935. {
  2936. row1.CreateCell(j);
  2937. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  2938. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  2939. }
  2940. else if (j == ShowDataIndex)
  2941. {
  2942. row1.CreateCell(j);
  2943. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  2944. }
  2945. else
  2946. {
  2947. row1.CreateCell(j);
  2948. }
  2949. row1.GetCell(j).CellStyle = style;
  2950. }
  2951. row1 = sheet.CreateRow(PaintIndex);
  2952. PaintIndex = PaintIndex + 1;
  2953. //第二行添加型号
  2954. for (int j = 0; j < columnNum - 3; j++)
  2955. {
  2956. if (j == 0)
  2957. {
  2958. row1.CreateCell(j);
  2959. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString()
  2960. + "_(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2961. }
  2962. else if (j == ShowSizeIndex)
  2963. {
  2964. row1.CreateCell(j);
  2965. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  2966. }
  2967. else if (j == ShowDataIndex)
  2968. {
  2969. row1.CreateCell(j);
  2970. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  2971. }
  2972. else
  2973. {
  2974. row1.CreateCell(j);
  2975. }
  2976. row1.GetCell(j).CellStyle = style;
  2977. }
  2978. //添加列名
  2979. row1 = sheet.CreateRow(PaintIndex);
  2980. PaintIndex = PaintIndex + 1;
  2981. //计数列所在的索引
  2982. int showcount = 0;
  2983. for (int j = 4; j < columnNum; j++)
  2984. {
  2985. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  2986. {
  2987. showcount = showcount + 1;
  2988. row1.CreateCell(j - 4);
  2989. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2990. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  2991. }
  2992. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2993. {
  2994. showcount = showcount + 1;
  2995. row1.CreateCell(j - 4);
  2996. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2997. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  2998. }
  2999. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  3000. {
  3001. showcount = showcount + 1;
  3002. row1.CreateCell(j - 4);
  3003. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3004. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  3005. }
  3006. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3007. {
  3008. }
  3009. else
  3010. {
  3011. showcount = showcount + 1;
  3012. row1.CreateCell(j - 4);
  3013. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3014. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  3015. }
  3016. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  3017. {
  3018. ShowBoxIndex = j;
  3019. }
  3020. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  3021. {
  3022. NumIndex = j;
  3023. if (ShowCountIndex == NumIndex - 4)
  3024. {
  3025. ShowCountIndex = ShowCountIndex + 1;
  3026. }
  3027. }
  3028. }
  3029. ShowColumnCount = showcount;
  3030. row1 = sheet.CreateRow(PaintIndex);
  3031. PaintIndex = PaintIndex + 1;
  3032. }
  3033. }
  3034. //添加数据内容
  3035. for (int j = 4; j < columnNum; j++)
  3036. {
  3037. string Data = DataTable.Rows[i][j].ToString();
  3038. row1.CreateCell(j - 4);
  3039. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3040. {
  3041. }
  3042. else
  3043. {
  3044. double Num = 0;
  3045. if (double.TryParse(Data, out Num))
  3046. {
  3047. row1.Cells[j - 4].SetCellValue(Num);
  3048. }
  3049. else
  3050. {
  3051. row1.Cells[j - 4].SetCellValue(Data);
  3052. }
  3053. row1.GetCell(j - 4).CellStyle = styleborder;
  3054. }
  3055. if (DataTable.Columns[j].ColumnName == "io_qty")
  3056. {
  3057. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3058. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  3059. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  3060. row1.Cells[j - 4].CellStyle = styleborder;
  3061. }
  3062. if (DataTable.Columns[j].ColumnName == "rownum")
  3063. {
  3064. row1.Cells[j - 4].SetCellValue(i + 1);
  3065. row1.Cells[j - 4].CellStyle = styleborder;
  3066. }
  3067. if (DataTable.Columns[j].ColumnName == "ch_code")
  3068. {
  3069. sheet.AutoSizeColumn(j - 4);
  3070. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  3071. }
  3072. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  3073. {
  3074. LastBox = Data;
  3075. }
  3076. }
  3077. //固定行号分组的时候自动拼接新的DataTable
  3078. if (i == rowNum - 1)
  3079. {
  3080. DataRow dr = FirstDT.NewRow();
  3081. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  3082. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  3083. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  3084. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  3085. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  3086. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  3087. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  3088. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  3089. dr["pd_ordercode"] = First_OrderCode;
  3090. dr["pr_orispeccode"] = First_Prspec;
  3091. dr["ch_splitbatch"] = First_Batch;
  3092. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  3093. dr["num"] = (i % PageSize) + 1;
  3094. dr["io_qty"] = sumCount;
  3095. FirstDT.Rows.Add(dr);
  3096. row1 = sheet.CreateRow(PaintIndex);
  3097. PaintIndex = PaintIndex + 1;
  3098. for (int j = 0; j < ShowColumnCount; j++)
  3099. {
  3100. row1.CreateCell(j);
  3101. if (j == 0)
  3102. {
  3103. row1.Cells[j].SetCellValue(批小计);
  3104. }
  3105. else if (j == ShowPieceIndex)
  3106. {
  3107. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize == 0 ? PageSize : (rowNum % PageSize)) + 片);
  3108. row1.Cells[j].CellStyle = styleborder;
  3109. }
  3110. else if (j == ShowBoxIndex - 4)
  3111. {
  3112. row1.Cells[j].SetCellValue(LastBox);
  3113. row1.Cells[j].CellStyle = styleborder;
  3114. }
  3115. else if (j == ShowCountIndex)
  3116. {
  3117. row1.Cells[j].SetCellValue(sumCount);
  3118. }
  3119. row1.Cells[j].CellStyle = styleborder;
  3120. }
  3121. row1 = sheet.CreateRow(PaintIndex);
  3122. PaintIndex = PaintIndex + 1;
  3123. for (int j = 0; j < ShowColumnCount; j++)
  3124. {
  3125. row1.CreateCell(j);
  3126. if (j == 0)
  3127. {
  3128. row1.Cells[j].SetCellValue(小计);
  3129. }
  3130. else if (j == ShowPieceIndex)
  3131. {
  3132. row1.Cells[ShowPieceIndex].SetCellValue(rowNum % PageSize + 片);
  3133. row1.Cells[j].CellStyle = styleborder;
  3134. }
  3135. else if (j == ShowBoxIndex - 4)
  3136. {
  3137. row1.Cells[j].SetCellValue(LastBox);
  3138. row1.Cells[j].CellStyle = styleborder;
  3139. }
  3140. else if (j == ShowCountIndex)
  3141. {
  3142. row1.Cells[j].SetCellValue(sumCount);
  3143. }
  3144. row1.Cells[j].CellStyle = styleborder;
  3145. }
  3146. row1 = sheet.CreateRow(PaintIndex);
  3147. for (int j = 0; j < columnNum - 3; j++)
  3148. {
  3149. if (j == 0)
  3150. {
  3151. row1.CreateCell(j);
  3152. row1.Cells[j].SetCellValue("备注");
  3153. }
  3154. else if (j == ShowCountIndex)
  3155. {
  3156. row1.CreateCell(j);
  3157. row1.Cells[j].SetCellValue(totalCount);
  3158. }
  3159. else if (j == ShowRemarkPiece)
  3160. {
  3161. row1.CreateCell(j);
  3162. row1.Cells[j].SetCellValue(rowNum + 片);
  3163. }
  3164. else
  3165. {
  3166. row1.CreateCell(j);
  3167. }
  3168. row1.Cells[j].CellStyle = style;
  3169. }
  3170. sheet.SetRowBreak(PaintIndex);
  3171. sheet.Footer.Center = "第&P页,共&N页";
  3172. PaintIndex = PaintIndex + 1;
  3173. }
  3174. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3175. pib_outboxcode1.Add(BoxCode.ToString());
  3176. }
  3177. break;
  3178. case "BatchCode":
  3179. string LastBatchCode = "";
  3180. int PageNum = 0;
  3181. for (int i = 0; i < rowNum; i++)
  3182. {
  3183. IRow row1 = sheet.CreateRow(PaintIndex);
  3184. PaintIndex = PaintIndex + 1;
  3185. row1.HeightInPoints = RowHeight;
  3186. //如果批号不相等的时候
  3187. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  3188. {
  3189. BoxCode = BoxCode + 1;
  3190. for (int j = 0; j < ShowColumnCount; j++)
  3191. {
  3192. row1.CreateCell(j);
  3193. if (j == 0)
  3194. {
  3195. row1.Cells[j].SetCellValue(小计);
  3196. row1.Cells[j].CellStyle = styleborder;
  3197. }
  3198. else if (j == ShowPieceIndex)
  3199. {
  3200. row1.Cells[ShowPieceIndex].SetCellValue(PageNum - 1 + 片);
  3201. row1.Cells[j].CellStyle = styleborder;
  3202. }
  3203. else if (j == ShowCountIndex)
  3204. {
  3205. row1.Cells[j].SetCellValue(sumCount);
  3206. row1.Cells[j].CellStyle = styleborder;
  3207. }
  3208. else if (j == ShowBoxIndex - 4)
  3209. {
  3210. row1.Cells[j].SetCellValue(LastBox);
  3211. row1.Cells[j].CellStyle = styleborder;
  3212. }
  3213. else
  3214. {
  3215. row1.Cells[j].CellStyle = styleborder;
  3216. }
  3217. }
  3218. sumCount = 0;
  3219. row1 = sheet.CreateRow(PaintIndex);
  3220. sheet.SetRowBreak(PaintIndex - 1);
  3221. sheet.Footer.Center = "第&P页,共&N页";
  3222. PaintIndex = PaintIndex + 1;
  3223. PageNum = 0;
  3224. }
  3225. //每次到了页数开始分页
  3226. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()) || i == rowNum - 1)
  3227. {
  3228. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  3229. //第一行添加客户信息
  3230. //if (i != rowNum - 1)
  3231. {
  3232. for (int j = 0; j < columnNum - 3; j++)
  3233. {
  3234. if (j == 0)
  3235. {
  3236. row1.CreateCell(j);
  3237. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  3238. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  3239. }
  3240. else if (j == ShowDataIndex)
  3241. {
  3242. row1.CreateCell(j);
  3243. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  3244. }
  3245. else
  3246. {
  3247. row1.CreateCell(j);
  3248. }
  3249. row1.GetCell(j).CellStyle = style;
  3250. }
  3251. row1 = sheet.CreateRow(PaintIndex);
  3252. PaintIndex = PaintIndex + 1;
  3253. //第二行添加型号
  3254. for (int j = 0; j < columnNum - 3; j++)
  3255. {
  3256. if (j == 0)
  3257. {
  3258. row1.CreateCell(j);
  3259. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  3260. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  3261. }
  3262. else if (j == ShowSizeIndex)
  3263. {
  3264. row1.CreateCell(j);
  3265. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  3266. }
  3267. else if (j == ShowDataIndex)
  3268. {
  3269. row1.CreateCell(j);
  3270. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  3271. }
  3272. else
  3273. {
  3274. row1.CreateCell(j);
  3275. }
  3276. row1.GetCell(j).CellStyle = style;
  3277. }
  3278. //添加列名
  3279. row1 = sheet.CreateRow(PaintIndex);
  3280. PaintIndex = PaintIndex + 1;
  3281. int showcount = 0;
  3282. for (int j = 4; j < columnNum; j++)
  3283. {
  3284. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  3285. {
  3286. showcount = showcount + 1;
  3287. row1.CreateCell(j - 4);
  3288. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3289. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  3290. }
  3291. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  3292. {
  3293. showcount = showcount + 1;
  3294. row1.CreateCell(j - 4);
  3295. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3296. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  3297. }
  3298. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  3299. {
  3300. showcount = showcount + 1;
  3301. row1.CreateCell(j - 4);
  3302. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3303. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  3304. }
  3305. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3306. {
  3307. }
  3308. else
  3309. {
  3310. showcount = showcount + 1;
  3311. row1.CreateCell(j - 4);
  3312. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3313. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  3314. }
  3315. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  3316. {
  3317. ShowBoxIndex = j;
  3318. }
  3319. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  3320. {
  3321. NumIndex = j;
  3322. if (ShowCountIndex == NumIndex - 4)
  3323. {
  3324. ShowCountIndex = ShowCountIndex + 1;
  3325. }
  3326. }
  3327. }
  3328. ShowColumnCount = showcount;
  3329. row1 = sheet.CreateRow(PaintIndex);
  3330. PaintIndex = PaintIndex + 1;
  3331. }
  3332. }
  3333. //添加数据内容
  3334. for (int j = 4; j < columnNum; j++)
  3335. {
  3336. string Data = DataTable.Rows[i][j].ToString();
  3337. row1.CreateCell(j - 4);
  3338. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3339. {
  3340. }
  3341. else
  3342. {
  3343. double Num = 0;
  3344. if (double.TryParse(Data, out Num))
  3345. {
  3346. row1.Cells[j - 4].SetCellValue(Num);
  3347. }
  3348. else
  3349. {
  3350. row1.Cells[j - 4].SetCellValue(Data);
  3351. }
  3352. row1.Cells[j - 4].CellStyle = styleborder;
  3353. }
  3354. if (DataTable.Columns[j].ColumnName == "io_qty")
  3355. {
  3356. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3357. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  3358. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  3359. }
  3360. if (DataTable.Columns[j].ColumnName == "rownum")
  3361. {
  3362. row1.Cells[j - 4].SetCellValue(i + 1);
  3363. row1.Cells[j - 4].CellStyle = styleborder;
  3364. }
  3365. if (DataTable.Columns[j].ColumnName == "ch_code")
  3366. {
  3367. sheet.AutoSizeColumn(j - 4);
  3368. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  3369. }
  3370. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  3371. {
  3372. LastBox = Data;
  3373. }
  3374. }
  3375. if (i == rowNum - 1)
  3376. {
  3377. row1 = sheet.CreateRow(PaintIndex);
  3378. PaintIndex = PaintIndex + 1;
  3379. for (int j = 0; j < ShowColumnCount; j++)
  3380. {
  3381. row1.CreateCell(j);
  3382. if (j == 0)
  3383. {
  3384. row1.Cells[j].SetCellValue(批小计);
  3385. row1.Cells[j].CellStyle = styleborder;
  3386. }
  3387. else if (j == ShowPieceIndex)
  3388. {
  3389. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  3390. row1.Cells[j].CellStyle = styleborder;
  3391. }
  3392. else if (j == ShowCountIndex)
  3393. {
  3394. row1.Cells[j].SetCellValue(sumCount);
  3395. row1.Cells[j].CellStyle = styleborder;
  3396. }
  3397. else
  3398. {
  3399. row1.Cells[j].CellStyle = styleborder;
  3400. }
  3401. }
  3402. row1 = sheet.CreateRow(PaintIndex);
  3403. PaintIndex = PaintIndex + 1;
  3404. for (int j = 0; j < ShowColumnCount; j++)
  3405. {
  3406. row1.CreateCell(j);
  3407. if (j == 0)
  3408. {
  3409. row1.Cells[j].SetCellValue(小计);
  3410. row1.Cells[j].CellStyle = styleborder;
  3411. }
  3412. else if (j == ShowPieceIndex)
  3413. {
  3414. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  3415. row1.Cells[j].CellStyle = styleborder;
  3416. }
  3417. else if (j == ShowCountIndex)
  3418. {
  3419. row1.Cells[j].SetCellValue(sumCount);
  3420. row1.Cells[j].CellStyle = styleborder;
  3421. }
  3422. else
  3423. {
  3424. row1.Cells[j].CellStyle = styleborder;
  3425. }
  3426. }
  3427. //创建备注内容
  3428. row1 = sheet.CreateRow(PaintIndex);
  3429. for (int j = 0; j < columnNum - 3; j++)
  3430. {
  3431. if (j == 0)
  3432. {
  3433. row1.CreateCell(j);
  3434. row1.Cells[j].SetCellValue("备注");
  3435. }
  3436. else if (j == ShowCountIndex)
  3437. {
  3438. row1.CreateCell(j);
  3439. row1.Cells[j].SetCellValue(totalCount);
  3440. }
  3441. else if (j == ShowRemarkPiece)
  3442. {
  3443. row1.CreateCell(j);
  3444. row1.Cells[j].SetCellValue(rowNum + 片);
  3445. }
  3446. else
  3447. {
  3448. row1.CreateCell(j);
  3449. }
  3450. row1.Cells[j].CellStyle = style;
  3451. }
  3452. sheet.SetRowBreak(PaintIndex);
  3453. sheet.Footer.Center = "第&P页,共&N页";
  3454. PaintIndex = PaintIndex + 1;
  3455. PageNum = 0;
  3456. }
  3457. PageNum = PageNum + 1;
  3458. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3459. pib_outboxcode1.Add(BoxCode.ToString());
  3460. }
  3461. break;
  3462. case "BoxCode":
  3463. string LastBoxCode = "";
  3464. int PageNum1 = 0;
  3465. for (int i = 0; i < rowNum; i++)
  3466. {
  3467. IRow row1 = sheet.CreateRow(PaintIndex);
  3468. PaintIndex = PaintIndex + 1;
  3469. row1.HeightInPoints = RowHeight;
  3470. //如果批号不相等的时候
  3471. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  3472. {
  3473. BoxCode = BoxCode + 1;
  3474. for (int j = 0; j < ShowColumnCount; j++)
  3475. {
  3476. row1.CreateCell(j);
  3477. if (j == 0)
  3478. {
  3479. row1.Cells[j].SetCellValue(小计);
  3480. row1.Cells[j].CellStyle = styleborder;
  3481. }
  3482. else if (j == ShowPieceIndex)
  3483. {
  3484. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3485. row1.Cells[j].CellStyle = styleborder;
  3486. }
  3487. else if (j == ShowCountIndex)
  3488. {
  3489. row1.Cells[j].SetCellValue(sumCount);
  3490. row1.Cells[j].CellStyle = styleborder;
  3491. }
  3492. else if (j == ShowBoxIndex - 4)
  3493. {
  3494. row1.Cells[j].SetCellValue(LastBox);
  3495. row1.Cells[j].CellStyle = styleborder;
  3496. }
  3497. else
  3498. {
  3499. row1.Cells[j].CellStyle = styleborder;
  3500. }
  3501. }
  3502. sumCount = 0;
  3503. row1 = sheet.CreateRow(PaintIndex);
  3504. sheet.SetRowBreak(PaintIndex - 1);
  3505. sheet.Footer.Center = "第&P页,共&N页";
  3506. PaintIndex = PaintIndex + 1;
  3507. PageNum1 = 0;
  3508. }
  3509. //每次到了页数开始分页
  3510. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  3511. {
  3512. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  3513. //第一行添加客户信息
  3514. //if (i != rowNum - 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["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  3522. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  3523. }
  3524. else if (j == ShowDataIndex)
  3525. {
  3526. row1.CreateCell(j);
  3527. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  3528. }
  3529. else
  3530. {
  3531. row1.CreateCell(j);
  3532. }
  3533. row1.GetCell(j).CellStyle = style;
  3534. }
  3535. row1 = sheet.CreateRow(PaintIndex);
  3536. PaintIndex = PaintIndex + 1;
  3537. //第二行添加型号
  3538. for (int j = 0; j < columnNum - 3; j++)
  3539. {
  3540. if (j == 0)
  3541. {
  3542. row1.CreateCell(j);
  3543. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  3544. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  3545. }
  3546. else if (j == ShowSizeIndex)
  3547. {
  3548. row1.CreateCell(j);
  3549. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  3550. }
  3551. else if (j == ShowDataIndex)
  3552. {
  3553. row1.CreateCell(j);
  3554. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  3555. }
  3556. else
  3557. {
  3558. row1.CreateCell(j);
  3559. }
  3560. }
  3561. //添加列名
  3562. row1 = sheet.CreateRow(PaintIndex);
  3563. PaintIndex = PaintIndex + 1;
  3564. int showcount = 0;
  3565. for (int j = 4; j < columnNum; j++)
  3566. {
  3567. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  3568. {
  3569. showcount = showcount + 1;
  3570. row1.CreateCell(j - 4);
  3571. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3572. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  3573. }
  3574. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  3575. {
  3576. showcount = showcount + 1;
  3577. row1.CreateCell(j - 4);
  3578. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3579. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  3580. }
  3581. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  3582. {
  3583. showcount = showcount + 1;
  3584. row1.CreateCell(j - 4);
  3585. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3586. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  3587. }
  3588. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3589. {
  3590. }
  3591. else
  3592. {
  3593. showcount = showcount + 1;
  3594. row1.CreateCell(j - 4);
  3595. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3596. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  3597. }
  3598. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  3599. {
  3600. ShowBoxIndex = j;
  3601. }
  3602. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  3603. {
  3604. NumIndex = j;
  3605. if (ShowCountIndex == NumIndex - 4)
  3606. {
  3607. ShowCountIndex = ShowCountIndex + 1;
  3608. }
  3609. }
  3610. }
  3611. ShowColumnCount = showcount;
  3612. row1 = sheet.CreateRow(PaintIndex);
  3613. PaintIndex = PaintIndex + 1;
  3614. }
  3615. }
  3616. //添加数据内容
  3617. for (int j = 4; j < columnNum; j++)
  3618. {
  3619. string Data = DataTable.Rows[i][j].ToString();
  3620. row1.CreateCell(j - 4);
  3621. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3622. {
  3623. }
  3624. else
  3625. {
  3626. double Num = 0;
  3627. if (double.TryParse(Data, out Num))
  3628. {
  3629. row1.Cells[j - 4].SetCellValue(Num);
  3630. }
  3631. else
  3632. {
  3633. row1.Cells[j - 4].SetCellValue(Data);
  3634. }
  3635. row1.Cells[j - 4].CellStyle = styleborder;
  3636. }
  3637. if (DataTable.Columns[j].ColumnName == "io_qty")
  3638. {
  3639. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3640. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  3641. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  3642. row1.Cells[j - 4].CellStyle = styleborder;
  3643. }
  3644. if (DataTable.Columns[j].ColumnName == "rownum")
  3645. {
  3646. row1.Cells[j - 4].SetCellValue(i + 1);
  3647. row1.Cells[j - 4].CellStyle = styleborder;
  3648. }
  3649. if (DataTable.Columns[j].ColumnName == "ch_code")
  3650. {
  3651. sheet.AutoSizeColumn(j - 4);
  3652. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  3653. }
  3654. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  3655. {
  3656. LastBox = Data;
  3657. }
  3658. }
  3659. if (i == rowNum - 1)
  3660. {
  3661. PageNum1 = PageNum1 + 1;
  3662. row1 = sheet.CreateRow(PaintIndex);
  3663. PaintIndex = PaintIndex + 1;
  3664. for (int j = 0; j < ShowColumnCount; j++)
  3665. {
  3666. row1.CreateCell(j);
  3667. if (j == 0)
  3668. {
  3669. row1.Cells[j].SetCellValue(批小计);
  3670. row1.Cells[j].CellStyle = styleborder;
  3671. }
  3672. else if (j == ShowPieceIndex)
  3673. {
  3674. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3675. row1.Cells[j].CellStyle = styleborder;
  3676. }
  3677. else if (j == ShowCountIndex)
  3678. {
  3679. row1.Cells[j].SetCellValue(sumCount);
  3680. row1.Cells[j].CellStyle = styleborder;
  3681. }
  3682. else if (j == ShowBoxIndex - 4)
  3683. {
  3684. row1.Cells[j].SetCellValue(LastBox);
  3685. row1.Cells[j].CellStyle = styleborder;
  3686. }
  3687. else
  3688. {
  3689. row1.Cells[j].CellStyle = styleborder;
  3690. }
  3691. }
  3692. row1 = sheet.CreateRow(PaintIndex);
  3693. PaintIndex = PaintIndex + 1;
  3694. for (int j = 0; j < ShowColumnCount; j++)
  3695. {
  3696. row1.CreateCell(j);
  3697. if (j == 0)
  3698. {
  3699. row1.Cells[j].SetCellValue(小计);
  3700. row1.Cells[j].CellStyle = styleborder;
  3701. }
  3702. else if (j == ShowPieceIndex)
  3703. {
  3704. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3705. row1.Cells[j].CellStyle = styleborder;
  3706. }
  3707. else if (j == ShowCountIndex)
  3708. {
  3709. row1.Cells[j].SetCellValue(sumCount);
  3710. row1.Cells[j].CellStyle = styleborder;
  3711. }
  3712. else if (j == ShowBoxIndex - 4)
  3713. {
  3714. row1.Cells[j].SetCellValue(LastBox);
  3715. row1.Cells[j].CellStyle = styleborder;
  3716. }
  3717. else
  3718. {
  3719. row1.Cells[j].CellStyle = styleborder;
  3720. }
  3721. }
  3722. row1 = sheet.CreateRow(PaintIndex);
  3723. for (int j = 0; j < columnNum - 3; j++)
  3724. {
  3725. if (j == 0)
  3726. {
  3727. row1.CreateCell(j);
  3728. row1.Cells[j].SetCellValue("备注");
  3729. }
  3730. else if (j == ShowCountIndex)
  3731. {
  3732. row1.CreateCell(j);
  3733. row1.Cells[j].SetCellValue(totalCount);
  3734. }
  3735. else if (j == ShowRemarkPiece)
  3736. {
  3737. row1.CreateCell(j);
  3738. row1.Cells[j].SetCellValue(rowNum + 片);
  3739. }
  3740. else
  3741. {
  3742. row1.CreateCell(j);
  3743. }
  3744. row1.Cells[j].CellStyle = style;
  3745. }
  3746. sheet.SetRowBreak(PaintIndex);
  3747. sheet.Footer.Center = "第&P页,共&N页";
  3748. PaintIndex = PaintIndex + 1;
  3749. PageNum1 = 0;
  3750. }
  3751. PageNum1 = PageNum1 + 1;
  3752. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3753. pib_outboxcode1.Add(BoxCode.ToString());
  3754. }
  3755. break;
  3756. case "BoxSplit":
  3757. string LastBoxCode1 = "";
  3758. int PageNum2 = 0;
  3759. string LastBatch = "";
  3760. int MidCount = 0;
  3761. int SerialNum = 1;
  3762. for (int i = 0; i < rowNum; i++)
  3763. {
  3764. IRow row1 = sheet.CreateRow(PaintIndex);
  3765. PaintIndex = PaintIndex + 1;
  3766. row1.HeightInPoints = RowHeight;
  3767. //如果批号不相等的时候
  3768. if (LastBatch == "" || (LastBatch != "" && LastBatch != DataTable.Rows[i]["ch_splitbatch"].ToString()))
  3769. {
  3770. LastBatch = DataTable.Rows[i]["ch_splitbatch"].ToString();
  3771. for (int j = 0; j < ShowColumnCount; j++)
  3772. {
  3773. if (j == 0)
  3774. {
  3775. row1.CreateCell(j).SetCellValue(SerialNum - 1);
  3776. }
  3777. else if (j == 1)
  3778. {
  3779. row1.CreateCell(j).SetCellValue("批小计");
  3780. }
  3781. else if (j == 2)
  3782. {
  3783. row1.CreateCell(j).SetCellValue(MidCount);
  3784. }
  3785. else if (j == ShowBoxIndex - 4)
  3786. {
  3787. row1.CreateCell(j).SetCellValue(LastBox);
  3788. }
  3789. else
  3790. {
  3791. row1.CreateCell(j);
  3792. }
  3793. row1.Cells[j].CellStyle = styleborder;
  3794. }
  3795. SerialNum = 1;
  3796. MidCount = 0;
  3797. row1 = sheet.CreateRow(PaintIndex);
  3798. PaintIndex = PaintIndex + 1;
  3799. }
  3800. if (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["CH_PBCODE"].ToString())
  3801. {
  3802. BoxCode = BoxCode + 1;
  3803. for (int j = 0; j < ShowColumnCount; j++)
  3804. {
  3805. row1.CreateCell(j);
  3806. if (j == 1)
  3807. {
  3808. row1.Cells[j].SetCellValue(小计);
  3809. row1.Cells[j].CellStyle = styleborder;
  3810. }
  3811. else if (j == 0)
  3812. {
  3813. row1.Cells[0].SetCellValue(PageNum2);
  3814. row1.Cells[j].CellStyle = styleborder;
  3815. }
  3816. else if (j == ShowCountIndex)
  3817. {
  3818. row1.Cells[j].SetCellValue(sumCount);
  3819. row1.Cells[j].CellStyle = styleborder;
  3820. }
  3821. else if (j == ShowBoxIndex - 4)
  3822. {
  3823. row1.Cells[j].SetCellValue(LastBox);
  3824. row1.Cells[j].CellStyle = styleborder;
  3825. }
  3826. else
  3827. {
  3828. row1.Cells[j].CellStyle = styleborder;
  3829. }
  3830. }
  3831. sumCount = 0;
  3832. row1 = sheet.CreateRow(PaintIndex);
  3833. sheet.SetRowBreak(PaintIndex - 1);
  3834. sheet.Footer.Center = "第&P页,共&N页";
  3835. PaintIndex = PaintIndex + 1;
  3836. PageNum2 = 0;
  3837. }
  3838. //每次到了页数开始分页
  3839. if (LastBoxCode1 == "" || (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["ch_pbcode"].ToString())))
  3840. {
  3841. LastBoxCode1 = DataTable.Rows[i]["CH_PBCODE"].ToString();
  3842. //第一行添加客户信息
  3843. //if (i != rowNum - 1)
  3844. {
  3845. for (int j = 0; j < columnNum - 3; j++)
  3846. {
  3847. if (j == 0)
  3848. {
  3849. row1.CreateCell(j);
  3850. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  3851. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  3852. }
  3853. else if (j == ShowDataIndex)
  3854. {
  3855. row1.CreateCell(j);
  3856. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  3857. }
  3858. else
  3859. {
  3860. row1.CreateCell(j);
  3861. }
  3862. row1.GetCell(j).CellStyle = style;
  3863. }
  3864. row1 = sheet.CreateRow(PaintIndex);
  3865. PaintIndex = PaintIndex + 1;
  3866. //第二行添加型号
  3867. for (int j = 0; j < columnNum - 3; j++)
  3868. {
  3869. if (j == 0)
  3870. {
  3871. row1.CreateCell(j);
  3872. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  3873. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  3874. }
  3875. else if (j == ShowSizeIndex)
  3876. {
  3877. row1.CreateCell(j);
  3878. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  3879. }
  3880. else if (j == ShowDataIndex)
  3881. {
  3882. row1.CreateCell(j);
  3883. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  3884. }
  3885. else
  3886. {
  3887. row1.CreateCell(j);
  3888. }
  3889. }
  3890. //添加列名
  3891. row1 = sheet.CreateRow(PaintIndex);
  3892. PaintIndex = PaintIndex + 1;
  3893. int showcount = 0;
  3894. for (int j = 4; j < columnNum; j++)
  3895. {
  3896. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  3897. {
  3898. showcount = showcount + 1;
  3899. row1.CreateCell(j - 4);
  3900. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3901. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  3902. }
  3903. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  3904. {
  3905. showcount = showcount + 1;
  3906. row1.CreateCell(j - 4);
  3907. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3908. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  3909. }
  3910. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  3911. {
  3912. showcount = showcount + 1;
  3913. row1.CreateCell(j - 4);
  3914. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3915. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  3916. }
  3917. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3918. {
  3919. }
  3920. else
  3921. {
  3922. showcount = showcount + 1;
  3923. row1.CreateCell(j - 4);
  3924. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3925. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  3926. }
  3927. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  3928. {
  3929. ShowBoxIndex = j;
  3930. }
  3931. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  3932. {
  3933. NumIndex = j;
  3934. if (ShowCountIndex == NumIndex - 4)
  3935. {
  3936. ShowCountIndex = ShowCountIndex + 1;
  3937. }
  3938. }
  3939. }
  3940. ShowColumnCount = showcount;
  3941. row1 = sheet.CreateRow(PaintIndex);
  3942. PaintIndex = PaintIndex + 1;
  3943. }
  3944. }
  3945. //添加数据内容
  3946. for (int j = 4; j < columnNum; j++)
  3947. {
  3948. string Data = DataTable.Rows[i][j].ToString();
  3949. row1.CreateCell(j - 4);
  3950. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3951. {
  3952. }
  3953. else
  3954. {
  3955. row1.Cells[j - 4].SetCellValue(Data);
  3956. row1.GetCell(j - 4).CellStyle = styleborder;
  3957. }
  3958. if (DataTable.Columns[j].ColumnName == "io_qty")
  3959. {
  3960. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3961. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  3962. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  3963. MidCount += int.Parse(DataTable.Rows[i][j].ToString());
  3964. }
  3965. if (DataTable.Columns[j].ColumnName == "rownum")
  3966. {
  3967. row1.Cells[j - 4].SetCellValue(SerialNum);
  3968. }
  3969. if (DataTable.Columns[j].ColumnName == "ch_code")
  3970. {
  3971. sheet.AutoSizeColumn(j - 4);
  3972. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  3973. }
  3974. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  3975. {
  3976. LastBox = Data;
  3977. }
  3978. }
  3979. if (i == rowNum - 1)
  3980. {
  3981. PageNum2 = PageNum2 + 1;
  3982. row1 = sheet.CreateRow(PaintIndex);
  3983. PaintIndex = PaintIndex + 1;
  3984. for (int j = 0; j < ShowColumnCount; j++)
  3985. {
  3986. row1.CreateCell(j);
  3987. if (j == 0)
  3988. {
  3989. row1.Cells[j].SetCellValue(小计);
  3990. row1.Cells[j].CellStyle = styleborder;
  3991. }
  3992. else if (j == ShowPieceIndex)
  3993. {
  3994. row1.Cells[ShowPieceIndex].SetCellValue(PageNum2 + 片);
  3995. row1.Cells[j].CellStyle = styleborder;
  3996. }
  3997. else if (j == ShowCountIndex)
  3998. {
  3999. row1.Cells[j].SetCellValue(sumCount);
  4000. row1.Cells[j].CellStyle = styleborder;
  4001. }
  4002. else if (j == ShowBoxIndex - 4)
  4003. {
  4004. row1.Cells[j].SetCellValue(LastBox);
  4005. row1.Cells[j].CellStyle = styleborder;
  4006. }
  4007. else
  4008. {
  4009. row1.Cells[j].CellStyle = styleborder;
  4010. }
  4011. }
  4012. row1 = sheet.CreateRow(PaintIndex);
  4013. for (int j = 0; j < columnNum - 3; j++)
  4014. {
  4015. if (j == 0)
  4016. {
  4017. row1.CreateCell(j);
  4018. row1.Cells[j].SetCellValue("备注");
  4019. }
  4020. else if (j == ShowCountIndex)
  4021. {
  4022. row1.CreateCell(j);
  4023. row1.Cells[j].SetCellValue(totalCount);
  4024. }
  4025. else if (j == ShowRemarkPiece)
  4026. {
  4027. row1.CreateCell(j);
  4028. row1.Cells[j].SetCellValue(rowNum + 片);
  4029. }
  4030. else
  4031. {
  4032. row1.CreateCell(j);
  4033. }
  4034. row1.Cells[j].CellStyle = style;
  4035. }
  4036. sheet.SetRowBreak(PaintIndex);
  4037. sheet.Footer.Center = "第&P页,共&N页";
  4038. PaintIndex = PaintIndex + 1;
  4039. PageNum1 = 0;
  4040. }
  4041. PageNum2 = PageNum2 + 1;
  4042. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  4043. pib_outboxcode1.Add(BoxCode.ToString());
  4044. SerialNum = SerialNum + 1;
  4045. }
  4046. break;
  4047. default:
  4048. break;
  4049. }
  4050. 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());
  4051. //删除下载链接再重新插入
  4052. HttpHandler.GenDownLoadLinK(Inoutno);
  4053. //填充首页
  4054. sumCount = 0;
  4055. totalCount = 0;
  4056. PaintIndex = 1;
  4057. ISheet sheet2 = book.CreateSheet("首页");
  4058. row = sheet2.CreateRow(0);
  4059. row.CreateCell(0);
  4060. row.Cells[0].SetCellValue(" " + companyname);
  4061. row.GetCell(0).CellStyle = style;
  4062. rowNum = FirstDT.Rows.Count;
  4063. //不需要显示的列移除
  4064. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  4065. {
  4066. for (int j = 0; j < box.Length; j++)
  4067. {
  4068. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  4069. {
  4070. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  4071. {
  4072. FirstDT.Columns.RemoveAt(i);
  4073. }
  4074. }
  4075. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  4076. {
  4077. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  4078. {
  4079. FirstDT.Columns.RemoveAt(i);
  4080. }
  4081. }
  4082. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  4083. {
  4084. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  4085. {
  4086. FirstDT.Columns.RemoveAt(i);
  4087. }
  4088. }
  4089. if (box[j].Name == "FirstPage_BOXCODE" && !box[j].Checked)
  4090. {
  4091. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  4092. {
  4093. FirstDT.Columns.RemoveAt(i);
  4094. }
  4095. }
  4096. }
  4097. }
  4098. columnNum = FirstDT.Columns.Count;
  4099. for (int i = 0; i < rowNum; i++)
  4100. {
  4101. IRow row1 = sheet2.CreateRow(PaintIndex);
  4102. PaintIndex = PaintIndex + 1;
  4103. row1.HeightInPoints = RowHeight;
  4104. //只需要绘制一行
  4105. if (i == 0)
  4106. {
  4107. for (int j = 0; j < columnNum - 3; j++)
  4108. {
  4109. if (j == 0)
  4110. {
  4111. row1.CreateCell(j);
  4112. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString() + " "
  4113. + FirstDT.Columns["ch_level"].Caption + ":" + FirstDT.Rows[i]["ch_level"].ToString());
  4114. }
  4115. else if (j > 5 && j == columnNum - 5)
  4116. {
  4117. row1.CreateCell(j);
  4118. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  4119. }
  4120. else if (columnNum > 5 && j == columnNum - 5)
  4121. {
  4122. row1.CreateCell(j);
  4123. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  4124. }
  4125. else
  4126. {
  4127. row1.CreateCell(j);
  4128. }
  4129. row1.GetCell(j).CellStyle = style;
  4130. }
  4131. row1 = sheet2.CreateRow(PaintIndex);
  4132. PaintIndex = PaintIndex + 1;
  4133. //第二行添加型号
  4134. for (int j = 0; j < columnNum - 3; j++)
  4135. {
  4136. if (j == 0)
  4137. {
  4138. row1.CreateCell(j).SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString() + "_"
  4139. + "(" + FirstDT.Rows[i]["me_desc"].ToString() + ")" + FirstDT.Columns["pi_chipouttype"].Caption + ":" + FirstDT.Rows[i]["pi_chipouttype"].ToString());
  4140. }
  4141. else if (j == ShowSizeIndex)
  4142. {
  4143. row1.CreateCell(j);
  4144. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_size"].Caption + ":" + FirstDT.Rows[i]["pr_size"].ToString());
  4145. }
  4146. else if (j > 5 && j == columnNum - 5)
  4147. {
  4148. row1.CreateCell(j);
  4149. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  4150. }
  4151. else if (columnNum > 5 && j == columnNum - 5)
  4152. {
  4153. row1.CreateCell(j);
  4154. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  4155. }
  4156. else
  4157. {
  4158. row1.CreateCell(j);
  4159. }
  4160. row1.GetCell(j).CellStyle = style;
  4161. }
  4162. row1 = sheet2.CreateRow(PaintIndex);
  4163. PaintIndex = PaintIndex + 1;
  4164. //添加列名
  4165. for (int j = 4; j < columnNum; j++)
  4166. {
  4167. row1.CreateCell(j - 4);
  4168. if (NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  4169. {
  4170. }
  4171. else
  4172. {
  4173. row1.Cells[j - 4].CellStyle = styleborder;
  4174. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  4175. }
  4176. }
  4177. row1 = sheet2.CreateRow(PaintIndex);
  4178. PaintIndex = PaintIndex + 1;
  4179. }
  4180. //添加数据内容
  4181. ShowColumnCount = 0;
  4182. for (int j = 4; j < columnNum; j++)
  4183. {
  4184. row1.CreateCell(j - 4);
  4185. if (!NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  4186. {
  4187. string Data = FirstDT.Rows[i][j].ToString();
  4188. row1.Cells[j - 4].SetCellValue(Data);
  4189. row1.GetCell(j - 4).CellStyle = styleborder;
  4190. if (FirstDT.Columns[j].ColumnName == "num")
  4191. {
  4192. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  4193. sumCount += int.Parse(Data);
  4194. }
  4195. if (FirstDT.Columns[j].ColumnName == "io_qty")
  4196. {
  4197. totalCount += int.Parse(Data);
  4198. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  4199. }
  4200. ShowColumnCount = ShowColumnCount + 1;
  4201. }
  4202. else
  4203. {
  4204. }
  4205. }
  4206. //添加总计行
  4207. if (i == rowNum - 1)
  4208. {
  4209. row1 = sheet2.CreateRow(PaintIndex);
  4210. PaintIndex = PaintIndex + 1;
  4211. for (int j = 0; j < ShowColumnCount; j++)
  4212. {
  4213. if (j == 0)
  4214. {
  4215. row1.CreateCell(j);
  4216. row1.Cells[j].CellStyle = styleborder;
  4217. row1.Cells[j].SetCellValue(总计);
  4218. }
  4219. else if (j == ShowColumnCount - 2)
  4220. {
  4221. row1.CreateCell(j);
  4222. row1.Cells[j].CellStyle = styleborder;
  4223. row1.Cells[j].SetCellValue(sumCount);
  4224. }
  4225. else if (j == ShowColumnCount - 1)
  4226. {
  4227. row1.CreateCell(j);
  4228. row1.Cells[j].CellStyle = styleborder;
  4229. row1.Cells[j].SetCellValue(totalCount);
  4230. }
  4231. else
  4232. {
  4233. row1.CreateCell(j);
  4234. row1.Cells[j].CellStyle = styleborder;
  4235. }
  4236. }
  4237. }
  4238. }
  4239. //将book的内容写入内存流中返回
  4240. book.Write(ms);
  4241. return ms;
  4242. }
  4243. }
  4244. }