ExcelHandler.cs 244 KB

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