ExcelHandler.cs 231 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438
  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. row1.Cells[j - 4].CellStyle = styleborder;
  1886. }
  1887. //固定行号分组的时候自动拼接新的DataTable
  1888. if (i == rowNum - 1)
  1889. {
  1890. DataRow dr = FirstDT.NewRow();
  1891. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  1892. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  1893. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  1894. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  1895. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  1896. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  1897. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  1898. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  1899. dr["pd_ordercode"] = First_OrderCode;
  1900. dr["pr_orispeccode"] = First_Prspec;
  1901. dr["ch_splitbatch"] = First_Batch;
  1902. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  1903. dr["num"] = (i % PageSize) + 1;
  1904. dr["io_qty"] = sumCount;
  1905. FirstDT.Rows.Add(dr);
  1906. row1 = sheet.CreateRow(PaintIndex);
  1907. PaintIndex = PaintIndex + 1;
  1908. for (int j = 0; j < ShowColumnCount; j++)
  1909. {
  1910. row1.CreateCell(j);
  1911. if (j == 0)
  1912. {
  1913. row1.Cells[j].SetCellValue(小计);
  1914. }
  1915. else if (j == ShowPieceIndex)
  1916. {
  1917. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize == 0 ? PageSize : (rowNum % PageSize)) + 片);
  1918. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1919. }
  1920. else if (j == ShowCountIndex)
  1921. {
  1922. row1.Cells[j].SetCellValue(sumCount);
  1923. }
  1924. row1.Cells[j].CellStyle = styleborder;
  1925. }
  1926. row1 = sheet.CreateRow(PaintIndex);
  1927. for (int j = 0; j < columnNum - 3; j++)
  1928. {
  1929. if (j == 0)
  1930. {
  1931. row1.CreateCell(j);
  1932. row1.Cells[j].SetCellValue("备注");
  1933. }
  1934. else if (j == ShowCountIndex)
  1935. {
  1936. row1.CreateCell(j);
  1937. row1.Cells[j].SetCellValue(totalCount);
  1938. }
  1939. else if (j == ShowRemarkPiece)
  1940. {
  1941. row1.CreateCell(j);
  1942. row1.Cells[j].SetCellValue(rowNum + 片);
  1943. }
  1944. else
  1945. {
  1946. row1.CreateCell(j);
  1947. }
  1948. row1.Cells[j].CellStyle = style;
  1949. }
  1950. sheet.SetRowBreak(PaintIndex);
  1951. sheet.Footer.Center = "第&P页,共&N页";
  1952. }
  1953. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  1954. pib_outboxcode1.Add(BoxCode.ToString());
  1955. }
  1956. break;
  1957. case "BatchCode":
  1958. string LastBatchCode = "";
  1959. int PageNum = 0;
  1960. for (int i = 0; i < rowNum; i++)
  1961. {
  1962. row1 = sheet.CreateRow(PaintIndex);
  1963. if (i != 0)
  1964. PaintIndex = PaintIndex + 1;
  1965. row1.HeightInPoints = RowHeight;
  1966. //如果批号不相等的时候
  1967. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  1968. {
  1969. BoxCode = BoxCode + 1;
  1970. for (int j = 0; j < ShowColumnCount; j++)
  1971. {
  1972. row1.CreateCell(j);
  1973. if (j == 0)
  1974. {
  1975. row1.Cells[j].SetCellValue(小计);
  1976. row1.Cells[j].CellStyle = styleborder;
  1977. }
  1978. else if (j == ShowPieceIndex)
  1979. {
  1980. row1.Cells[ShowPieceIndex].SetCellValue(PageNum);
  1981. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1982. }
  1983. else if (j == ShowCountIndex)
  1984. {
  1985. row1.Cells[j].SetCellValue(sumCount);
  1986. row1.Cells[j].CellStyle = styleborder;
  1987. }
  1988. else
  1989. {
  1990. row1.Cells[j].CellStyle = styleborder;
  1991. }
  1992. }
  1993. sumCount = 0;
  1994. //row1 = sheet.CreateRow(PaintIndex);
  1995. sheet.SetRowBreak(PaintIndex - 1);
  1996. sheet.Footer.Center = "第&P页,共&N页";
  1997. PageNum = 0;
  1998. }
  1999. //每次到了页数开始分页
  2000. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()))
  2001. {
  2002. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  2003. //第一行添加客户信息
  2004. row1 = sheet.CreateRow(PaintIndex);
  2005. PaintIndex = PaintIndex + 1;
  2006. row1.CreateCell(0).SetCellValue(" " + companyname);
  2007. row1.GetCell(0).CellStyle = TitleStyle;
  2008. row1 = sheet.CreateRow(PaintIndex);
  2009. PaintIndex = PaintIndex + 1;
  2010. //if (i != rowNum - 1)
  2011. {
  2012. for (int j = 0; j < columnNum - 3; j++)
  2013. {
  2014. if (j == 0)
  2015. {
  2016. row1.CreateCell(j);
  2017. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  2018. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  2019. }
  2020. else if (j == ShowDataIndex)
  2021. {
  2022. row1.CreateCell(j);
  2023. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  2024. }
  2025. else
  2026. {
  2027. row1.CreateCell(j);
  2028. }
  2029. row1.GetCell(j).CellStyle = style;
  2030. }
  2031. row1 = sheet.CreateRow(PaintIndex);
  2032. PaintIndex = PaintIndex + 1;
  2033. //第二行添加型号
  2034. for (int j = 0; j < columnNum - 3; j++)
  2035. {
  2036. if (j == 0)
  2037. {
  2038. row1.CreateCell(j);
  2039. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  2040. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2041. }
  2042. else if (j == ShowSizeIndex)
  2043. {
  2044. row1.CreateCell(j);
  2045. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  2046. }
  2047. else if (j == ShowDataIndex)
  2048. {
  2049. row1.CreateCell(j);
  2050. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  2051. }
  2052. else
  2053. {
  2054. row1.CreateCell(j);
  2055. }
  2056. row1.GetCell(j).CellStyle = style;
  2057. }
  2058. //特殊客户添加一列空行
  2059. row1 = sheet.CreateRow(PaintIndex);
  2060. PaintIndex = PaintIndex + 1;
  2061. for (int j = 0; j < columnNum; j++)
  2062. {
  2063. row1.CreateCell(j).SetCellValue("");
  2064. }
  2065. //添加列名
  2066. row1 = sheet.CreateRow(PaintIndex);
  2067. PaintIndex = PaintIndex + 1;
  2068. int showcount = 0;
  2069. for (int j = 4; j < columnNum; j++)
  2070. {
  2071. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  2072. {
  2073. showcount = showcount + 1;
  2074. row1.CreateCell(j - 4);
  2075. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2076. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  2077. }
  2078. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2079. {
  2080. showcount = showcount + 1;
  2081. row1.CreateCell(j - 4);
  2082. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2083. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  2084. }
  2085. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  2086. {
  2087. showcount = showcount + 1;
  2088. row1.CreateCell(j - 4);
  2089. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2090. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  2091. }
  2092. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2093. {
  2094. }
  2095. else
  2096. {
  2097. showcount = showcount + 1;
  2098. row1.CreateCell(j - 4);
  2099. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2100. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  2101. }
  2102. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  2103. {
  2104. NumIndex = j - 4;
  2105. }
  2106. }
  2107. ShowColumnCount = showcount;
  2108. row1 = sheet.CreateRow(PaintIndex);
  2109. PaintIndex = PaintIndex + 1;
  2110. }
  2111. }
  2112. //添加数据内容
  2113. for (int j = 4; j < columnNum; j++)
  2114. {
  2115. string Data = DataTable.Rows[i][j].ToString();
  2116. row1.CreateCell(j - 4);
  2117. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2118. {
  2119. }
  2120. else
  2121. {
  2122. double Num = 0;
  2123. if (double.TryParse(Data, out Num))
  2124. {
  2125. row1.Cells[j - 4].SetCellValue(Num);
  2126. }
  2127. else
  2128. {
  2129. row1.Cells[j - 4].SetCellValue(Data);
  2130. }
  2131. row1.Cells[j - 4].CellStyle = styleborder;
  2132. }
  2133. if (DataTable.Columns[j].ColumnName == "io_qty")
  2134. {
  2135. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2136. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  2137. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  2138. }
  2139. if (DataTable.Columns[j].ColumnName == "rownum")
  2140. {
  2141. row1.Cells[j - 4].SetCellValue(i + 1);
  2142. }
  2143. if (DataTable.Columns[j].ColumnName == "ch_code")
  2144. {
  2145. sheet.AutoSizeColumn(j - 4);
  2146. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  2147. }
  2148. row1.Cells[j - 4].CellStyle = styleborder;
  2149. }
  2150. if (i == rowNum - 1)
  2151. {
  2152. row1 = sheet.CreateRow(PaintIndex);
  2153. PaintIndex = PaintIndex + 1;
  2154. for (int j = 0; j < ShowColumnCount; j++)
  2155. {
  2156. row1.CreateCell(j);
  2157. if (j == 0)
  2158. {
  2159. row1.Cells[j].SetCellValue(小计);
  2160. row1.Cells[j].CellStyle = styleborder;
  2161. }
  2162. else if (j == ShowPieceIndex)
  2163. {
  2164. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  2165. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2166. }
  2167. else if (j == ShowCountIndex)
  2168. {
  2169. row1.Cells[j].SetCellValue(sumCount);
  2170. row1.Cells[j].CellStyle = styleborder;
  2171. }
  2172. else
  2173. {
  2174. row1.Cells[j].CellStyle = styleborder;
  2175. }
  2176. }
  2177. //创建备注内容
  2178. row1 = sheet.CreateRow(PaintIndex);
  2179. for (int j = 0; j < columnNum - 3; j++)
  2180. {
  2181. if (j == 0)
  2182. {
  2183. row1.CreateCell(j);
  2184. row1.Cells[j].SetCellValue("备注");
  2185. }
  2186. else if (j == ShowCountIndex)
  2187. {
  2188. row1.CreateCell(j);
  2189. row1.Cells[j].SetCellValue(totalCount);
  2190. }
  2191. else if (j == ShowRemarkPiece)
  2192. {
  2193. row1.CreateCell(j);
  2194. row1.Cells[j].SetCellValue(rowNum + 片);
  2195. }
  2196. else
  2197. {
  2198. row1.CreateCell(j);
  2199. }
  2200. row1.Cells[j].CellStyle = style;
  2201. }
  2202. sheet.SetRowBreak(PaintIndex);
  2203. sheet.Footer.Center = "第&P页,共&N页";
  2204. PageNum = 0;
  2205. }
  2206. PageNum = PageNum + 1;
  2207. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  2208. pib_outboxcode1.Add(BoxCode.ToString());
  2209. }
  2210. break;
  2211. case "BoxCode":
  2212. string LastBoxCode = "";
  2213. int PageNum1 = 0;
  2214. for (int i = 0; i < rowNum; i++)
  2215. {
  2216. row1 = sheet.CreateRow(PaintIndex);
  2217. if (i != 0)
  2218. PaintIndex = PaintIndex + 1;
  2219. row1.HeightInPoints = RowHeight;
  2220. //如果箱号不相等的时候
  2221. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  2222. {
  2223. BoxCode = BoxCode + 1;
  2224. for (int j = 0; j < ShowColumnCount; j++)
  2225. {
  2226. row1.CreateCell(j);
  2227. if (j == 0)
  2228. {
  2229. row1.Cells[j].SetCellValue(小计);
  2230. row1.Cells[j].CellStyle = styleborder;
  2231. }
  2232. else if (j == ShowPieceIndex)
  2233. {
  2234. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  2235. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2236. }
  2237. else if (j == ShowCountIndex)
  2238. {
  2239. row1.Cells[j].SetCellValue(sumCount);
  2240. row1.Cells[j].CellStyle = styleborder;
  2241. }
  2242. else
  2243. {
  2244. row1.Cells[j].CellStyle = styleborder;
  2245. }
  2246. }
  2247. sumCount = 0;
  2248. //row1 = sheet.CreateRow(PaintIndex);
  2249. sheet.SetRowBreak(PaintIndex - 1);
  2250. sheet.Footer.Center = "第&P页,共&N页";
  2251. PageNum1 = 0;
  2252. }
  2253. //每次到了页数开始分页
  2254. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  2255. {
  2256. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  2257. row1 = sheet.CreateRow(PaintIndex);
  2258. PaintIndex = PaintIndex + 1;
  2259. row1.CreateCell(0).SetCellValue(" " + companyname);
  2260. row1.GetCell(0).CellStyle = TitleStyle;
  2261. row1 = sheet.CreateRow(PaintIndex);
  2262. PaintIndex = PaintIndex + 1;
  2263. //第一行添加客户信息
  2264. //if (i != rowNum - 1)
  2265. {
  2266. for (int j = 0; j < columnNum - 3; j++)
  2267. {
  2268. if (j == 0)
  2269. {
  2270. row1.CreateCell(j);
  2271. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  2272. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  2273. }
  2274. else if (j == ShowDataIndex)
  2275. {
  2276. row1.CreateCell(j);
  2277. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  2278. }
  2279. else
  2280. {
  2281. row1.CreateCell(j);
  2282. }
  2283. row1.GetCell(j).CellStyle = style;
  2284. }
  2285. row1 = sheet.CreateRow(PaintIndex);
  2286. PaintIndex = PaintIndex + 1;
  2287. //第二行添加型号
  2288. for (int j = 0; j < columnNum - 3; j++)
  2289. {
  2290. if (j == 0)
  2291. {
  2292. row1.CreateCell(j);
  2293. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  2294. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2295. }
  2296. else if (j == ShowSizeIndex)
  2297. {
  2298. row1.CreateCell(j);
  2299. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  2300. }
  2301. else if (j == ShowDataIndex)
  2302. {
  2303. row1.CreateCell(j);
  2304. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  2305. }
  2306. else
  2307. {
  2308. row1.CreateCell(j);
  2309. }
  2310. row1.GetCell(j).CellStyle = style;
  2311. }
  2312. //特殊客户添加一列空行
  2313. row1 = sheet.CreateRow(PaintIndex);
  2314. PaintIndex = PaintIndex + 1;
  2315. for (int j = 0; j < columnNum; j++)
  2316. {
  2317. row1.CreateCell(j).SetCellValue("");
  2318. }
  2319. //添加列名
  2320. row1 = sheet.CreateRow(PaintIndex);
  2321. PaintIndex = PaintIndex + 1;
  2322. int showcount = 0;
  2323. for (int j = 4; j < columnNum; j++)
  2324. {
  2325. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  2326. {
  2327. showcount = showcount + 1;
  2328. row1.CreateCell(j - 4);
  2329. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2330. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  2331. }
  2332. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2333. {
  2334. showcount = showcount + 1;
  2335. row1.CreateCell(j - 4);
  2336. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2337. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  2338. }
  2339. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  2340. {
  2341. showcount = showcount + 1;
  2342. row1.CreateCell(j - 4);
  2343. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2344. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  2345. }
  2346. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2347. {
  2348. }
  2349. else
  2350. {
  2351. showcount = showcount + 1;
  2352. row1.CreateCell(j - 4);
  2353. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2354. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  2355. }
  2356. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  2357. {
  2358. NumIndex = j - 4;
  2359. }
  2360. }
  2361. ShowColumnCount = showcount;
  2362. row1 = sheet.CreateRow(PaintIndex);
  2363. PaintIndex = PaintIndex + 1;
  2364. }
  2365. }
  2366. //添加数据内容
  2367. for (int j = 4; j < columnNum; j++)
  2368. {
  2369. string Data = DataTable.Rows[i][j].ToString();
  2370. row1.CreateCell(j - 4);
  2371. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2372. {
  2373. }
  2374. else
  2375. {
  2376. double Num = 0;
  2377. if (double.TryParse(Data, out Num))
  2378. {
  2379. row1.Cells[j - 4].SetCellValue(Num);
  2380. }
  2381. else
  2382. {
  2383. row1.Cells[j - 4].SetCellValue(Data);
  2384. }
  2385. row1.Cells[j - 4].CellStyle = styleborder;
  2386. }
  2387. if (DataTable.Columns[j].ColumnName == "io_qty")
  2388. {
  2389. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2390. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  2391. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  2392. }
  2393. if (DataTable.Columns[j].ColumnName == "rownum")
  2394. {
  2395. row1.Cells[j - 4].SetCellValue(i + 1);
  2396. }
  2397. if (DataTable.Columns[j].ColumnName == "ch_code")
  2398. {
  2399. sheet.AutoSizeColumn(j - 4);
  2400. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  2401. }
  2402. row1.Cells[j - 4].CellStyle = styleborder;
  2403. }
  2404. if (i == rowNum - 1)
  2405. {
  2406. PageNum1 = PageNum1 + 1;
  2407. row1 = sheet.CreateRow(PaintIndex);
  2408. PaintIndex = PaintIndex + 1;
  2409. for (int j = 0; j < ShowColumnCount; j++)
  2410. {
  2411. row1.CreateCell(j);
  2412. if (j == 0)
  2413. {
  2414. row1.Cells[j].SetCellValue(小计);
  2415. row1.Cells[j].CellStyle = styleborder;
  2416. }
  2417. else if (j == ShowPieceIndex)
  2418. {
  2419. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  2420. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2421. }
  2422. else if (j == ShowCountIndex)
  2423. {
  2424. row1.Cells[j].SetCellValue(sumCount);
  2425. row1.Cells[j].CellStyle = styleborder;
  2426. }
  2427. else
  2428. {
  2429. row1.Cells[j].CellStyle = styleborder;
  2430. }
  2431. }
  2432. row1 = sheet.CreateRow(PaintIndex);
  2433. for (int j = 0; j < columnNum - 3; j++)
  2434. {
  2435. if (j == 0)
  2436. {
  2437. row1.CreateCell(j);
  2438. row1.Cells[j].SetCellValue("备注");
  2439. }
  2440. else if (j == ShowCountIndex)
  2441. {
  2442. row1.CreateCell(j);
  2443. row1.Cells[j].SetCellValue(totalCount);
  2444. }
  2445. else if (j == ShowRemarkPiece)
  2446. {
  2447. row1.CreateCell(j);
  2448. row1.Cells[j].SetCellValue(rowNum + 片);
  2449. }
  2450. else
  2451. {
  2452. row1.CreateCell(j);
  2453. }
  2454. row1.Cells[j].CellStyle = style;
  2455. }
  2456. sheet.SetRowBreak(PaintIndex);
  2457. sheet.Footer.Center = "第&P页,共&N页";
  2458. PageNum1 = 0;
  2459. }
  2460. PageNum1 = PageNum1 + 1;
  2461. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  2462. pib_outboxcode1.Add(BoxCode.ToString());
  2463. }
  2464. break;
  2465. default:
  2466. break;
  2467. }
  2468. 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());
  2469. //删除下载链接再重新插入
  2470. HttpHandler.GenDownLoadLinK(Inoutno);
  2471. //填充首页
  2472. sumCount = 0;
  2473. totalCount = 0;
  2474. PaintIndex = 0;
  2475. ISheet sheet2 = book.CreateSheet("首页");
  2476. IRow row = sheet2.CreateRow(0);
  2477. row.CreateCell(0);
  2478. row.Cells[0].SetCellValue(" " + companyname);
  2479. row.GetCell(0).CellStyle = style;
  2480. rowNum = FirstDT.Rows.Count;
  2481. //不需要显示的列移除
  2482. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  2483. {
  2484. for (int j = 0; j < box.Length; j++)
  2485. {
  2486. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  2487. {
  2488. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  2489. {
  2490. FirstDT.Columns.RemoveAt(i);
  2491. }
  2492. }
  2493. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  2494. {
  2495. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  2496. {
  2497. FirstDT.Columns.RemoveAt(i);
  2498. }
  2499. }
  2500. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  2501. {
  2502. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  2503. {
  2504. FirstDT.Columns.RemoveAt(i);
  2505. }
  2506. }
  2507. if (box[j].Name == "FirstPage_BOXCODE" && !box[j].Checked)
  2508. {
  2509. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  2510. {
  2511. FirstDT.Columns.RemoveAt(i);
  2512. }
  2513. }
  2514. }
  2515. }
  2516. columnNum = FirstDT.Columns.Count;
  2517. for (int i = 0; i < rowNum; i++)
  2518. {
  2519. row1 = sheet2.CreateRow(PaintIndex);
  2520. PaintIndex = PaintIndex + 1;
  2521. row1.HeightInPoints = RowHeight;
  2522. //只需要绘制一行
  2523. if (i == 0)
  2524. {
  2525. for (int j = 0; j < columnNum - 3; j++)
  2526. {
  2527. if (j == 0)
  2528. {
  2529. row1.CreateCell(j);
  2530. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString() + " "
  2531. + FirstDT.Columns["ch_level"].Caption + ":" + FirstDT.Rows[i]["ch_level"].ToString());
  2532. }
  2533. else if (j > 5 && j == columnNum - 5)
  2534. {
  2535. row1.CreateCell(j);
  2536. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  2537. }
  2538. else if (columnNum > 5 && j == columnNum - 5)
  2539. {
  2540. row1.CreateCell(j);
  2541. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  2542. }
  2543. else
  2544. {
  2545. row1.CreateCell(j);
  2546. }
  2547. row1.GetCell(j).CellStyle = style;
  2548. }
  2549. row1 = sheet2.CreateRow(PaintIndex);
  2550. PaintIndex = PaintIndex + 1;
  2551. //第二行添加型号
  2552. for (int j = 0; j < columnNum - 3; j++)
  2553. {
  2554. if (j == 0)
  2555. {
  2556. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  2557. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ")" + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2558. }
  2559. else if (j == ShowSizeIndex)
  2560. {
  2561. row1.CreateCell(j);
  2562. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_size"].Caption + ":" + FirstDT.Rows[i]["pr_size"].ToString());
  2563. }
  2564. else if (j > 5 && j == columnNum - 5)
  2565. {
  2566. row1.CreateCell(j);
  2567. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  2568. }
  2569. else if (columnNum > 5 && j == columnNum - 5)
  2570. {
  2571. row1.CreateCell(j);
  2572. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  2573. }
  2574. else
  2575. {
  2576. row1.CreateCell(j);
  2577. }
  2578. row1.GetCell(j).CellStyle = style;
  2579. }
  2580. row1 = sheet2.CreateRow(PaintIndex);
  2581. PaintIndex = PaintIndex + 1;
  2582. //添加列名
  2583. for (int j = 4; j < columnNum; j++)
  2584. {
  2585. row1.CreateCell(j - 4);
  2586. if (NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  2587. {
  2588. }
  2589. else
  2590. {
  2591. row1.Cells[j - 4].CellStyle = styleborder;
  2592. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  2593. }
  2594. }
  2595. row1 = sheet2.CreateRow(PaintIndex);
  2596. PaintIndex = PaintIndex + 1;
  2597. }
  2598. //添加数据内容
  2599. ShowColumnCount = 0;
  2600. for (int j = 4; j < columnNum; j++)
  2601. {
  2602. row1.CreateCell(j - 4);
  2603. if (!NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  2604. {
  2605. string Data = FirstDT.Rows[i][j].ToString();
  2606. row1.Cells[j - 4].SetCellValue(Data);
  2607. row1.GetCell(j - 4).CellStyle = styleborder;
  2608. if (FirstDT.Columns[j].ColumnName == "num")
  2609. {
  2610. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2611. sumCount += int.Parse(Data);
  2612. }
  2613. if (FirstDT.Columns[j].ColumnName == "io_qty")
  2614. {
  2615. totalCount += int.Parse(Data);
  2616. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2617. }
  2618. ShowColumnCount = ShowColumnCount + 1;
  2619. }
  2620. else
  2621. {
  2622. }
  2623. }
  2624. //添加总计行
  2625. if (i == rowNum - 1)
  2626. {
  2627. row1 = sheet2.CreateRow(PaintIndex);
  2628. PaintIndex = PaintIndex + 1;
  2629. for (int j = 0; j < ShowColumnCount; j++)
  2630. {
  2631. if (j == 0)
  2632. {
  2633. row1.CreateCell(j);
  2634. row1.Cells[j].CellStyle = styleborder;
  2635. row1.Cells[j].SetCellValue(总计);
  2636. }
  2637. else if (j == ShowColumnCount - 2)
  2638. {
  2639. row1.CreateCell(j);
  2640. row1.Cells[j].CellStyle = styleborder;
  2641. row1.Cells[j].SetCellValue(sumCount);
  2642. }
  2643. else if (j == ShowColumnCount - 1)
  2644. {
  2645. row1.CreateCell(j);
  2646. row1.Cells[j].CellStyle = styleborder;
  2647. row1.Cells[j].SetCellValue(totalCount);
  2648. }
  2649. else
  2650. {
  2651. row1.CreateCell(j);
  2652. row1.Cells[j].CellStyle = styleborder;
  2653. }
  2654. }
  2655. }
  2656. }
  2657. for (int i = 0; i < sheet2.LastRowNum; i++)
  2658. {
  2659. if (i != 0)
  2660. {
  2661. sheet2.AutoSizeColumn(i);
  2662. sheet2.SetColumnWidth(i, sheet2.GetColumnWidth(i) + 1000);
  2663. }
  2664. }
  2665. //将book的内容写入内存流中返回
  2666. book.Write(ms);
  2667. return ms;
  2668. }
  2669. /// <summary>
  2670. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  2671. /// </summary>
  2672. /// <param name="DataTable"></param>
  2673. /// <returns></returns>
  2674. private MemoryStream DataTableToExcel_LIPUXIN(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  2675. {
  2676. string 小计 = "";
  2677. string 批小计 = "";
  2678. string 总计 = "";
  2679. string 片 = "";
  2680. string companyname = "";
  2681. int ShowBoxIndex = 0;
  2682. //用于小计的盒号
  2683. string LastBox = "";
  2684. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype", "pi_inoutno='" + Inoutno + "'").ToString() == "Chinese")
  2685. {
  2686. 小计 = "小计";
  2687. 总计 = "总计";
  2688. 批小计 = "批小计";
  2689. companyname = "深爱半导体股份有限公司芯片出货清单";
  2690. }
  2691. else
  2692. {
  2693. 批小计 = "BatchTotal";
  2694. 小计 = "total";
  2695. 总计 = "total";
  2696. companyname = "SHENZHEN SI SEMICONDUCTORS CO.,LTD";
  2697. }
  2698. //转换为序列
  2699. CheckBox[] box = conditionbox.ToArray();
  2700. //创建内存流
  2701. MemoryStream ms = new MemoryStream();
  2702. //创建一个Book,相当于一个Excel文件
  2703. HSSFWorkbook book = new HSSFWorkbook();
  2704. //Excel中的Sheet
  2705. ISheet sheet = book.CreateSheet("分页");
  2706. sheet.SetMargin(MarginType.TopMargin, 0.4);
  2707. sheet.SetMargin(MarginType.BottomMargin, 0.4);
  2708. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  2709. sheet.SetMargin(MarginType.RightMargin, 0.4);
  2710. sheet.FitToPage = true;
  2711. sheet.PrintSetup.FitHeight = 200;
  2712. //芯片号需要作为更新盒号的条件
  2713. HSSFFont ffont = (HSSFFont)book.CreateFont();
  2714. ffont.FontName = "宋体";
  2715. //更新箱号
  2716. List<string> pib_id = new List<string>();
  2717. //系统打印箱号
  2718. List<string> pib_outboxcode1 = new List<string>();
  2719. int BoxCode = 1;
  2720. ICellStyle style = book.CreateCellStyle();
  2721. style.VerticalAlignment = VerticalAlignment.Center;
  2722. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  2723. style.SetFont(ffont);
  2724. ICellStyle styleborder = book.CreateCellStyle();
  2725. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2726. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2727. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2728. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2729. styleborder.VerticalAlignment = VerticalAlignment.Center;
  2730. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  2731. styleborder.SetFont(ffont);
  2732. string pi_inoutno = "";
  2733. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  2734. ColumnTitle.FontName = "宋体";
  2735. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  2736. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  2737. ColumnTitleStyle.SetFont(ColumnTitle);
  2738. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2739. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2740. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2741. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2742. List<string> NotShowColumn = new List<string>();
  2743. NotShowColumn.Add("ch_level");
  2744. NotShowColumn.Add("pib_id");
  2745. NotShowColumn.Add("chw_itemname1");
  2746. NotShowColumn.Add("chw_itemname2");
  2747. NotShowColumn.Add("chw_itemname3");
  2748. NotShowColumn.Add("pd_ordercode");
  2749. NotShowColumn.Add("pr_size");
  2750. NotShowColumn.Add("me_desc");
  2751. NotShowColumn.Add("pr_orispeccode");
  2752. NotShowColumn.Add("pr_orispeccode1");
  2753. NotShowColumn.Add("pi_title");
  2754. NotShowColumn.Add("pi_chipouttype");
  2755. NotShowColumn.Add("pi_date");
  2756. int ShowColumnCount = 0;
  2757. //展示的内容列
  2758. //设置列的宽度,根据首行的列的内容的长度来设置
  2759. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  2760. {
  2761. for (int j = 0; j < box.Length; j++)
  2762. {
  2763. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  2764. {
  2765. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  2766. {
  2767. DataTable.Columns.RemoveAt(i);
  2768. break;
  2769. }
  2770. }
  2771. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  2772. {
  2773. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  2774. {
  2775. DataTable.Columns.RemoveAt(i);
  2776. break;
  2777. }
  2778. }
  2779. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  2780. {
  2781. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  2782. {
  2783. DataTable.Columns.RemoveAt(i);
  2784. break;
  2785. }
  2786. }
  2787. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  2788. {
  2789. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  2790. {
  2791. DataTable.Columns.RemoveAt(i);
  2792. break;
  2793. }
  2794. }
  2795. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  2796. {
  2797. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  2798. {
  2799. DataTable.Columns.RemoveAt(i);
  2800. break;
  2801. }
  2802. }
  2803. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  2804. {
  2805. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  2806. {
  2807. DataTable.Columns.RemoveAt(i);
  2808. break;
  2809. }
  2810. }
  2811. if (box[j].Name.ToLower() == "ch_yield" && !box[j].Checked)
  2812. {
  2813. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_yield"))
  2814. {
  2815. DataTable.Columns.RemoveAt(i);
  2816. break;
  2817. }
  2818. }
  2819. }
  2820. }
  2821. //获取行数量和列数量
  2822. int rowNum = DataTable.Rows.Count;
  2823. int columnNum = DataTable.Columns.Count;
  2824. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  2825. IRow row = sheet.CreateRow(0);
  2826. //冻结第一行
  2827. sheet.CreateFreezePane(0, 1, 0, 1);
  2828. row.HeightInPoints = RowHeight;
  2829. //固定第一行
  2830. //row.RowStyle.IsLocked=true;
  2831. //给第一行的标签赋值样式和值
  2832. // ffont.FontHeight = 13;
  2833. row.CreateCell(0);
  2834. row.Cells[0].SetCellValue(" " + companyname);
  2835. row.GetCell(0).CellStyle.SetFont((ffont));
  2836. //ffont.FontHeight = 10;
  2837. //开始绘制的Index
  2838. int PaintIndex = 1;
  2839. int sumCount = 0;
  2840. int totalCount = 0;
  2841. switch (Type)
  2842. {
  2843. case "FixRow":
  2844. //清理系统取出来的数据
  2845. BaseUtil.CleanDataTableData(FirstDT);
  2846. //首页参数拼接
  2847. string First_OrderCode = "";
  2848. string First_Prspec = "";
  2849. string First_Batch = "";
  2850. int NumIndex = 0;
  2851. ArrayList<string> First_WID = new ArrayList<string>();
  2852. for (int i = 0; i < rowNum; i++)
  2853. {
  2854. IRow row1 = sheet.CreateRow(PaintIndex);
  2855. PaintIndex = PaintIndex + 1;
  2856. row1.HeightInPoints = RowHeight;
  2857. //不包含的订单号
  2858. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  2859. {
  2860. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  2861. }
  2862. //不包含的物料型号
  2863. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  2864. {
  2865. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  2866. }
  2867. //不包含扩撒批号
  2868. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  2869. {
  2870. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  2871. }
  2872. //不包含Wafer_id
  2873. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  2874. {
  2875. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  2876. }
  2877. if (i / PageSize >= 1 && i % PageSize == 0)
  2878. {
  2879. DataRow dr = FirstDT.NewRow();
  2880. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  2881. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  2882. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  2883. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  2884. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  2885. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  2886. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  2887. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  2888. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  2889. dr["pd_ordercode"] = First_OrderCode;
  2890. dr["pr_orispeccode"] = First_Prspec;
  2891. dr["ch_splitbatch"] = First_Batch;
  2892. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  2893. dr["num"] = PageSize;
  2894. dr["io_qty"] = sumCount;
  2895. FirstDT.Rows.Add(dr);
  2896. First_OrderCode = "";
  2897. First_Prspec = "";
  2898. First_Batch = "";
  2899. First_WID.Clear();
  2900. BoxCode = BoxCode + 1;
  2901. for (int j = 0; j < ShowColumnCount; j++)
  2902. {
  2903. row1.CreateCell(j);
  2904. if (j == 0)
  2905. {
  2906. row1.Cells[j].SetCellValue(批小计);
  2907. }
  2908. else if (j == ShowPieceIndex)
  2909. {
  2910. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i) + 片);
  2911. row1.Cells[j].CellStyle = styleborder;
  2912. }
  2913. else if (j == ShowCountIndex)
  2914. {
  2915. row1.Cells[j].SetCellValue(sumCount);
  2916. }
  2917. else if (j == ShowBoxIndex - 4)
  2918. {
  2919. row1.Cells[j].SetCellValue(LastBox);
  2920. row1.Cells[j].CellStyle = styleborder;
  2921. }
  2922. row1.Cells[j].CellStyle = styleborder;
  2923. }
  2924. row1 = sheet.CreateRow(PaintIndex);
  2925. PaintIndex = PaintIndex + 1;
  2926. for (int j = 0; j < ShowColumnCount; j++)
  2927. {
  2928. row1.CreateCell(j);
  2929. if (j == 0)
  2930. {
  2931. row1.Cells[j].SetCellValue(小计);
  2932. }
  2933. else if (j == ShowPieceIndex)
  2934. {
  2935. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i) + 片);
  2936. }
  2937. else if (j == ShowCountIndex)
  2938. {
  2939. row1.Cells[j].SetCellValue(sumCount);
  2940. }
  2941. else if (j == ShowBoxIndex - 4)
  2942. {
  2943. row1.Cells[j].SetCellValue(LastBox);
  2944. row1.Cells[j].CellStyle = styleborder;
  2945. }
  2946. row1.Cells[j].CellStyle = styleborder;
  2947. }
  2948. sumCount = 0;
  2949. row1 = sheet.CreateRow(PaintIndex);
  2950. sheet.SetRowBreak(PaintIndex - 1);
  2951. sheet.Footer.Center = "第&P页,共&N页";
  2952. PaintIndex = PaintIndex + 1;
  2953. }
  2954. //每次到了页数开始分页
  2955. if (i % PageSize == 0 || i == rowNum - 1)
  2956. {
  2957. //第一行添加客户信息 rownum只有一行的情
  2958. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  2959. {
  2960. for (int j = 0; j < columnNum - 3; j++)
  2961. {
  2962. if (j == 0)
  2963. {
  2964. row1.CreateCell(j);
  2965. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  2966. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  2967. }
  2968. else if (j == ShowDataIndex)
  2969. {
  2970. row1.CreateCell(j);
  2971. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  2972. }
  2973. else
  2974. {
  2975. row1.CreateCell(j);
  2976. }
  2977. row1.GetCell(j).CellStyle = style;
  2978. }
  2979. row1 = sheet.CreateRow(PaintIndex);
  2980. PaintIndex = PaintIndex + 1;
  2981. //第二行添加型号
  2982. for (int j = 0; j < columnNum - 3; j++)
  2983. {
  2984. if (j == 0)
  2985. {
  2986. row1.CreateCell(j);
  2987. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString()
  2988. + "_(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2989. }
  2990. else if (j == ShowSizeIndex)
  2991. {
  2992. row1.CreateCell(j);
  2993. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  2994. }
  2995. else if (j == ShowDataIndex)
  2996. {
  2997. row1.CreateCell(j);
  2998. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  2999. }
  3000. else
  3001. {
  3002. row1.CreateCell(j);
  3003. }
  3004. row1.GetCell(j).CellStyle = style;
  3005. }
  3006. //添加列名
  3007. row1 = sheet.CreateRow(PaintIndex);
  3008. PaintIndex = PaintIndex + 1;
  3009. //计数列所在的索引
  3010. int showcount = 0;
  3011. for (int j = 4; j < columnNum; j++)
  3012. {
  3013. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  3014. {
  3015. showcount = showcount + 1;
  3016. row1.CreateCell(j - 4);
  3017. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3018. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  3019. }
  3020. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  3021. {
  3022. showcount = showcount + 1;
  3023. row1.CreateCell(j - 4);
  3024. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3025. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  3026. }
  3027. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  3028. {
  3029. showcount = showcount + 1;
  3030. row1.CreateCell(j - 4);
  3031. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3032. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  3033. }
  3034. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3035. {
  3036. }
  3037. else
  3038. {
  3039. showcount = showcount + 1;
  3040. row1.CreateCell(j - 4);
  3041. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3042. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  3043. }
  3044. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  3045. {
  3046. ShowBoxIndex = j;
  3047. }
  3048. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  3049. {
  3050. NumIndex = j;
  3051. if (ShowCountIndex == NumIndex - 4)
  3052. {
  3053. ShowCountIndex = ShowCountIndex + 1;
  3054. }
  3055. }
  3056. }
  3057. ShowColumnCount = showcount;
  3058. row1 = sheet.CreateRow(PaintIndex);
  3059. PaintIndex = PaintIndex + 1;
  3060. }
  3061. }
  3062. //添加数据内容
  3063. for (int j = 4; j < columnNum; j++)
  3064. {
  3065. string Data = DataTable.Rows[i][j].ToString();
  3066. row1.CreateCell(j - 4);
  3067. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3068. {
  3069. }
  3070. else
  3071. {
  3072. double Num = 0;
  3073. if (double.TryParse(Data, out Num))
  3074. {
  3075. row1.Cells[j - 4].SetCellValue(Num);
  3076. }
  3077. else
  3078. {
  3079. row1.Cells[j - 4].SetCellValue(Data);
  3080. }
  3081. row1.GetCell(j - 4).CellStyle = styleborder;
  3082. }
  3083. if (DataTable.Columns[j].ColumnName == "io_qty")
  3084. {
  3085. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3086. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  3087. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  3088. row1.Cells[j - 4].CellStyle = styleborder;
  3089. }
  3090. if (DataTable.Columns[j].ColumnName == "rownum")
  3091. {
  3092. row1.Cells[j - 4].SetCellValue(i + 1);
  3093. row1.Cells[j - 4].CellStyle = styleborder;
  3094. }
  3095. if (DataTable.Columns[j].ColumnName == "ch_code")
  3096. {
  3097. sheet.AutoSizeColumn(j - 4);
  3098. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  3099. }
  3100. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  3101. {
  3102. LastBox = Data;
  3103. }
  3104. }
  3105. //固定行号分组的时候自动拼接新的DataTable
  3106. if (i == rowNum - 1)
  3107. {
  3108. DataRow dr = FirstDT.NewRow();
  3109. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  3110. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  3111. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  3112. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  3113. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  3114. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  3115. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  3116. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  3117. dr["pd_ordercode"] = First_OrderCode;
  3118. dr["pr_orispeccode"] = First_Prspec;
  3119. dr["ch_splitbatch"] = First_Batch;
  3120. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  3121. dr["num"] = (i % PageSize) + 1;
  3122. dr["io_qty"] = sumCount;
  3123. FirstDT.Rows.Add(dr);
  3124. row1 = sheet.CreateRow(PaintIndex);
  3125. PaintIndex = PaintIndex + 1;
  3126. for (int j = 0; j < ShowColumnCount; j++)
  3127. {
  3128. row1.CreateCell(j);
  3129. if (j == 0)
  3130. {
  3131. row1.Cells[j].SetCellValue(批小计);
  3132. }
  3133. else if (j == ShowPieceIndex)
  3134. {
  3135. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize == 0 ? PageSize : (rowNum % PageSize)) + 片);
  3136. row1.Cells[j].CellStyle = styleborder;
  3137. }
  3138. else if (j == ShowBoxIndex - 4)
  3139. {
  3140. row1.Cells[j].SetCellValue(LastBox);
  3141. row1.Cells[j].CellStyle = styleborder;
  3142. }
  3143. else if (j == ShowCountIndex)
  3144. {
  3145. row1.Cells[j].SetCellValue(sumCount);
  3146. }
  3147. row1.Cells[j].CellStyle = styleborder;
  3148. }
  3149. row1 = sheet.CreateRow(PaintIndex);
  3150. PaintIndex = PaintIndex + 1;
  3151. for (int j = 0; j < ShowColumnCount; j++)
  3152. {
  3153. row1.CreateCell(j);
  3154. if (j == 0)
  3155. {
  3156. row1.Cells[j].SetCellValue(小计);
  3157. }
  3158. else if (j == ShowPieceIndex)
  3159. {
  3160. row1.Cells[ShowPieceIndex].SetCellValue(rowNum % PageSize + 片);
  3161. row1.Cells[j].CellStyle = styleborder;
  3162. }
  3163. else if (j == ShowBoxIndex - 4)
  3164. {
  3165. row1.Cells[j].SetCellValue(LastBox);
  3166. row1.Cells[j].CellStyle = styleborder;
  3167. }
  3168. else if (j == ShowCountIndex)
  3169. {
  3170. row1.Cells[j].SetCellValue(sumCount);
  3171. }
  3172. row1.Cells[j].CellStyle = styleborder;
  3173. }
  3174. row1 = sheet.CreateRow(PaintIndex);
  3175. for (int j = 0; j < columnNum - 3; j++)
  3176. {
  3177. if (j == 0)
  3178. {
  3179. row1.CreateCell(j);
  3180. row1.Cells[j].SetCellValue("备注");
  3181. }
  3182. else if (j == ShowCountIndex)
  3183. {
  3184. row1.CreateCell(j);
  3185. row1.Cells[j].SetCellValue(totalCount);
  3186. }
  3187. else if (j == ShowRemarkPiece)
  3188. {
  3189. row1.CreateCell(j);
  3190. row1.Cells[j].SetCellValue(rowNum + 片);
  3191. }
  3192. else
  3193. {
  3194. row1.CreateCell(j);
  3195. }
  3196. row1.Cells[j].CellStyle = style;
  3197. }
  3198. sheet.SetRowBreak(PaintIndex);
  3199. sheet.Footer.Center = "第&P页,共&N页";
  3200. PaintIndex = PaintIndex + 1;
  3201. }
  3202. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3203. pib_outboxcode1.Add(BoxCode.ToString());
  3204. }
  3205. break;
  3206. case "BatchCode":
  3207. string LastBatchCode = "";
  3208. int PageNum = 0;
  3209. for (int i = 0; i < rowNum; i++)
  3210. {
  3211. IRow row1 = sheet.CreateRow(PaintIndex);
  3212. PaintIndex = PaintIndex + 1;
  3213. row1.HeightInPoints = RowHeight;
  3214. //如果批号不相等的时候
  3215. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  3216. {
  3217. BoxCode = BoxCode + 1;
  3218. for (int j = 0; j < ShowColumnCount; j++)
  3219. {
  3220. row1.CreateCell(j);
  3221. if (j == 0)
  3222. {
  3223. row1.Cells[j].SetCellValue(批小计);
  3224. row1.Cells[j].CellStyle = styleborder;
  3225. }
  3226. else if (j == ShowPieceIndex)
  3227. {
  3228. row1.Cells[ShowPieceIndex].SetCellValue(PageNum - 1 + 片);
  3229. row1.Cells[j].CellStyle = styleborder;
  3230. }
  3231. else if (j == ShowCountIndex)
  3232. {
  3233. row1.Cells[j].SetCellValue(sumCount);
  3234. row1.Cells[j].CellStyle = styleborder;
  3235. }
  3236. else if (j == ShowBoxIndex - 4)
  3237. {
  3238. row1.Cells[j].SetCellValue(LastBox);
  3239. row1.Cells[j].CellStyle = styleborder;
  3240. }
  3241. else
  3242. {
  3243. row1.Cells[j].CellStyle = styleborder;
  3244. }
  3245. }
  3246. row1 = sheet.CreateRow(PaintIndex);
  3247. PaintIndex = PaintIndex + 1;
  3248. for (int j = 0; j < ShowColumnCount; j++)
  3249. {
  3250. row1.CreateCell(j);
  3251. if (j == 0)
  3252. {
  3253. row1.Cells[j].SetCellValue(小计);
  3254. row1.Cells[j].CellStyle = styleborder;
  3255. }
  3256. else if (j == ShowPieceIndex)
  3257. {
  3258. row1.Cells[ShowPieceIndex].SetCellValue(PageNum - 1 + 片);
  3259. row1.Cells[j].CellStyle = styleborder;
  3260. }
  3261. else if (j == ShowCountIndex)
  3262. {
  3263. row1.Cells[j].SetCellValue(sumCount);
  3264. row1.Cells[j].CellStyle = styleborder;
  3265. }
  3266. else if (j == ShowBoxIndex - 4)
  3267. {
  3268. row1.Cells[j].SetCellValue(LastBox);
  3269. row1.Cells[j].CellStyle = styleborder;
  3270. }
  3271. else
  3272. {
  3273. row1.Cells[j].CellStyle = styleborder;
  3274. }
  3275. }
  3276. sumCount = 0;
  3277. row1 = sheet.CreateRow(PaintIndex);
  3278. sheet.SetRowBreak(PaintIndex - 1);
  3279. sheet.Footer.Center = "第&P页,共&N页";
  3280. PaintIndex = PaintIndex + 1;
  3281. PageNum = 0;
  3282. }
  3283. //每次到了页数开始分页
  3284. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()) || i == rowNum - 1)
  3285. {
  3286. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  3287. //第一行添加客户信息
  3288. //if (i != rowNum - 1)
  3289. {
  3290. for (int j = 0; j < columnNum - 3; j++)
  3291. {
  3292. if (j == 0)
  3293. {
  3294. row1.CreateCell(j);
  3295. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  3296. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  3297. }
  3298. else if (j == ShowDataIndex)
  3299. {
  3300. row1.CreateCell(j);
  3301. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  3302. }
  3303. else
  3304. {
  3305. row1.CreateCell(j);
  3306. }
  3307. row1.GetCell(j).CellStyle = style;
  3308. }
  3309. row1 = sheet.CreateRow(PaintIndex);
  3310. PaintIndex = PaintIndex + 1;
  3311. //第二行添加型号
  3312. for (int j = 0; j < columnNum - 3; j++)
  3313. {
  3314. if (j == 0)
  3315. {
  3316. row1.CreateCell(j);
  3317. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  3318. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  3319. }
  3320. else if (j == ShowSizeIndex)
  3321. {
  3322. row1.CreateCell(j);
  3323. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  3324. }
  3325. else if (j == ShowDataIndex)
  3326. {
  3327. row1.CreateCell(j);
  3328. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  3329. }
  3330. else
  3331. {
  3332. row1.CreateCell(j);
  3333. }
  3334. row1.GetCell(j).CellStyle = style;
  3335. }
  3336. //添加列名
  3337. row1 = sheet.CreateRow(PaintIndex);
  3338. PaintIndex = PaintIndex + 1;
  3339. int showcount = 0;
  3340. for (int j = 4; j < columnNum; j++)
  3341. {
  3342. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  3343. {
  3344. showcount = showcount + 1;
  3345. row1.CreateCell(j - 4);
  3346. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3347. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  3348. }
  3349. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  3350. {
  3351. showcount = showcount + 1;
  3352. row1.CreateCell(j - 4);
  3353. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3354. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  3355. }
  3356. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  3357. {
  3358. showcount = showcount + 1;
  3359. row1.CreateCell(j - 4);
  3360. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3361. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  3362. }
  3363. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3364. {
  3365. }
  3366. else
  3367. {
  3368. showcount = showcount + 1;
  3369. row1.CreateCell(j - 4);
  3370. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3371. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  3372. }
  3373. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  3374. {
  3375. ShowBoxIndex = j;
  3376. }
  3377. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  3378. {
  3379. NumIndex = j;
  3380. if (ShowCountIndex == NumIndex - 4)
  3381. {
  3382. ShowCountIndex = ShowCountIndex + 1;
  3383. }
  3384. }
  3385. }
  3386. ShowColumnCount = showcount;
  3387. row1 = sheet.CreateRow(PaintIndex);
  3388. PaintIndex = PaintIndex + 1;
  3389. }
  3390. }
  3391. //添加数据内容
  3392. for (int j = 4; j < columnNum; j++)
  3393. {
  3394. string Data = DataTable.Rows[i][j].ToString();
  3395. row1.CreateCell(j - 4);
  3396. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3397. {
  3398. }
  3399. else
  3400. {
  3401. double Num = 0;
  3402. if (double.TryParse(Data, out Num))
  3403. {
  3404. row1.Cells[j - 4].SetCellValue(Num);
  3405. }
  3406. else
  3407. {
  3408. row1.Cells[j - 4].SetCellValue(Data);
  3409. }
  3410. row1.Cells[j - 4].CellStyle = styleborder;
  3411. }
  3412. if (DataTable.Columns[j].ColumnName == "io_qty")
  3413. {
  3414. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3415. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  3416. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  3417. }
  3418. if (DataTable.Columns[j].ColumnName == "rownum")
  3419. {
  3420. row1.Cells[j - 4].SetCellValue(i + 1);
  3421. row1.Cells[j - 4].CellStyle = styleborder;
  3422. }
  3423. if (DataTable.Columns[j].ColumnName == "ch_code")
  3424. {
  3425. sheet.AutoSizeColumn(j - 4);
  3426. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  3427. }
  3428. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  3429. {
  3430. LastBox = Data;
  3431. }
  3432. }
  3433. if (i == rowNum - 1)
  3434. {
  3435. row1 = sheet.CreateRow(PaintIndex);
  3436. PaintIndex = PaintIndex + 1;
  3437. for (int j = 0; j < ShowColumnCount; j++)
  3438. {
  3439. row1.CreateCell(j);
  3440. if (j == 0)
  3441. {
  3442. row1.Cells[j].SetCellValue(批小计);
  3443. row1.Cells[j].CellStyle = styleborder;
  3444. }
  3445. else if (j == ShowPieceIndex)
  3446. {
  3447. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  3448. row1.Cells[j].CellStyle = styleborder;
  3449. }
  3450. else if (j == ShowCountIndex)
  3451. {
  3452. row1.Cells[j].SetCellValue(sumCount);
  3453. row1.Cells[j].CellStyle = styleborder;
  3454. }
  3455. else
  3456. {
  3457. row1.Cells[j].CellStyle = styleborder;
  3458. }
  3459. }
  3460. row1 = sheet.CreateRow(PaintIndex);
  3461. PaintIndex = PaintIndex + 1;
  3462. for (int j = 0; j < ShowColumnCount; j++)
  3463. {
  3464. row1.CreateCell(j);
  3465. if (j == 0)
  3466. {
  3467. row1.Cells[j].SetCellValue(小计);
  3468. row1.Cells[j].CellStyle = styleborder;
  3469. }
  3470. else if (j == ShowPieceIndex)
  3471. {
  3472. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  3473. row1.Cells[j].CellStyle = styleborder;
  3474. }
  3475. else if (j == ShowCountIndex)
  3476. {
  3477. row1.Cells[j].SetCellValue(sumCount);
  3478. row1.Cells[j].CellStyle = styleborder;
  3479. }
  3480. else
  3481. {
  3482. row1.Cells[j].CellStyle = styleborder;
  3483. }
  3484. }
  3485. //创建备注内容
  3486. row1 = sheet.CreateRow(PaintIndex);
  3487. for (int j = 0; j < columnNum - 3; j++)
  3488. {
  3489. if (j == 0)
  3490. {
  3491. row1.CreateCell(j);
  3492. row1.Cells[j].SetCellValue("备注");
  3493. }
  3494. else if (j == ShowCountIndex)
  3495. {
  3496. row1.CreateCell(j);
  3497. row1.Cells[j].SetCellValue(totalCount);
  3498. }
  3499. else if (j == ShowRemarkPiece)
  3500. {
  3501. row1.CreateCell(j);
  3502. row1.Cells[j].SetCellValue(rowNum + 片);
  3503. }
  3504. else
  3505. {
  3506. row1.CreateCell(j);
  3507. }
  3508. row1.Cells[j].CellStyle = style;
  3509. }
  3510. sheet.SetRowBreak(PaintIndex);
  3511. sheet.Footer.Center = "第&P页,共&N页";
  3512. PaintIndex = PaintIndex + 1;
  3513. PageNum = 0;
  3514. }
  3515. PageNum = PageNum + 1;
  3516. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3517. pib_outboxcode1.Add(BoxCode.ToString());
  3518. }
  3519. break;
  3520. case "BoxCode":
  3521. string LastBoxCode = "";
  3522. int PageNum1 = 0;
  3523. for (int i = 0; i < rowNum; i++)
  3524. {
  3525. IRow row1 = sheet.CreateRow(PaintIndex);
  3526. PaintIndex = PaintIndex + 1;
  3527. row1.HeightInPoints = RowHeight;
  3528. //如果批号不相等的时候
  3529. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  3530. {
  3531. BoxCode = BoxCode + 1;
  3532. for (int j = 0; j < ShowColumnCount; j++)
  3533. {
  3534. row1.CreateCell(j);
  3535. if (j == 0)
  3536. {
  3537. row1.Cells[j].SetCellValue(批小计);
  3538. row1.Cells[j].CellStyle = styleborder;
  3539. }
  3540. else if (j == ShowPieceIndex)
  3541. {
  3542. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3543. row1.Cells[j].CellStyle = styleborder;
  3544. }
  3545. else if (j == ShowCountIndex)
  3546. {
  3547. row1.Cells[j].SetCellValue(sumCount);
  3548. row1.Cells[j].CellStyle = styleborder;
  3549. }
  3550. else if (j == ShowBoxIndex - 4)
  3551. {
  3552. row1.Cells[j].SetCellValue(LastBox);
  3553. row1.Cells[j].CellStyle = styleborder;
  3554. }
  3555. else
  3556. {
  3557. row1.Cells[j].CellStyle = styleborder;
  3558. }
  3559. }
  3560. row1 = sheet.CreateRow(PaintIndex);
  3561. PaintIndex = PaintIndex + 1;
  3562. for (int j = 0; j < ShowColumnCount; j++)
  3563. {
  3564. row1.CreateCell(j);
  3565. if (j == 0)
  3566. {
  3567. row1.Cells[j].SetCellValue(小计);
  3568. row1.Cells[j].CellStyle = styleborder;
  3569. }
  3570. else if (j == ShowPieceIndex)
  3571. {
  3572. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3573. row1.Cells[j].CellStyle = styleborder;
  3574. }
  3575. else if (j == ShowCountIndex)
  3576. {
  3577. row1.Cells[j].SetCellValue(sumCount);
  3578. row1.Cells[j].CellStyle = styleborder;
  3579. }
  3580. else if (j == ShowBoxIndex - 4)
  3581. {
  3582. row1.Cells[j].SetCellValue(LastBox);
  3583. row1.Cells[j].CellStyle = styleborder;
  3584. }
  3585. else
  3586. {
  3587. row1.Cells[j].CellStyle = styleborder;
  3588. }
  3589. }
  3590. sumCount = 0;
  3591. row1 = sheet.CreateRow(PaintIndex);
  3592. sheet.SetRowBreak(PaintIndex - 1);
  3593. sheet.Footer.Center = "第&P页,共&N页";
  3594. PaintIndex = PaintIndex + 1;
  3595. PageNum1 = 0;
  3596. }
  3597. //每次到了页数开始分页
  3598. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  3599. {
  3600. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  3601. //第一行添加客户信息
  3602. //if (i != rowNum - 1)
  3603. {
  3604. for (int j = 0; j < columnNum - 3; j++)
  3605. {
  3606. if (j == 0)
  3607. {
  3608. row1.CreateCell(j);
  3609. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  3610. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  3611. }
  3612. else if (j == ShowDataIndex)
  3613. {
  3614. row1.CreateCell(j);
  3615. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  3616. }
  3617. else
  3618. {
  3619. row1.CreateCell(j);
  3620. }
  3621. row1.GetCell(j).CellStyle = style;
  3622. }
  3623. row1 = sheet.CreateRow(PaintIndex);
  3624. PaintIndex = PaintIndex + 1;
  3625. //第二行添加型号
  3626. for (int j = 0; j < columnNum - 3; j++)
  3627. {
  3628. if (j == 0)
  3629. {
  3630. row1.CreateCell(j);
  3631. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  3632. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  3633. }
  3634. else if (j == ShowSizeIndex)
  3635. {
  3636. row1.CreateCell(j);
  3637. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  3638. }
  3639. else if (j == ShowDataIndex)
  3640. {
  3641. row1.CreateCell(j);
  3642. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  3643. }
  3644. else
  3645. {
  3646. row1.CreateCell(j);
  3647. }
  3648. }
  3649. //添加列名
  3650. row1 = sheet.CreateRow(PaintIndex);
  3651. PaintIndex = PaintIndex + 1;
  3652. int showcount = 0;
  3653. for (int j = 4; j < columnNum; j++)
  3654. {
  3655. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  3656. {
  3657. showcount = showcount + 1;
  3658. row1.CreateCell(j - 4);
  3659. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3660. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  3661. }
  3662. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  3663. {
  3664. showcount = showcount + 1;
  3665. row1.CreateCell(j - 4);
  3666. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3667. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  3668. }
  3669. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  3670. {
  3671. showcount = showcount + 1;
  3672. row1.CreateCell(j - 4);
  3673. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3674. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  3675. }
  3676. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3677. {
  3678. }
  3679. else
  3680. {
  3681. showcount = showcount + 1;
  3682. row1.CreateCell(j - 4);
  3683. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3684. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  3685. }
  3686. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  3687. {
  3688. ShowBoxIndex = j;
  3689. }
  3690. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  3691. {
  3692. NumIndex = j;
  3693. if (ShowCountIndex == NumIndex - 4)
  3694. {
  3695. ShowCountIndex = ShowCountIndex + 1;
  3696. }
  3697. }
  3698. }
  3699. ShowColumnCount = showcount;
  3700. row1 = sheet.CreateRow(PaintIndex);
  3701. PaintIndex = PaintIndex + 1;
  3702. }
  3703. }
  3704. //添加数据内容
  3705. for (int j = 4; j < columnNum; j++)
  3706. {
  3707. string Data = DataTable.Rows[i][j].ToString();
  3708. row1.CreateCell(j - 4);
  3709. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3710. {
  3711. }
  3712. else
  3713. {
  3714. double Num = 0;
  3715. if (double.TryParse(Data, out Num))
  3716. {
  3717. row1.Cells[j - 4].SetCellValue(Num);
  3718. }
  3719. else
  3720. {
  3721. row1.Cells[j - 4].SetCellValue(Data);
  3722. }
  3723. row1.Cells[j - 4].CellStyle = styleborder;
  3724. }
  3725. if (DataTable.Columns[j].ColumnName == "io_qty")
  3726. {
  3727. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3728. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  3729. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  3730. row1.Cells[j - 4].CellStyle = styleborder;
  3731. }
  3732. if (DataTable.Columns[j].ColumnName == "rownum")
  3733. {
  3734. row1.Cells[j - 4].SetCellValue(i + 1);
  3735. row1.Cells[j - 4].CellStyle = styleborder;
  3736. }
  3737. if (DataTable.Columns[j].ColumnName == "ch_code")
  3738. {
  3739. sheet.AutoSizeColumn(j - 4);
  3740. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  3741. }
  3742. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  3743. {
  3744. LastBox = Data;
  3745. }
  3746. }
  3747. if (i == rowNum - 1)
  3748. {
  3749. PageNum1 = PageNum1 + 1;
  3750. row1 = sheet.CreateRow(PaintIndex);
  3751. PaintIndex = PaintIndex + 1;
  3752. for (int j = 0; j < ShowColumnCount; j++)
  3753. {
  3754. row1.CreateCell(j);
  3755. if (j == 0)
  3756. {
  3757. row1.Cells[j].SetCellValue(批小计);
  3758. row1.Cells[j].CellStyle = styleborder;
  3759. }
  3760. else if (j == ShowPieceIndex)
  3761. {
  3762. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3763. row1.Cells[j].CellStyle = styleborder;
  3764. }
  3765. else if (j == ShowCountIndex)
  3766. {
  3767. row1.Cells[j].SetCellValue(sumCount);
  3768. row1.Cells[j].CellStyle = styleborder;
  3769. }
  3770. else if (j == ShowBoxIndex - 4)
  3771. {
  3772. row1.Cells[j].SetCellValue(LastBox);
  3773. row1.Cells[j].CellStyle = styleborder;
  3774. }
  3775. else
  3776. {
  3777. row1.Cells[j].CellStyle = styleborder;
  3778. }
  3779. }
  3780. row1 = sheet.CreateRow(PaintIndex);
  3781. PaintIndex = PaintIndex + 1;
  3782. for (int j = 0; j < ShowColumnCount; j++)
  3783. {
  3784. row1.CreateCell(j);
  3785. if (j == 0)
  3786. {
  3787. row1.Cells[j].SetCellValue(小计);
  3788. row1.Cells[j].CellStyle = styleborder;
  3789. }
  3790. else if (j == ShowPieceIndex)
  3791. {
  3792. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3793. row1.Cells[j].CellStyle = styleborder;
  3794. }
  3795. else if (j == ShowCountIndex)
  3796. {
  3797. row1.Cells[j].SetCellValue(sumCount);
  3798. row1.Cells[j].CellStyle = styleborder;
  3799. }
  3800. else if (j == ShowBoxIndex - 4)
  3801. {
  3802. row1.Cells[j].SetCellValue(LastBox);
  3803. row1.Cells[j].CellStyle = styleborder;
  3804. }
  3805. else
  3806. {
  3807. row1.Cells[j].CellStyle = styleborder;
  3808. }
  3809. }
  3810. row1 = sheet.CreateRow(PaintIndex);
  3811. for (int j = 0; j < columnNum - 3; j++)
  3812. {
  3813. if (j == 0)
  3814. {
  3815. row1.CreateCell(j);
  3816. row1.Cells[j].SetCellValue("备注");
  3817. }
  3818. else if (j == ShowCountIndex)
  3819. {
  3820. row1.CreateCell(j);
  3821. row1.Cells[j].SetCellValue(totalCount);
  3822. }
  3823. else if (j == ShowRemarkPiece)
  3824. {
  3825. row1.CreateCell(j);
  3826. row1.Cells[j].SetCellValue(rowNum + 片);
  3827. }
  3828. else
  3829. {
  3830. row1.CreateCell(j);
  3831. }
  3832. row1.Cells[j].CellStyle = style;
  3833. }
  3834. sheet.SetRowBreak(PaintIndex);
  3835. sheet.Footer.Center = "第&P页,共&N页";
  3836. PaintIndex = PaintIndex + 1;
  3837. PageNum1 = 0;
  3838. }
  3839. PageNum1 = PageNum1 + 1;
  3840. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3841. pib_outboxcode1.Add(BoxCode.ToString());
  3842. }
  3843. break;
  3844. case "BoxSplit":
  3845. string LastBoxCode1 = "";
  3846. int PageNum2 = 0;
  3847. string LastBatch = "";
  3848. int MidCount = 0;
  3849. int SerialNum = 1;
  3850. for (int i = 0; i < rowNum; i++)
  3851. {
  3852. IRow row1 = sheet.CreateRow(PaintIndex);
  3853. PaintIndex = PaintIndex + 1;
  3854. row1.HeightInPoints = RowHeight;
  3855. //如果批号不相等的时候
  3856. if (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["CH_PBCODE"].ToString())
  3857. {
  3858. BoxCode = BoxCode + 1;
  3859. for (int j = 0; j < ShowColumnCount; j++)
  3860. {
  3861. row1.CreateCell(j);
  3862. if (j == 0)
  3863. {
  3864. row1.Cells[j].SetCellValue(批小计);
  3865. row1.Cells[j].CellStyle = styleborder;
  3866. }
  3867. else if (j == ShowPieceIndex)
  3868. {
  3869. row1.Cells[ShowPieceIndex].SetCellValue(PageNum2 + 片);
  3870. row1.Cells[j].CellStyle = styleborder;
  3871. }
  3872. else if (j == ShowCountIndex)
  3873. {
  3874. row1.Cells[j].SetCellValue(sumCount);
  3875. row1.Cells[j].CellStyle = styleborder;
  3876. }
  3877. else if (j == ShowBoxIndex - 4)
  3878. {
  3879. row1.Cells[j].SetCellValue(LastBox);
  3880. row1.Cells[j].CellStyle = styleborder;
  3881. }
  3882. else
  3883. {
  3884. row1.Cells[j].CellStyle = styleborder;
  3885. }
  3886. }
  3887. row1 = sheet.CreateRow(PaintIndex);
  3888. PaintIndex = PaintIndex + 1;
  3889. for (int j = 0; j < ShowColumnCount; j++)
  3890. {
  3891. row1.CreateCell(j);
  3892. if (j == 0)
  3893. {
  3894. row1.Cells[j].SetCellValue(小计);
  3895. row1.Cells[j].CellStyle = styleborder;
  3896. }
  3897. else if (j == ShowPieceIndex)
  3898. {
  3899. row1.Cells[ShowPieceIndex].SetCellValue(PageNum2 + 片);
  3900. row1.Cells[j].CellStyle = styleborder;
  3901. }
  3902. else if (j == ShowCountIndex)
  3903. {
  3904. row1.Cells[j].SetCellValue(sumCount);
  3905. row1.Cells[j].CellStyle = styleborder;
  3906. }
  3907. else if (j == ShowBoxIndex - 4)
  3908. {
  3909. row1.Cells[j].SetCellValue(LastBox);
  3910. row1.Cells[j].CellStyle = styleborder;
  3911. }
  3912. else
  3913. {
  3914. row1.Cells[j].CellStyle = styleborder;
  3915. }
  3916. }
  3917. sumCount = 0;
  3918. row1 = sheet.CreateRow(PaintIndex);
  3919. sheet.SetRowBreak(PaintIndex - 1);
  3920. sheet.Footer.Center = "第&P页,共&N页";
  3921. PaintIndex = PaintIndex + 1;
  3922. PageNum2 = 0;
  3923. }
  3924. if (LastBatch == "" || (LastBatch != "" && LastBatch != DataTable.Rows[i]["ch_splitbatch"].ToString()))
  3925. {
  3926. LastBatch = DataTable.Rows[i]["ch_splitbatch"].ToString();
  3927. for (int j = 0; j < ShowColumnCount; j++)
  3928. {
  3929. if (j == 0)
  3930. {
  3931. row1.CreateCell(j).SetCellValue(SerialNum - 1);
  3932. }
  3933. else if (j == 1)
  3934. {
  3935. row1.CreateCell(j).SetCellValue("批小计");
  3936. }
  3937. else if (j == 2)
  3938. {
  3939. row1.CreateCell(j).SetCellValue(MidCount);
  3940. }
  3941. else if (j == ShowBoxIndex - 4)
  3942. {
  3943. row1.CreateCell(j).SetCellValue(LastBox);
  3944. }
  3945. else
  3946. {
  3947. row1.CreateCell(j);
  3948. }
  3949. row1.Cells[j].CellStyle = styleborder;
  3950. }
  3951. SerialNum = 1;
  3952. MidCount = 0;
  3953. row1 = sheet.CreateRow(PaintIndex);
  3954. PaintIndex = PaintIndex + 1;
  3955. }
  3956. //每次到了页数开始分页
  3957. if (LastBoxCode1 == "" || (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["ch_pbcode"].ToString())))
  3958. {
  3959. LastBoxCode1 = DataTable.Rows[i]["CH_PBCODE"].ToString();
  3960. //第一行添加客户信息
  3961. //if (i != rowNum - 1)
  3962. {
  3963. for (int j = 0; j < columnNum - 3; j++)
  3964. {
  3965. if (j == 0)
  3966. {
  3967. row1.CreateCell(j);
  3968. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  3969. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  3970. }
  3971. else if (j == ShowDataIndex)
  3972. {
  3973. row1.CreateCell(j);
  3974. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  3975. }
  3976. else
  3977. {
  3978. row1.CreateCell(j);
  3979. }
  3980. row1.GetCell(j).CellStyle = style;
  3981. }
  3982. row1 = sheet.CreateRow(PaintIndex);
  3983. PaintIndex = PaintIndex + 1;
  3984. //第二行添加型号
  3985. for (int j = 0; j < columnNum - 3; j++)
  3986. {
  3987. if (j == 0)
  3988. {
  3989. row1.CreateCell(j);
  3990. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  3991. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  3992. }
  3993. else if (j == ShowSizeIndex)
  3994. {
  3995. row1.CreateCell(j);
  3996. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  3997. }
  3998. else if (j == ShowDataIndex)
  3999. {
  4000. row1.CreateCell(j);
  4001. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  4002. }
  4003. else
  4004. {
  4005. row1.CreateCell(j);
  4006. }
  4007. }
  4008. //添加列名
  4009. row1 = sheet.CreateRow(PaintIndex);
  4010. PaintIndex = PaintIndex + 1;
  4011. int showcount = 0;
  4012. for (int j = 4; j < columnNum; j++)
  4013. {
  4014. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  4015. {
  4016. showcount = showcount + 1;
  4017. row1.CreateCell(j - 4);
  4018. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4019. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  4020. }
  4021. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  4022. {
  4023. showcount = showcount + 1;
  4024. row1.CreateCell(j - 4);
  4025. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4026. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  4027. }
  4028. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  4029. {
  4030. showcount = showcount + 1;
  4031. row1.CreateCell(j - 4);
  4032. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4033. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  4034. }
  4035. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  4036. {
  4037. }
  4038. else
  4039. {
  4040. showcount = showcount + 1;
  4041. row1.CreateCell(j - 4);
  4042. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4043. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  4044. }
  4045. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  4046. {
  4047. ShowBoxIndex = j;
  4048. }
  4049. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  4050. {
  4051. NumIndex = j;
  4052. if (ShowCountIndex == NumIndex - 4)
  4053. {
  4054. ShowCountIndex = ShowCountIndex + 1;
  4055. }
  4056. }
  4057. }
  4058. ShowColumnCount = showcount;
  4059. row1 = sheet.CreateRow(PaintIndex);
  4060. PaintIndex = PaintIndex + 1;
  4061. }
  4062. }
  4063. //添加数据内容
  4064. for (int j = 4; j < columnNum; j++)
  4065. {
  4066. string Data = DataTable.Rows[i][j].ToString();
  4067. row1.CreateCell(j - 4);
  4068. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  4069. {
  4070. }
  4071. else
  4072. {
  4073. row1.Cells[j - 4].SetCellValue(Data);
  4074. row1.GetCell(j - 4).CellStyle = styleborder;
  4075. }
  4076. if (DataTable.Columns[j].ColumnName == "io_qty")
  4077. {
  4078. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  4079. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  4080. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  4081. MidCount += int.Parse(DataTable.Rows[i][j].ToString());
  4082. }
  4083. if (DataTable.Columns[j].ColumnName == "rownum")
  4084. {
  4085. row1.Cells[j - 4].SetCellValue(SerialNum);
  4086. }
  4087. if (DataTable.Columns[j].ColumnName == "ch_code")
  4088. {
  4089. sheet.AutoSizeColumn(j - 4);
  4090. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  4091. }
  4092. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  4093. {
  4094. LastBox = Data;
  4095. }
  4096. row1.Cells[j - 4].CellStyle = styleborder;
  4097. }
  4098. if (i == rowNum - 1)
  4099. {
  4100. PageNum2 = PageNum2 + 1;
  4101. row1 = sheet.CreateRow(PaintIndex);
  4102. PaintIndex = PaintIndex + 1;
  4103. for (int j = 0; j < ShowColumnCount; j++)
  4104. {
  4105. row1.CreateCell(j);
  4106. if (j == 0)
  4107. {
  4108. row1.Cells[j].SetCellValue(小计);
  4109. row1.Cells[j].CellStyle = styleborder;
  4110. }
  4111. else if (j == ShowPieceIndex)
  4112. {
  4113. row1.Cells[ShowPieceIndex].SetCellValue(PageNum2 + 片);
  4114. row1.Cells[j].CellStyle = styleborder;
  4115. }
  4116. else if (j == ShowCountIndex)
  4117. {
  4118. row1.Cells[j].SetCellValue(sumCount);
  4119. row1.Cells[j].CellStyle = styleborder;
  4120. }
  4121. else if (j == ShowBoxIndex - 4)
  4122. {
  4123. row1.Cells[j].SetCellValue(LastBox);
  4124. row1.Cells[j].CellStyle = styleborder;
  4125. }
  4126. else
  4127. {
  4128. row1.Cells[j].CellStyle = styleborder;
  4129. }
  4130. }
  4131. row1 = sheet.CreateRow(PaintIndex);
  4132. for (int j = 0; j < columnNum - 3; j++)
  4133. {
  4134. if (j == 0)
  4135. {
  4136. row1.CreateCell(j);
  4137. row1.Cells[j].SetCellValue("备注");
  4138. }
  4139. else if (j == ShowCountIndex)
  4140. {
  4141. row1.CreateCell(j);
  4142. row1.Cells[j].SetCellValue(totalCount);
  4143. }
  4144. else if (j == ShowRemarkPiece)
  4145. {
  4146. row1.CreateCell(j);
  4147. row1.Cells[j].SetCellValue(rowNum + 片);
  4148. }
  4149. else
  4150. {
  4151. row1.CreateCell(j);
  4152. }
  4153. row1.Cells[j].CellStyle = style;
  4154. }
  4155. sheet.SetRowBreak(PaintIndex);
  4156. sheet.Footer.Center = "第&P页,共&N页";
  4157. PaintIndex = PaintIndex + 1;
  4158. PageNum1 = 0;
  4159. }
  4160. PageNum2 = PageNum2 + 1;
  4161. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  4162. pib_outboxcode1.Add(BoxCode.ToString());
  4163. SerialNum = SerialNum + 1;
  4164. }
  4165. break;
  4166. default:
  4167. break;
  4168. }
  4169. 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());
  4170. //删除下载链接再重新插入
  4171. HttpHandler.GenDownLoadLinK(Inoutno);
  4172. //填充首页
  4173. sumCount = 0;
  4174. totalCount = 0;
  4175. PaintIndex = 1;
  4176. ISheet sheet2 = book.CreateSheet("首页");
  4177. row = sheet2.CreateRow(0);
  4178. row.CreateCell(0);
  4179. row.Cells[0].SetCellValue(" " + companyname);
  4180. row.GetCell(0).CellStyle = style;
  4181. rowNum = FirstDT.Rows.Count;
  4182. //不需要显示的列移除
  4183. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  4184. {
  4185. for (int j = 0; j < box.Length; j++)
  4186. {
  4187. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  4188. {
  4189. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  4190. {
  4191. FirstDT.Columns.RemoveAt(i);
  4192. }
  4193. }
  4194. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  4195. {
  4196. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  4197. {
  4198. FirstDT.Columns.RemoveAt(i);
  4199. }
  4200. }
  4201. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  4202. {
  4203. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  4204. {
  4205. FirstDT.Columns.RemoveAt(i);
  4206. }
  4207. }
  4208. if (box[j].Name == "FirstPage_BOXCODE" && !box[j].Checked)
  4209. {
  4210. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  4211. {
  4212. FirstDT.Columns.RemoveAt(i);
  4213. }
  4214. }
  4215. }
  4216. }
  4217. columnNum = FirstDT.Columns.Count;
  4218. for (int i = 0; i < rowNum; i++)
  4219. {
  4220. IRow row1 = sheet2.CreateRow(PaintIndex);
  4221. PaintIndex = PaintIndex + 1;
  4222. row1.HeightInPoints = RowHeight;
  4223. //只需要绘制一行
  4224. if (i == 0)
  4225. {
  4226. for (int j = 0; j < columnNum - 3; j++)
  4227. {
  4228. if (j == 0)
  4229. {
  4230. row1.CreateCell(j);
  4231. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString() + " "
  4232. + FirstDT.Columns["ch_level"].Caption + ":" + FirstDT.Rows[i]["ch_level"].ToString());
  4233. }
  4234. else if (j > 5 && j == columnNum - 5)
  4235. {
  4236. row1.CreateCell(j);
  4237. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  4238. }
  4239. else if (columnNum > 5 && j == columnNum - 5)
  4240. {
  4241. row1.CreateCell(j);
  4242. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  4243. }
  4244. else
  4245. {
  4246. row1.CreateCell(j);
  4247. }
  4248. row1.GetCell(j).CellStyle = style;
  4249. }
  4250. row1 = sheet2.CreateRow(PaintIndex);
  4251. PaintIndex = PaintIndex + 1;
  4252. //第二行添加型号
  4253. for (int j = 0; j < columnNum - 3; j++)
  4254. {
  4255. if (j == 0)
  4256. {
  4257. row1.CreateCell(j).SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString() + "_"
  4258. + "(" + FirstDT.Rows[i]["me_desc"].ToString() + ")" + FirstDT.Columns["pi_chipouttype"].Caption + ":" + FirstDT.Rows[i]["pi_chipouttype"].ToString());
  4259. }
  4260. else if (j == ShowSizeIndex)
  4261. {
  4262. row1.CreateCell(j);
  4263. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_size"].Caption + ":" + FirstDT.Rows[i]["pr_size"].ToString());
  4264. }
  4265. else if (j > 5 && j == columnNum - 5)
  4266. {
  4267. row1.CreateCell(j);
  4268. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  4269. }
  4270. else if (columnNum > 5 && j == columnNum - 5)
  4271. {
  4272. row1.CreateCell(j);
  4273. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  4274. }
  4275. else
  4276. {
  4277. row1.CreateCell(j);
  4278. }
  4279. row1.GetCell(j).CellStyle = style;
  4280. }
  4281. row1 = sheet2.CreateRow(PaintIndex);
  4282. PaintIndex = PaintIndex + 1;
  4283. //添加列名
  4284. for (int j = 4; j < columnNum; j++)
  4285. {
  4286. row1.CreateCell(j - 4);
  4287. if (NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  4288. {
  4289. }
  4290. else
  4291. {
  4292. row1.Cells[j - 4].CellStyle = styleborder;
  4293. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  4294. }
  4295. }
  4296. row1 = sheet2.CreateRow(PaintIndex);
  4297. PaintIndex = PaintIndex + 1;
  4298. }
  4299. //添加数据内容
  4300. ShowColumnCount = 0;
  4301. for (int j = 4; j < columnNum; j++)
  4302. {
  4303. row1.CreateCell(j - 4);
  4304. if (!NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  4305. {
  4306. string Data = FirstDT.Rows[i][j].ToString();
  4307. row1.Cells[j - 4].SetCellValue(Data);
  4308. row1.GetCell(j - 4).CellStyle = styleborder;
  4309. if (FirstDT.Columns[j].ColumnName == "num")
  4310. {
  4311. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  4312. sumCount += int.Parse(Data);
  4313. }
  4314. if (FirstDT.Columns[j].ColumnName == "io_qty")
  4315. {
  4316. totalCount += int.Parse(Data);
  4317. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  4318. }
  4319. ShowColumnCount = ShowColumnCount + 1;
  4320. }
  4321. else
  4322. {
  4323. }
  4324. }
  4325. //添加总计行
  4326. if (i == rowNum - 1)
  4327. {
  4328. row1 = sheet2.CreateRow(PaintIndex);
  4329. PaintIndex = PaintIndex + 1;
  4330. for (int j = 0; j < ShowColumnCount; j++)
  4331. {
  4332. if (j == 0)
  4333. {
  4334. row1.CreateCell(j);
  4335. row1.Cells[j].CellStyle = styleborder;
  4336. row1.Cells[j].SetCellValue(总计);
  4337. }
  4338. else if (j == ShowColumnCount - 2)
  4339. {
  4340. row1.CreateCell(j);
  4341. row1.Cells[j].CellStyle = styleborder;
  4342. row1.Cells[j].SetCellValue(sumCount);
  4343. }
  4344. else if (j == ShowColumnCount - 1)
  4345. {
  4346. row1.CreateCell(j);
  4347. row1.Cells[j].CellStyle = styleborder;
  4348. row1.Cells[j].SetCellValue(totalCount);
  4349. }
  4350. else
  4351. {
  4352. row1.CreateCell(j);
  4353. row1.Cells[j].CellStyle = styleborder;
  4354. }
  4355. }
  4356. }
  4357. }
  4358. //将book的内容写入内存流中返回
  4359. book.Write(ms);
  4360. return ms;
  4361. }
  4362. }
  4363. }