ExcelHandler.cs 254 KB

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