ExcelHandler.cs 247 KB

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