ExcelHandler.cs 222 KB

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