ExcelHandler.cs 245 KB

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