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