ExcelHandler.cs 228 KB

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