ExcelHandler.cs 203 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911
  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. }
  1290. }
  1291. columnNum = FirstDT.Columns.Count;
  1292. for (int i = 0; i < rowNum; i++)
  1293. {
  1294. IRow row1 = sheet2.CreateRow(PaintIndex);
  1295. PaintIndex = PaintIndex + 1;
  1296. row1.HeightInPoints = RowHeight;
  1297. //只需要绘制一行
  1298. if (i == 0)
  1299. {
  1300. for (int j = 0; j < columnNum - 3; j++)
  1301. {
  1302. if (j == 0)
  1303. {
  1304. row1.CreateCell(j);
  1305. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString());
  1306. }
  1307. else if (j > 5 && j == columnNum - 5)
  1308. {
  1309. row1.CreateCell(j);
  1310. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  1311. }
  1312. else if (columnNum > 5 && j == columnNum - 5)
  1313. {
  1314. row1.CreateCell(j);
  1315. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  1316. }
  1317. else
  1318. {
  1319. row1.CreateCell(j);
  1320. }
  1321. row1.GetCell(j).CellStyle = style;
  1322. }
  1323. row1 = sheet2.CreateRow(PaintIndex);
  1324. PaintIndex = PaintIndex + 1;
  1325. //第二行添加型号
  1326. for (int j = 0; j < columnNum - 3; j++)
  1327. {
  1328. if (j == 0)
  1329. {
  1330. row1.CreateCell(j);
  1331. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString());
  1332. }
  1333. else if (j > 5 && j == columnNum - 5)
  1334. {
  1335. row1.CreateCell(j);
  1336. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  1337. }
  1338. else if (columnNum > 5 && j == columnNum - 5)
  1339. {
  1340. row1.CreateCell(j);
  1341. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  1342. }
  1343. else
  1344. {
  1345. row1.CreateCell(j);
  1346. }
  1347. row1.GetCell(j).CellStyle = style;
  1348. }
  1349. row1 = sheet2.CreateRow(PaintIndex);
  1350. PaintIndex = PaintIndex + 1;
  1351. //添加列名
  1352. for (int j = 4; j < columnNum; j++)
  1353. {
  1354. row1.CreateCell(j - 4);
  1355. row1.Cells[j - 4].CellStyle = styleborder;
  1356. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  1357. }
  1358. row1 = sheet2.CreateRow(PaintIndex);
  1359. PaintIndex = PaintIndex + 1;
  1360. }
  1361. //添加数据内容
  1362. for (int j = 4; j < columnNum; j++)
  1363. {
  1364. string Data = FirstDT.Rows[i][j].ToString();
  1365. row1.CreateCell(j - 4);
  1366. row1.Cells[j - 4].SetCellValue(Data);
  1367. row1.GetCell(j - 4).CellStyle = styleborder;
  1368. if (FirstDT.Columns[j].ColumnName == "num")
  1369. {
  1370. sumCount += int.Parse(Data);
  1371. }
  1372. if (FirstDT.Columns[j].ColumnName == "io_qty")
  1373. {
  1374. totalCount += int.Parse(Data);
  1375. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  1376. }
  1377. }
  1378. //添加总计行
  1379. if (i == rowNum - 1)
  1380. {
  1381. row1 = sheet2.CreateRow(PaintIndex);
  1382. PaintIndex = PaintIndex + 1;
  1383. for (int j = 0; j < columnNum - 4; j++)
  1384. {
  1385. if (j == 0)
  1386. {
  1387. row1.CreateCell(j);
  1388. row1.Cells[j].CellStyle = styleborder;
  1389. row1.Cells[j].SetCellValue(总计);
  1390. }
  1391. else if (j == columnNum - 6)
  1392. {
  1393. row1.CreateCell(j);
  1394. row1.Cells[j].CellStyle = styleborder;
  1395. row1.Cells[j].SetCellValue(sumCount);
  1396. }
  1397. else if (j == columnNum - 5)
  1398. {
  1399. row1.CreateCell(j);
  1400. row1.Cells[j].CellStyle = styleborder;
  1401. row1.Cells[j].SetCellValue(totalCount);
  1402. }
  1403. else
  1404. {
  1405. row1.CreateCell(j);
  1406. row1.Cells[j].CellStyle = styleborder;
  1407. }
  1408. }
  1409. }
  1410. }
  1411. for (int i = 0; i < sheet2.LastRowNum; i++)
  1412. {
  1413. if (i != 0)
  1414. {
  1415. sheet2.AutoSizeColumn(i);
  1416. sheet2.SetColumnWidth(i, sheet2.GetColumnWidth(i) + 1000);
  1417. }
  1418. }
  1419. //将book的内容写入内存流中返回
  1420. book.Write(ms);
  1421. return ms;
  1422. }
  1423. /// <summary>
  1424. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  1425. /// </summary>
  1426. /// <param name="DataTable"></param>
  1427. /// <returns></returns>
  1428. private MemoryStream DataTableToExcel_JINYUAN(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  1429. {
  1430. string 小计 = "";
  1431. string 总计 = "";
  1432. string 片 = "";
  1433. string companyname = "";
  1434. //晶源的需要显示在数量列下面
  1435. int ShowCountIndex = 2;
  1436. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype", "pi_inoutno='" + Inoutno + "'").ToString() == "Chinese")
  1437. {
  1438. 小计 = "小计";
  1439. 总计 = "总计";
  1440. 片 = "片";
  1441. companyname = "深爱半导体股份有限公司芯片出货清单";
  1442. }
  1443. else
  1444. {
  1445. 小计 = "total";
  1446. 总计 = "total";
  1447. 片 = "slice";
  1448. companyname = "SHENZHEN SI SEMICONDUCTORS CO.,LTD";
  1449. }
  1450. //转换为序列
  1451. CheckBox[] box = conditionbox.ToArray();
  1452. //创建内存流
  1453. MemoryStream ms = new MemoryStream();
  1454. //创建一个Book,相当于一个Excel文件
  1455. HSSFWorkbook book = new HSSFWorkbook();
  1456. //Excel中的Sheet
  1457. ISheet sheet = book.CreateSheet("分页");
  1458. sheet.SetMargin(MarginType.TopMargin, 0.4);
  1459. sheet.SetMargin(MarginType.BottomMargin, 0.1);
  1460. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  1461. sheet.SetMargin(MarginType.RightMargin, 0.4);
  1462. sheet.PrintSetup.NoColor = true;
  1463. sheet.PrintSetup.Landscape = true;
  1464. //芯片号需要作为更新盒号的条件
  1465. HSSFFont ffont = (HSSFFont)book.CreateFont();
  1466. ffont.FontName = "宋体";
  1467. //更新箱号
  1468. List<string> pib_id = new List<string>();
  1469. //系统打印箱号
  1470. List<string> pib_outboxcode1 = new List<string>();
  1471. int BoxCode = 1;
  1472. ICellStyle style = book.CreateCellStyle();
  1473. style.VerticalAlignment = VerticalAlignment.Center;
  1474. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  1475. style.SetFont(ffont);
  1476. ICellStyle styleborder = book.CreateCellStyle();
  1477. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1478. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1479. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1480. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1481. styleborder.VerticalAlignment = VerticalAlignment.Center;
  1482. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  1483. styleborder.SetFont(ffont);
  1484. string pi_inoutno = "";
  1485. List<string> NotShowColumn = new List<string>();
  1486. NotShowColumn.Add("ch_level");
  1487. NotShowColumn.Add("pib_id");
  1488. NotShowColumn.Add("chw_itemname1");
  1489. NotShowColumn.Add("chw_itemname2");
  1490. NotShowColumn.Add("chw_itemname3");
  1491. NotShowColumn.Add("pd_ordercode");
  1492. NotShowColumn.Add("pr_size");
  1493. NotShowColumn.Add("me_desc");
  1494. NotShowColumn.Add("pr_orispeccode");
  1495. NotShowColumn.Add("pr_orispeccode1");
  1496. NotShowColumn.Add("pi_title");
  1497. NotShowColumn.Add("pi_date");
  1498. NotShowColumn.Add("pi_chipouttype");
  1499. //设置列的宽度,根据首行的列的内容的长度来设置
  1500. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  1501. {
  1502. for (int j = 0; j < box.Length; j++)
  1503. {
  1504. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  1505. {
  1506. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  1507. {
  1508. DataTable.Columns.RemoveAt(i);
  1509. break;
  1510. }
  1511. }
  1512. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  1513. {
  1514. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  1515. {
  1516. DataTable.Columns.RemoveAt(i);
  1517. break;
  1518. }
  1519. }
  1520. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  1521. {
  1522. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  1523. {
  1524. DataTable.Columns.RemoveAt(i);
  1525. break;
  1526. }
  1527. }
  1528. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  1529. {
  1530. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  1531. {
  1532. DataTable.Columns.RemoveAt(i);
  1533. break;
  1534. }
  1535. }
  1536. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  1537. {
  1538. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  1539. {
  1540. DataTable.Columns.RemoveAt(i);
  1541. break;
  1542. }
  1543. }
  1544. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  1545. {
  1546. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  1547. {
  1548. DataTable.Columns.RemoveAt(i);
  1549. break;
  1550. }
  1551. }
  1552. if (box[j].Name.ToLower() == "ch_yield" && !box[j].Checked)
  1553. {
  1554. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_yield"))
  1555. {
  1556. DataTable.Columns.RemoveAt(i);
  1557. break;
  1558. }
  1559. }
  1560. }
  1561. }
  1562. //获取行数量和列数量
  1563. int rowNum = DataTable.Rows.Count;
  1564. int columnNum = DataTable.Columns.Count;
  1565. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  1566. //ffont.FontHeight = 10;
  1567. //开始绘制的Index
  1568. int PaintIndex = 0;
  1569. int sumCount = 0;
  1570. int totalCount = 0;
  1571. //Title的字体
  1572. HSSFFont titlefont = (HSSFFont)book.CreateFont();
  1573. titlefont.FontName = "宋体";
  1574. titlefont.FontHeight = 270;
  1575. titlefont.Boldweight = (short)FontBoldWeight.Bold;
  1576. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  1577. ColumnTitle.FontName = "宋体";
  1578. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  1579. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  1580. ColumnTitleStyle.SetFont(ColumnTitle);
  1581. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1582. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1583. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1584. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1585. ICellStyle TitleStyle = book.CreateCellStyle();
  1586. TitleStyle.SetFont(titlefont);
  1587. int ShowColumnCount = 0;
  1588. IRow row1 = null;
  1589. switch (Type)
  1590. {
  1591. case "FixRow":
  1592. //清理系统取出来的数据
  1593. BaseUtil.CleanDataTableData(FirstDT);
  1594. //首页参数拼接
  1595. string First_OrderCode = "";
  1596. string First_Prspec = "";
  1597. string First_Batch = "";
  1598. ArrayList<string> First_WID = new ArrayList<string>();
  1599. for (int i = 0; i < rowNum; i++)
  1600. {
  1601. if (PaintIndex != 0)
  1602. {
  1603. row1 = sheet.CreateRow(PaintIndex);
  1604. PaintIndex = PaintIndex + 1;
  1605. row1.HeightInPoints = RowHeight;
  1606. }
  1607. //不包含的订单号
  1608. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  1609. {
  1610. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  1611. }
  1612. //不包含的物料型号
  1613. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  1614. {
  1615. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  1616. }
  1617. //不包含扩撒批号
  1618. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  1619. {
  1620. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  1621. }
  1622. //不包含Wafer_id
  1623. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  1624. {
  1625. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  1626. }
  1627. if (i / PageSize >= 1 && i % PageSize == 0)
  1628. {
  1629. DataRow dr = FirstDT.NewRow();
  1630. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  1631. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  1632. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  1633. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  1634. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  1635. dr["pd_ordercode"] = First_OrderCode;
  1636. dr["pr_orispeccode"] = First_Prspec;
  1637. dr["ch_splitbatch"] = First_Batch;
  1638. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  1639. dr["num"] = PageSize;
  1640. dr["io_qty"] = sumCount;
  1641. FirstDT.Rows.Add(dr);
  1642. First_OrderCode = "";
  1643. First_Prspec = "";
  1644. First_Batch = "";
  1645. First_WID.Clear();
  1646. BoxCode = BoxCode + 1;
  1647. for (int j = 0; j < ShowColumnCount; j++)
  1648. {
  1649. row1.CreateCell(j);
  1650. if (j == 0)
  1651. {
  1652. row1.Cells[j].SetCellValue(小计);
  1653. }
  1654. else if (j == ShowPieceIndex)
  1655. {
  1656. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i) + 片);
  1657. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1658. }
  1659. else if (j == ShowCountIndex)
  1660. {
  1661. row1.Cells[j].SetCellValue(sumCount);
  1662. }
  1663. row1.Cells[j].CellStyle = styleborder;
  1664. }
  1665. sumCount = 0;
  1666. row1 = sheet.CreateRow(PaintIndex);
  1667. sheet.SetRowBreak(PaintIndex - 1);
  1668. sheet.Footer.Center = "第&P页,共&N页";
  1669. }
  1670. //每次到了页数开始分页
  1671. if (i % PageSize == 0 || i == rowNum - 1)
  1672. {
  1673. //第一行添加客户信息 rownum只有一行的情
  1674. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  1675. {
  1676. //抬头设置
  1677. row1 = sheet.CreateRow(PaintIndex);
  1678. PaintIndex = PaintIndex + 1;
  1679. row1.CreateCell(0).SetCellValue(" " + companyname);
  1680. row1.GetCell(0).CellStyle = TitleStyle;
  1681. row1 = sheet.CreateRow(PaintIndex);
  1682. PaintIndex = PaintIndex + 1;
  1683. for (int j = 0; j < columnNum - 3; j++)
  1684. {
  1685. if (j == 0)
  1686. {
  1687. row1.CreateCell(j);
  1688. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  1689. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  1690. }
  1691. else if (j == ShowDataIndex)
  1692. {
  1693. row1.CreateCell(j);
  1694. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  1695. }
  1696. else
  1697. {
  1698. row1.CreateCell(j);
  1699. }
  1700. row1.GetCell(j).CellStyle = style;
  1701. }
  1702. row1 = sheet.CreateRow(PaintIndex);
  1703. PaintIndex = PaintIndex + 1;
  1704. //第二行添加型号
  1705. for (int j = 0; j < columnNum - 3; j++)
  1706. {
  1707. if (j == 0)
  1708. {
  1709. row1.CreateCell(j);
  1710. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  1711. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  1712. }
  1713. else if (j == ShowSizeIndex)
  1714. {
  1715. row1.CreateCell(j);
  1716. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  1717. }
  1718. else if (j == ShowDataIndex)
  1719. {
  1720. row1.CreateCell(j);
  1721. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  1722. }
  1723. else
  1724. {
  1725. row1.CreateCell(j);
  1726. }
  1727. row1.GetCell(j).CellStyle = style;
  1728. }
  1729. //特殊客户添加一列空行
  1730. row1 = sheet.CreateRow(PaintIndex);
  1731. PaintIndex = PaintIndex + 1;
  1732. for (int j = 0; j < columnNum; j++)
  1733. {
  1734. row1.CreateCell(j).SetCellValue("");
  1735. }
  1736. //添加列名
  1737. row1 = sheet.CreateRow(PaintIndex);
  1738. PaintIndex = PaintIndex + 1;
  1739. //计数列所在的索引
  1740. int showcount = 0;
  1741. //前面有4列标题内容,数据库设置的,需要从4开始索引
  1742. for (int j = 4; j < columnNum; j++)
  1743. {
  1744. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  1745. {
  1746. showcount = showcount + 1;
  1747. row1.CreateCell(j - 4);
  1748. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1749. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  1750. }
  1751. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  1752. {
  1753. showcount = showcount + 1;
  1754. row1.CreateCell(j - 4);
  1755. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1756. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  1757. }
  1758. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  1759. {
  1760. showcount = showcount + 1;
  1761. row1.CreateCell(j - 4);
  1762. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1763. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  1764. }
  1765. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1766. {
  1767. }
  1768. else
  1769. {
  1770. showcount = showcount + 1;
  1771. row1.CreateCell(j - 4);
  1772. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1773. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  1774. }
  1775. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  1776. {
  1777. NumIndex = j - 4;
  1778. }
  1779. }
  1780. ShowColumnCount = showcount;
  1781. row1 = sheet.CreateRow(PaintIndex);
  1782. PaintIndex = PaintIndex + 1;
  1783. }
  1784. }
  1785. //添加数据内容
  1786. for (int j = 4; j < columnNum; j++)
  1787. {
  1788. string Data = DataTable.Rows[i][j].ToString();
  1789. row1.CreateCell(j - 4);
  1790. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1791. {
  1792. }
  1793. else
  1794. {
  1795. row1.Cells[j - 4].SetCellValue(Data);
  1796. row1.GetCell(j - 4).CellStyle = styleborder;
  1797. }
  1798. if (DataTable.Columns[j].ColumnName == "io_qty")
  1799. {
  1800. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  1801. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  1802. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  1803. }
  1804. if (DataTable.Columns[j].ColumnName == "rownum")
  1805. {
  1806. row1.Cells[j - 4].SetCellValue(i + 1);
  1807. }
  1808. if (DataTable.Columns[j].ColumnName == "ch_code")
  1809. {
  1810. sheet.AutoSizeColumn(j - 4);
  1811. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  1812. }
  1813. }
  1814. //固定行号分组的时候自动拼接新的DataTable
  1815. if (i == rowNum - 1)
  1816. {
  1817. DataRow dr = FirstDT.NewRow();
  1818. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  1819. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  1820. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  1821. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  1822. dr["pd_ordercode"] = First_OrderCode;
  1823. dr["pr_orispeccode"] = First_Prspec;
  1824. dr["ch_splitbatch"] = First_Batch;
  1825. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  1826. dr["num"] = (i % PageSize) + 1;
  1827. dr["io_qty"] = sumCount;
  1828. FirstDT.Rows.Add(dr);
  1829. row1 = sheet.CreateRow(PaintIndex);
  1830. PaintIndex = PaintIndex + 1;
  1831. for (int j = 0; j < ShowColumnCount; j++)
  1832. {
  1833. row1.CreateCell(j);
  1834. if (j == 0)
  1835. {
  1836. row1.Cells[j].SetCellValue(小计);
  1837. }
  1838. else if (j == ShowPieceIndex)
  1839. {
  1840. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize == 0 ? PageSize : (rowNum % PageSize)) + 片);
  1841. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1842. }
  1843. else if (j == ShowCountIndex)
  1844. {
  1845. row1.Cells[j].SetCellValue(sumCount);
  1846. }
  1847. row1.Cells[j].CellStyle = styleborder;
  1848. }
  1849. row1 = sheet.CreateRow(PaintIndex);
  1850. for (int j = 0; j < columnNum - 3; j++)
  1851. {
  1852. if (j == 0)
  1853. {
  1854. row1.CreateCell(j);
  1855. row1.Cells[j].SetCellValue("备注");
  1856. }
  1857. else if (j == ShowCountIndex)
  1858. {
  1859. row1.CreateCell(j);
  1860. row1.Cells[j].SetCellValue(totalCount);
  1861. }
  1862. else if (j == ShowRemarkPiece)
  1863. {
  1864. row1.CreateCell(j);
  1865. row1.Cells[j].SetCellValue(rowNum + 片);
  1866. }
  1867. else
  1868. {
  1869. row1.CreateCell(j);
  1870. }
  1871. row1.Cells[j].CellStyle = style;
  1872. }
  1873. sheet.SetRowBreak(PaintIndex);
  1874. sheet.Footer.Center = "第&P页,共&N页";
  1875. }
  1876. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  1877. pib_outboxcode1.Add(BoxCode.ToString());
  1878. }
  1879. break;
  1880. case "BatchCode":
  1881. string LastBatchCode = "";
  1882. int PageNum = 0;
  1883. for (int i = 0; i < rowNum; i++)
  1884. {
  1885. row1 = sheet.CreateRow(PaintIndex);
  1886. if (i != 0)
  1887. PaintIndex = PaintIndex + 1;
  1888. row1.HeightInPoints = RowHeight;
  1889. //如果批号不相等的时候
  1890. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  1891. {
  1892. BoxCode = BoxCode + 1;
  1893. for (int j = 0; j < ShowColumnCount; j++)
  1894. {
  1895. row1.CreateCell(j);
  1896. if (j == 0)
  1897. {
  1898. row1.Cells[j].SetCellValue(小计);
  1899. row1.Cells[j].CellStyle = styleborder;
  1900. }
  1901. else if (j == ShowPieceIndex)
  1902. {
  1903. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  1904. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1905. }
  1906. else if (j == ShowCountIndex)
  1907. {
  1908. row1.Cells[j].SetCellValue(sumCount);
  1909. row1.Cells[j].CellStyle = styleborder;
  1910. }
  1911. else
  1912. {
  1913. row1.Cells[j].CellStyle = styleborder;
  1914. }
  1915. }
  1916. sumCount = 0;
  1917. //row1 = sheet.CreateRow(PaintIndex);
  1918. sheet.SetRowBreak(PaintIndex - 1);
  1919. sheet.Footer.Center = "第&P页,共&N页";
  1920. PageNum = 0;
  1921. }
  1922. //每次到了页数开始分页
  1923. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()))
  1924. {
  1925. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  1926. //第一行添加客户信息
  1927. row1 = sheet.CreateRow(PaintIndex);
  1928. PaintIndex = PaintIndex + 1;
  1929. row1.CreateCell(0).SetCellValue(" " + companyname);
  1930. row1.GetCell(0).CellStyle = TitleStyle;
  1931. row1 = sheet.CreateRow(PaintIndex);
  1932. PaintIndex = PaintIndex + 1;
  1933. //if (i != rowNum - 1)
  1934. {
  1935. for (int j = 0; j < columnNum - 3; j++)
  1936. {
  1937. if (j == 0)
  1938. {
  1939. row1.CreateCell(j);
  1940. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  1941. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  1942. }
  1943. else if (j == ShowDataIndex)
  1944. {
  1945. row1.CreateCell(j);
  1946. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  1947. }
  1948. else
  1949. {
  1950. row1.CreateCell(j);
  1951. }
  1952. row1.GetCell(j).CellStyle = style;
  1953. }
  1954. row1 = sheet.CreateRow(PaintIndex);
  1955. PaintIndex = PaintIndex + 1;
  1956. //第二行添加型号
  1957. for (int j = 0; j < columnNum - 3; j++)
  1958. {
  1959. if (j == 0)
  1960. {
  1961. row1.CreateCell(j);
  1962. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  1963. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  1964. }
  1965. else if (j == ShowSizeIndex)
  1966. {
  1967. row1.CreateCell(j);
  1968. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  1969. }
  1970. else if (j == ShowDataIndex)
  1971. {
  1972. row1.CreateCell(j);
  1973. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  1974. }
  1975. else
  1976. {
  1977. row1.CreateCell(j);
  1978. }
  1979. row1.GetCell(j).CellStyle = style;
  1980. }
  1981. //特殊客户添加一列空行
  1982. row1 = sheet.CreateRow(PaintIndex);
  1983. PaintIndex = PaintIndex + 1;
  1984. for (int j = 0; j < columnNum; j++)
  1985. {
  1986. row1.CreateCell(j).SetCellValue("");
  1987. }
  1988. //添加列名
  1989. row1 = sheet.CreateRow(PaintIndex);
  1990. PaintIndex = PaintIndex + 1;
  1991. int showcount = 0;
  1992. for (int j = 4; j < columnNum; j++)
  1993. {
  1994. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  1995. {
  1996. showcount = showcount + 1;
  1997. row1.CreateCell(j - 4);
  1998. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1999. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  2000. }
  2001. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2002. {
  2003. showcount = showcount + 1;
  2004. row1.CreateCell(j - 4);
  2005. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2006. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  2007. }
  2008. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  2009. {
  2010. showcount = showcount + 1;
  2011. row1.CreateCell(j - 4);
  2012. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2013. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  2014. }
  2015. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2016. {
  2017. }
  2018. else
  2019. {
  2020. showcount = showcount + 1;
  2021. row1.CreateCell(j - 4);
  2022. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2023. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  2024. }
  2025. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  2026. {
  2027. NumIndex = j - 4;
  2028. }
  2029. }
  2030. ShowColumnCount = showcount;
  2031. row1 = sheet.CreateRow(PaintIndex);
  2032. PaintIndex = PaintIndex + 1;
  2033. }
  2034. }
  2035. //添加数据内容
  2036. for (int j = 4; j < columnNum; j++)
  2037. {
  2038. string Data = DataTable.Rows[i][j].ToString();
  2039. row1.CreateCell(j - 4);
  2040. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2041. {
  2042. }
  2043. else
  2044. {
  2045. row1.Cells[j - 4].SetCellValue(Data);
  2046. row1.GetCell(j - 4).CellStyle = styleborder;
  2047. }
  2048. if (DataTable.Columns[j].ColumnName == "io_qty")
  2049. {
  2050. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2051. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  2052. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  2053. }
  2054. if (DataTable.Columns[j].ColumnName == "rownum")
  2055. {
  2056. row1.Cells[j - 4].SetCellValue(i + 1);
  2057. }
  2058. if (DataTable.Columns[j].ColumnName == "ch_code")
  2059. {
  2060. sheet.AutoSizeColumn(j - 4);
  2061. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  2062. }
  2063. }
  2064. if (i == rowNum - 1)
  2065. {
  2066. row1 = sheet.CreateRow(PaintIndex);
  2067. PaintIndex = PaintIndex + 1;
  2068. for (int j = 0; j < ShowColumnCount; j++)
  2069. {
  2070. row1.CreateCell(j);
  2071. if (j == 0)
  2072. {
  2073. row1.Cells[j].SetCellValue(小计);
  2074. row1.Cells[j].CellStyle = styleborder;
  2075. }
  2076. else if (j == ShowPieceIndex)
  2077. {
  2078. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  2079. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2080. }
  2081. else if (j == ShowCountIndex)
  2082. {
  2083. row1.Cells[j].SetCellValue(sumCount);
  2084. row1.Cells[j].CellStyle = styleborder;
  2085. }
  2086. else
  2087. {
  2088. row1.Cells[j].CellStyle = styleborder;
  2089. }
  2090. }
  2091. //创建备注内容
  2092. row1 = sheet.CreateRow(PaintIndex);
  2093. for (int j = 0; j < columnNum - 3; j++)
  2094. {
  2095. if (j == 0)
  2096. {
  2097. row1.CreateCell(j);
  2098. row1.Cells[j].SetCellValue("备注");
  2099. }
  2100. else if (j == ShowCountIndex)
  2101. {
  2102. row1.CreateCell(j);
  2103. row1.Cells[j].SetCellValue(totalCount);
  2104. }
  2105. else if (j == ShowRemarkPiece)
  2106. {
  2107. row1.CreateCell(j);
  2108. row1.Cells[j].SetCellValue(rowNum + 片);
  2109. }
  2110. else
  2111. {
  2112. row1.CreateCell(j);
  2113. }
  2114. row1.Cells[j].CellStyle = style;
  2115. }
  2116. sheet.SetRowBreak(PaintIndex);
  2117. sheet.Footer.Center = "第&P页,共&N页";
  2118. PageNum = 0;
  2119. }
  2120. PageNum = PageNum + 1;
  2121. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  2122. pib_outboxcode1.Add(BoxCode.ToString());
  2123. }
  2124. break;
  2125. case "BoxCode":
  2126. string LastBoxCode = "";
  2127. int PageNum1 = 0;
  2128. for (int i = 0; i < rowNum; i++)
  2129. {
  2130. row1 = sheet.CreateRow(PaintIndex);
  2131. if (i != 0)
  2132. PaintIndex = PaintIndex + 1;
  2133. row1.HeightInPoints = RowHeight;
  2134. //如果箱号不相等的时候
  2135. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  2136. {
  2137. BoxCode = BoxCode + 1;
  2138. for (int j = 0; j < ShowColumnCount; j++)
  2139. {
  2140. row1.CreateCell(j);
  2141. if (j == 0)
  2142. {
  2143. row1.Cells[j].SetCellValue(小计);
  2144. row1.Cells[j].CellStyle = styleborder;
  2145. }
  2146. else if (j == ShowPieceIndex)
  2147. {
  2148. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  2149. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2150. }
  2151. else if (j == ShowCountIndex)
  2152. {
  2153. row1.Cells[j].SetCellValue(sumCount);
  2154. row1.Cells[j].CellStyle = styleborder;
  2155. }
  2156. else
  2157. {
  2158. row1.Cells[j].CellStyle = styleborder;
  2159. }
  2160. }
  2161. sumCount = 0;
  2162. //row1 = sheet.CreateRow(PaintIndex);
  2163. sheet.SetRowBreak(PaintIndex - 1);
  2164. sheet.Footer.Center = "第&P页,共&N页";
  2165. PageNum1 = 0;
  2166. }
  2167. //每次到了页数开始分页
  2168. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  2169. {
  2170. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  2171. row1 = sheet.CreateRow(PaintIndex);
  2172. PaintIndex = PaintIndex + 1;
  2173. row1.CreateCell(0).SetCellValue(" " + companyname);
  2174. row1.GetCell(0).CellStyle = TitleStyle;
  2175. row1 = sheet.CreateRow(PaintIndex);
  2176. PaintIndex = PaintIndex + 1;
  2177. //第一行添加客户信息
  2178. //if (i != rowNum - 1)
  2179. {
  2180. for (int j = 0; j < columnNum - 3; j++)
  2181. {
  2182. if (j == 0)
  2183. {
  2184. row1.CreateCell(j);
  2185. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  2186. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  2187. }
  2188. else if (j == ShowDataIndex)
  2189. {
  2190. row1.CreateCell(j);
  2191. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  2192. }
  2193. else
  2194. {
  2195. row1.CreateCell(j);
  2196. }
  2197. row1.GetCell(j).CellStyle = style;
  2198. }
  2199. row1 = sheet.CreateRow(PaintIndex);
  2200. PaintIndex = PaintIndex + 1;
  2201. //第二行添加型号
  2202. for (int j = 0; j < columnNum - 3; j++)
  2203. {
  2204. if (j == 0)
  2205. {
  2206. row1.CreateCell(j);
  2207. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  2208. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2209. }
  2210. else if (j == ShowSizeIndex)
  2211. {
  2212. row1.CreateCell(j);
  2213. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  2214. }
  2215. else if (j == ShowDataIndex)
  2216. {
  2217. row1.CreateCell(j);
  2218. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  2219. }
  2220. else
  2221. {
  2222. row1.CreateCell(j);
  2223. }
  2224. row1.GetCell(j).CellStyle = style;
  2225. }
  2226. //特殊客户添加一列空行
  2227. row1 = sheet.CreateRow(PaintIndex);
  2228. PaintIndex = PaintIndex + 1;
  2229. for (int j = 0; j < columnNum; j++)
  2230. {
  2231. row1.CreateCell(j).SetCellValue("");
  2232. }
  2233. //添加列名
  2234. row1 = sheet.CreateRow(PaintIndex);
  2235. PaintIndex = PaintIndex + 1;
  2236. int showcount = 0;
  2237. for (int j = 4; j < columnNum; j++)
  2238. {
  2239. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  2240. {
  2241. showcount = showcount + 1;
  2242. row1.CreateCell(j - 4);
  2243. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2244. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  2245. }
  2246. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2247. {
  2248. showcount = showcount + 1;
  2249. row1.CreateCell(j - 4);
  2250. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2251. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  2252. }
  2253. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  2254. {
  2255. showcount = showcount + 1;
  2256. row1.CreateCell(j - 4);
  2257. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2258. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  2259. }
  2260. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2261. {
  2262. }
  2263. else
  2264. {
  2265. showcount = showcount + 1;
  2266. row1.CreateCell(j - 4);
  2267. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2268. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  2269. }
  2270. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  2271. {
  2272. NumIndex = j - 4;
  2273. }
  2274. }
  2275. ShowColumnCount = showcount;
  2276. row1 = sheet.CreateRow(PaintIndex);
  2277. PaintIndex = PaintIndex + 1;
  2278. }
  2279. }
  2280. //添加数据内容
  2281. for (int j = 4; j < columnNum; j++)
  2282. {
  2283. string Data = DataTable.Rows[i][j].ToString();
  2284. row1.CreateCell(j - 4);
  2285. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2286. {
  2287. }
  2288. else
  2289. {
  2290. row1.Cells[j - 4].SetCellValue(Data);
  2291. row1.GetCell(j - 4).CellStyle = styleborder;
  2292. }
  2293. if (DataTable.Columns[j].ColumnName == "io_qty")
  2294. {
  2295. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2296. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  2297. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  2298. }
  2299. if (DataTable.Columns[j].ColumnName == "rownum")
  2300. {
  2301. row1.Cells[j - 4].SetCellValue(i + 1);
  2302. }
  2303. if (DataTable.Columns[j].ColumnName == "ch_code")
  2304. {
  2305. sheet.AutoSizeColumn(j - 4);
  2306. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  2307. }
  2308. }
  2309. if (i == rowNum - 1)
  2310. {
  2311. PageNum1 = PageNum1 + 1;
  2312. row1 = sheet.CreateRow(PaintIndex);
  2313. PaintIndex = PaintIndex + 1;
  2314. for (int j = 0; j < ShowColumnCount; j++)
  2315. {
  2316. row1.CreateCell(j);
  2317. if (j == 0)
  2318. {
  2319. row1.Cells[j].SetCellValue(小计);
  2320. row1.Cells[j].CellStyle = styleborder;
  2321. }
  2322. else if (j == ShowPieceIndex)
  2323. {
  2324. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  2325. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2326. }
  2327. else if (j == ShowCountIndex)
  2328. {
  2329. row1.Cells[j].SetCellValue(sumCount);
  2330. row1.Cells[j].CellStyle = styleborder;
  2331. }
  2332. else
  2333. {
  2334. row1.Cells[j].CellStyle = styleborder;
  2335. }
  2336. }
  2337. row1 = sheet.CreateRow(PaintIndex);
  2338. for (int j = 0; j < columnNum - 3; j++)
  2339. {
  2340. if (j == 0)
  2341. {
  2342. row1.CreateCell(j);
  2343. row1.Cells[j].SetCellValue("备注");
  2344. }
  2345. else if (j == ShowCountIndex)
  2346. {
  2347. row1.CreateCell(j);
  2348. row1.Cells[j].SetCellValue(totalCount);
  2349. }
  2350. else if (j == ShowRemarkPiece)
  2351. {
  2352. row1.CreateCell(j);
  2353. row1.Cells[j].SetCellValue(rowNum + 片);
  2354. }
  2355. else
  2356. {
  2357. row1.CreateCell(j);
  2358. }
  2359. row1.Cells[j].CellStyle = style;
  2360. }
  2361. sheet.SetRowBreak(PaintIndex);
  2362. sheet.Footer.Center = "第&P页,共&N页";
  2363. PageNum1 = 0;
  2364. }
  2365. PageNum1 = PageNum1 + 1;
  2366. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  2367. pib_outboxcode1.Add(BoxCode.ToString());
  2368. }
  2369. //for (int i = 0; i < sheet.LastRowNum; i++)
  2370. //{
  2371. // if (i != 0)
  2372. // {
  2373. // sheet.AutoSizeColumn(i);
  2374. // sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  2375. // }
  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. }
  2421. }
  2422. columnNum = FirstDT.Columns.Count;
  2423. for (int i = 0; i < rowNum; i++)
  2424. {
  2425. row1 = sheet2.CreateRow(PaintIndex);
  2426. PaintIndex = PaintIndex + 1;
  2427. row1.HeightInPoints = RowHeight;
  2428. //只需要绘制一行
  2429. if (i == 0)
  2430. {
  2431. for (int j = 0; j < columnNum - 3; j++)
  2432. {
  2433. if (j == 0)
  2434. {
  2435. row1.CreateCell(j);
  2436. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString());
  2437. }
  2438. else if (j > 5 && j == columnNum - 5)
  2439. {
  2440. row1.CreateCell(j);
  2441. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  2442. }
  2443. else if (columnNum > 5 && j == columnNum - 5)
  2444. {
  2445. row1.CreateCell(j);
  2446. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  2447. }
  2448. else
  2449. {
  2450. row1.CreateCell(j);
  2451. }
  2452. row1.GetCell(j).CellStyle = style;
  2453. }
  2454. row1 = sheet2.CreateRow(PaintIndex);
  2455. PaintIndex = PaintIndex + 1;
  2456. //第二行添加型号
  2457. for (int j = 0; j < columnNum - 3; j++)
  2458. {
  2459. if (j == 0)
  2460. {
  2461. row1.CreateCell(j);
  2462. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString());
  2463. }
  2464. else if (j > 5 && j == columnNum - 5)
  2465. {
  2466. row1.CreateCell(j);
  2467. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  2468. }
  2469. else if (columnNum > 5 && j == columnNum - 5)
  2470. {
  2471. row1.CreateCell(j);
  2472. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  2473. }
  2474. else
  2475. {
  2476. row1.CreateCell(j);
  2477. }
  2478. row1.GetCell(j).CellStyle = style;
  2479. }
  2480. row1 = sheet2.CreateRow(PaintIndex);
  2481. PaintIndex = PaintIndex + 1;
  2482. //添加列名
  2483. for (int j = 4; j < columnNum; j++)
  2484. {
  2485. row1.CreateCell(j - 4);
  2486. row1.Cells[j - 4].CellStyle = styleborder;
  2487. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  2488. }
  2489. row1 = sheet2.CreateRow(PaintIndex);
  2490. PaintIndex = PaintIndex + 1;
  2491. }
  2492. //添加数据内容
  2493. for (int j = 4; j < columnNum; j++)
  2494. {
  2495. string Data = FirstDT.Rows[i][j].ToString();
  2496. row1.CreateCell(j - 4);
  2497. row1.Cells[j - 4].SetCellValue(Data);
  2498. row1.GetCell(j - 4).CellStyle = styleborder;
  2499. if (FirstDT.Columns[j].ColumnName == "num")
  2500. {
  2501. sumCount += int.Parse(Data);
  2502. }
  2503. if (FirstDT.Columns[j].ColumnName == "io_qty")
  2504. {
  2505. totalCount += int.Parse(Data);
  2506. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2507. }
  2508. }
  2509. //添加总计行
  2510. if (i == rowNum - 1)
  2511. {
  2512. row1 = sheet2.CreateRow(PaintIndex);
  2513. PaintIndex = PaintIndex + 1;
  2514. for (int j = 0; j < columnNum - 4; j++)
  2515. {
  2516. if (j == 0)
  2517. {
  2518. row1.CreateCell(j);
  2519. row1.Cells[j].CellStyle = styleborder;
  2520. row1.Cells[j].SetCellValue(总计);
  2521. }
  2522. else if (j == columnNum - 6)
  2523. {
  2524. row1.CreateCell(j);
  2525. row1.Cells[j].CellStyle = styleborder;
  2526. row1.Cells[j].SetCellValue(sumCount);
  2527. }
  2528. else if (j == columnNum - 5)
  2529. {
  2530. row1.CreateCell(j);
  2531. row1.Cells[j].CellStyle = styleborder;
  2532. row1.Cells[j].SetCellValue(totalCount);
  2533. }
  2534. else
  2535. {
  2536. row1.CreateCell(j);
  2537. row1.Cells[j].CellStyle = styleborder;
  2538. }
  2539. }
  2540. }
  2541. }
  2542. for (int i = 0; i < sheet2.LastRowNum; i++)
  2543. {
  2544. if (i != 0)
  2545. {
  2546. sheet2.AutoSizeColumn(i);
  2547. sheet2.SetColumnWidth(i, sheet2.GetColumnWidth(i) + 1000);
  2548. }
  2549. }
  2550. //将book的内容写入内存流中返回
  2551. book.Write(ms);
  2552. return ms;
  2553. }
  2554. /// <summary>
  2555. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  2556. /// </summary>
  2557. /// <param name="DataTable"></param>
  2558. /// <returns></returns>
  2559. private MemoryStream DataTableToExcel_LIPUXIN(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  2560. {
  2561. string 小计 = "";
  2562. string 批小计 = "";
  2563. string 总计 = "";
  2564. string 片 = "";
  2565. string companyname = "";
  2566. int ShowBoxIndex = 0;
  2567. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype", "pi_inoutno='" + Inoutno + "'").ToString() == "Chinese")
  2568. {
  2569. 小计 = "小计";
  2570. 总计 = "总计";
  2571. 批小计 = "批小计";
  2572. companyname = "深爱半导体股份有限公司芯片出货清单";
  2573. }
  2574. else
  2575. {
  2576. 批小计 = "BatchTotal";
  2577. 小计 = "total";
  2578. 总计 = "total";
  2579. companyname = "SHENZHEN SI SEMICONDUCTORS CO.,LTD";
  2580. }
  2581. //转换为序列
  2582. CheckBox[] box = conditionbox.ToArray();
  2583. //创建内存流
  2584. MemoryStream ms = new MemoryStream();
  2585. //创建一个Book,相当于一个Excel文件
  2586. HSSFWorkbook book = new HSSFWorkbook();
  2587. //Excel中的Sheet
  2588. ISheet sheet = book.CreateSheet("分页");
  2589. sheet.SetMargin(MarginType.TopMargin, 0.4);
  2590. sheet.SetMargin(MarginType.BottomMargin, 0.4);
  2591. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  2592. sheet.SetMargin(MarginType.RightMargin, 0.4);
  2593. sheet.FitToPage = true;
  2594. sheet.PrintSetup.FitHeight = 200;
  2595. //芯片号需要作为更新盒号的条件
  2596. HSSFFont ffont = (HSSFFont)book.CreateFont();
  2597. ffont.FontName = "宋体";
  2598. //更新箱号
  2599. List<string> pib_id = new List<string>();
  2600. //系统打印箱号
  2601. List<string> pib_outboxcode1 = new List<string>();
  2602. int BoxCode = 1;
  2603. ICellStyle style = book.CreateCellStyle();
  2604. style.VerticalAlignment = VerticalAlignment.Center;
  2605. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  2606. style.SetFont(ffont);
  2607. ICellStyle styleborder = book.CreateCellStyle();
  2608. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2609. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2610. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2611. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2612. styleborder.VerticalAlignment = VerticalAlignment.Center;
  2613. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  2614. styleborder.SetFont(ffont);
  2615. string pi_inoutno = "";
  2616. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  2617. ColumnTitle.FontName = "宋体";
  2618. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  2619. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  2620. ColumnTitleStyle.SetFont(ColumnTitle);
  2621. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2622. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2623. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2624. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2625. List<string> NotShowColumn = new List<string>();
  2626. NotShowColumn.Add("ch_level");
  2627. NotShowColumn.Add("pib_id");
  2628. NotShowColumn.Add("chw_itemname1");
  2629. NotShowColumn.Add("chw_itemname2");
  2630. NotShowColumn.Add("chw_itemname3");
  2631. NotShowColumn.Add("pd_ordercode");
  2632. NotShowColumn.Add("pr_size");
  2633. NotShowColumn.Add("me_desc");
  2634. NotShowColumn.Add("pr_orispeccode");
  2635. NotShowColumn.Add("pr_orispeccode1");
  2636. NotShowColumn.Add("pi_title");
  2637. NotShowColumn.Add("pi_chipouttype");
  2638. NotShowColumn.Add("pi_date");
  2639. int ShowColumnCount = 0;
  2640. //展示的内容列
  2641. //设置列的宽度,根据首行的列的内容的长度来设置
  2642. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  2643. {
  2644. for (int j = 0; j < box.Length; j++)
  2645. {
  2646. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  2647. {
  2648. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  2649. {
  2650. DataTable.Columns.RemoveAt(i);
  2651. break;
  2652. }
  2653. }
  2654. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  2655. {
  2656. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  2657. {
  2658. DataTable.Columns.RemoveAt(i);
  2659. break;
  2660. }
  2661. }
  2662. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  2663. {
  2664. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  2665. {
  2666. DataTable.Columns.RemoveAt(i);
  2667. break;
  2668. }
  2669. }
  2670. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  2671. {
  2672. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  2673. {
  2674. DataTable.Columns.RemoveAt(i);
  2675. break;
  2676. }
  2677. }
  2678. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  2679. {
  2680. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  2681. {
  2682. DataTable.Columns.RemoveAt(i);
  2683. break;
  2684. }
  2685. }
  2686. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  2687. {
  2688. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  2689. {
  2690. DataTable.Columns.RemoveAt(i);
  2691. break;
  2692. }
  2693. }
  2694. if (box[j].Name.ToLower() == "ch_yield" && !box[j].Checked)
  2695. {
  2696. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_yield"))
  2697. {
  2698. DataTable.Columns.RemoveAt(i);
  2699. break;
  2700. }
  2701. }
  2702. }
  2703. }
  2704. //获取行数量和列数量
  2705. int rowNum = DataTable.Rows.Count;
  2706. int columnNum = DataTable.Columns.Count;
  2707. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  2708. IRow row = sheet.CreateRow(0);
  2709. //冻结第一行
  2710. sheet.CreateFreezePane(0, 1, 0, 1);
  2711. row.HeightInPoints = RowHeight;
  2712. //固定第一行
  2713. //row.RowStyle.IsLocked=true;
  2714. //给第一行的标签赋值样式和值
  2715. // ffont.FontHeight = 13;
  2716. row.CreateCell(0);
  2717. row.Cells[0].SetCellValue(" " + companyname);
  2718. row.GetCell(0).CellStyle.SetFont((ffont));
  2719. //ffont.FontHeight = 10;
  2720. //开始绘制的Index
  2721. int PaintIndex = 1;
  2722. int sumCount = 0;
  2723. int totalCount = 0;
  2724. switch (Type)
  2725. {
  2726. case "FixRow":
  2727. //清理系统取出来的数据
  2728. BaseUtil.CleanDataTableData(FirstDT);
  2729. //首页参数拼接
  2730. string First_OrderCode = "";
  2731. string First_Prspec = "";
  2732. string First_Batch = "";
  2733. int NumIndex = 0;
  2734. ArrayList<string> First_WID = new ArrayList<string>();
  2735. for (int i = 0; i < rowNum; i++)
  2736. {
  2737. IRow row1 = sheet.CreateRow(PaintIndex);
  2738. PaintIndex = PaintIndex + 1;
  2739. row1.HeightInPoints = RowHeight;
  2740. //不包含的订单号
  2741. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  2742. {
  2743. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  2744. }
  2745. //不包含的物料型号
  2746. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  2747. {
  2748. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  2749. }
  2750. //不包含扩撒批号
  2751. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  2752. {
  2753. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  2754. }
  2755. //不包含Wafer_id
  2756. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  2757. {
  2758. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  2759. }
  2760. if (i / PageSize >= 1 && i % PageSize == 0)
  2761. {
  2762. DataRow dr = FirstDT.NewRow();
  2763. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  2764. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  2765. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  2766. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  2767. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  2768. dr["pd_ordercode"] = First_OrderCode;
  2769. dr["pr_orispeccode"] = First_Prspec;
  2770. dr["ch_splitbatch"] = First_Batch;
  2771. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  2772. dr["num"] = PageSize;
  2773. dr["io_qty"] = sumCount;
  2774. FirstDT.Rows.Add(dr);
  2775. First_OrderCode = "";
  2776. First_Prspec = "";
  2777. First_Batch = "";
  2778. First_WID.Clear();
  2779. BoxCode = BoxCode + 1;
  2780. for (int j = 0; j < ShowColumnCount; j++)
  2781. {
  2782. row1.CreateCell(j);
  2783. if (j == 0)
  2784. {
  2785. row1.Cells[j].SetCellValue(批小计);
  2786. }
  2787. else if (j == ShowPieceIndex)
  2788. {
  2789. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i) + 片);
  2790. row1.Cells[j].CellStyle = styleborder;
  2791. }
  2792. else if (j == ShowCountIndex)
  2793. {
  2794. row1.Cells[j].SetCellValue(sumCount);
  2795. }
  2796. else if (j == ShowBoxIndex - 4)
  2797. {
  2798. row1.Cells[j].SetCellValue(DataTable.Rows[i - 1]["ch_pbcode"].ToString());
  2799. row1.Cells[j].CellStyle = styleborder;
  2800. }
  2801. row1.Cells[j].CellStyle = styleborder;
  2802. }
  2803. row1 = sheet.CreateRow(PaintIndex);
  2804. PaintIndex = PaintIndex + 1;
  2805. for (int j = 0; j < ShowColumnCount; j++)
  2806. {
  2807. row1.CreateCell(j);
  2808. if (j == 0)
  2809. {
  2810. row1.Cells[j].SetCellValue(小计);
  2811. }
  2812. else if (j == ShowPieceIndex)
  2813. {
  2814. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i) + 片);
  2815. }
  2816. else if (j == ShowCountIndex)
  2817. {
  2818. row1.Cells[j].SetCellValue(sumCount);
  2819. }
  2820. else if (j == ShowBoxIndex - 4)
  2821. {
  2822. row1.Cells[j].SetCellValue(DataTable.Rows[i - 1]["ch_pbcode"].ToString());
  2823. row1.Cells[j].CellStyle = styleborder;
  2824. }
  2825. row1.Cells[j].CellStyle = styleborder;
  2826. }
  2827. sumCount = 0;
  2828. row1 = sheet.CreateRow(PaintIndex);
  2829. sheet.SetRowBreak(PaintIndex - 1);
  2830. sheet.Footer.Center = "第&P页,共&N页";
  2831. PaintIndex = PaintIndex + 1;
  2832. }
  2833. //每次到了页数开始分页
  2834. if (i % PageSize == 0 || i == rowNum - 1)
  2835. {
  2836. //第一行添加客户信息 rownum只有一行的情
  2837. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  2838. {
  2839. for (int j = 0; j < columnNum - 3; j++)
  2840. {
  2841. if (j == 0)
  2842. {
  2843. row1.CreateCell(j);
  2844. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  2845. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  2846. }
  2847. else if (j == ShowDataIndex)
  2848. {
  2849. row1.CreateCell(j);
  2850. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  2851. }
  2852. else
  2853. {
  2854. row1.CreateCell(j);
  2855. }
  2856. row1.GetCell(j).CellStyle = style;
  2857. }
  2858. row1 = sheet.CreateRow(PaintIndex);
  2859. PaintIndex = PaintIndex + 1;
  2860. //第二行添加型号
  2861. for (int j = 0; j < columnNum - 3; j++)
  2862. {
  2863. if (j == 0)
  2864. {
  2865. row1.CreateCell(j);
  2866. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString()
  2867. + "_(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2868. }
  2869. else if (j == ShowSizeIndex)
  2870. {
  2871. row1.CreateCell(j);
  2872. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  2873. }
  2874. else if (j == ShowDataIndex)
  2875. {
  2876. row1.CreateCell(j);
  2877. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  2878. }
  2879. else
  2880. {
  2881. row1.CreateCell(j);
  2882. }
  2883. row1.GetCell(j).CellStyle = style;
  2884. }
  2885. //添加列名
  2886. row1 = sheet.CreateRow(PaintIndex);
  2887. PaintIndex = PaintIndex + 1;
  2888. //计数列所在的索引
  2889. int showcount = 0;
  2890. for (int j = 4; j < columnNum; j++)
  2891. {
  2892. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  2893. {
  2894. showcount = showcount + 1;
  2895. row1.CreateCell(j - 4);
  2896. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2897. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  2898. }
  2899. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2900. {
  2901. showcount = showcount + 1;
  2902. row1.CreateCell(j - 4);
  2903. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2904. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  2905. }
  2906. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  2907. {
  2908. showcount = showcount + 1;
  2909. row1.CreateCell(j - 4);
  2910. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2911. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  2912. }
  2913. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2914. {
  2915. }
  2916. else
  2917. {
  2918. showcount = showcount + 1;
  2919. row1.CreateCell(j - 4);
  2920. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2921. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  2922. }
  2923. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  2924. {
  2925. ShowBoxIndex = j;
  2926. }
  2927. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  2928. {
  2929. NumIndex = j;
  2930. if (ShowCountIndex == NumIndex - 4)
  2931. {
  2932. ShowCountIndex = ShowCountIndex + 1;
  2933. }
  2934. }
  2935. }
  2936. ShowColumnCount = showcount;
  2937. row1 = sheet.CreateRow(PaintIndex);
  2938. PaintIndex = PaintIndex + 1;
  2939. }
  2940. }
  2941. //添加数据内容
  2942. for (int j = 4; j < columnNum; j++)
  2943. {
  2944. string Data = DataTable.Rows[i][j].ToString();
  2945. row1.CreateCell(j - 4);
  2946. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2947. {
  2948. }
  2949. else
  2950. {
  2951. row1.Cells[j - 4].SetCellValue(Data);
  2952. row1.GetCell(j - 4).CellStyle = styleborder;
  2953. }
  2954. if (DataTable.Columns[j].ColumnName == "io_qty")
  2955. {
  2956. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2957. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  2958. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  2959. }
  2960. if (DataTable.Columns[j].ColumnName == "rownum")
  2961. {
  2962. row1.Cells[j - 4].SetCellValue(i + 1);
  2963. }
  2964. if (DataTable.Columns[j].ColumnName == "ch_code")
  2965. {
  2966. sheet.AutoSizeColumn(j - 4);
  2967. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  2968. }
  2969. }
  2970. //固定行号分组的时候自动拼接新的DataTable
  2971. if (i == rowNum - 1)
  2972. {
  2973. DataRow dr = FirstDT.NewRow();
  2974. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  2975. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  2976. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  2977. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  2978. dr["pd_ordercode"] = First_OrderCode;
  2979. dr["pr_orispeccode"] = First_Prspec;
  2980. dr["ch_splitbatch"] = First_Batch;
  2981. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  2982. dr["num"] = (i % PageSize) + 1;
  2983. dr["io_qty"] = sumCount;
  2984. FirstDT.Rows.Add(dr);
  2985. row1 = sheet.CreateRow(PaintIndex);
  2986. PaintIndex = PaintIndex + 1;
  2987. for (int j = 0; j < ShowColumnCount; j++)
  2988. {
  2989. row1.CreateCell(j);
  2990. if (j == 0)
  2991. {
  2992. row1.Cells[j].SetCellValue(批小计);
  2993. }
  2994. else if (j == ShowPieceIndex)
  2995. {
  2996. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize == 0 ? PageSize : (rowNum % PageSize)) + 片);
  2997. row1.Cells[j].CellStyle = styleborder;
  2998. }
  2999. else if (j == ShowBoxIndex - 4)
  3000. {
  3001. row1.Cells[j].SetCellValue(DataTable.Rows[i - 1]["ch_pbcode"].ToString());
  3002. row1.Cells[j].CellStyle = styleborder;
  3003. }
  3004. else if (j == ShowCountIndex)
  3005. {
  3006. row1.Cells[j].SetCellValue(sumCount);
  3007. }
  3008. row1.Cells[j].CellStyle = styleborder;
  3009. }
  3010. row1 = sheet.CreateRow(PaintIndex);
  3011. PaintIndex = PaintIndex + 1;
  3012. for (int j = 0; j < ShowColumnCount; j++)
  3013. {
  3014. row1.CreateCell(j);
  3015. if (j == 0)
  3016. {
  3017. row1.Cells[j].SetCellValue(小计);
  3018. }
  3019. else if (j == ShowPieceIndex)
  3020. {
  3021. row1.Cells[ShowPieceIndex].SetCellValue(rowNum % PageSize + 片);
  3022. row1.Cells[j].CellStyle = styleborder;
  3023. }
  3024. else if (j == ShowBoxIndex - 4)
  3025. {
  3026. row1.Cells[j].SetCellValue(DataTable.Rows[i - 1]["ch_pbcode"].ToString());
  3027. row1.Cells[j].CellStyle = styleborder;
  3028. }
  3029. else if (j == ShowCountIndex)
  3030. {
  3031. row1.Cells[j].SetCellValue(sumCount);
  3032. }
  3033. row1.Cells[j].CellStyle = styleborder;
  3034. }
  3035. row1 = sheet.CreateRow(PaintIndex);
  3036. for (int j = 0; j < columnNum - 3; j++)
  3037. {
  3038. if (j == 0)
  3039. {
  3040. row1.CreateCell(j);
  3041. row1.Cells[j].SetCellValue("备注");
  3042. }
  3043. else if (j == ShowCountIndex)
  3044. {
  3045. row1.CreateCell(j);
  3046. row1.Cells[j].SetCellValue(totalCount);
  3047. }
  3048. else if (j == ShowRemarkPiece)
  3049. {
  3050. row1.CreateCell(j);
  3051. row1.Cells[j].SetCellValue(rowNum + 片);
  3052. }
  3053. else
  3054. {
  3055. row1.CreateCell(j);
  3056. }
  3057. row1.Cells[j].CellStyle = style;
  3058. }
  3059. sheet.SetRowBreak(PaintIndex);
  3060. sheet.Footer.Center = "第&P页,共&N页";
  3061. PaintIndex = PaintIndex + 1;
  3062. }
  3063. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3064. pib_outboxcode1.Add(BoxCode.ToString());
  3065. }
  3066. break;
  3067. case "BatchCode":
  3068. string LastBatchCode = "";
  3069. int PageNum = 0;
  3070. for (int i = 0; i < rowNum; i++)
  3071. {
  3072. IRow row1 = sheet.CreateRow(PaintIndex);
  3073. PaintIndex = PaintIndex + 1;
  3074. row1.HeightInPoints = RowHeight;
  3075. //如果批号不相等的时候
  3076. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  3077. {
  3078. BoxCode = BoxCode + 1;
  3079. for (int j = 0; j < ShowColumnCount; j++)
  3080. {
  3081. row1.CreateCell(j);
  3082. if (j == 0)
  3083. {
  3084. row1.Cells[j].SetCellValue(批小计);
  3085. row1.Cells[j].CellStyle = styleborder;
  3086. }
  3087. else if (j == ShowPieceIndex)
  3088. {
  3089. row1.Cells[ShowPieceIndex].SetCellValue(PageNum - 1 + 片);
  3090. row1.Cells[j].CellStyle = styleborder;
  3091. }
  3092. else if (j == ShowCountIndex)
  3093. {
  3094. row1.Cells[j].SetCellValue(sumCount);
  3095. row1.Cells[j].CellStyle = styleborder;
  3096. }
  3097. else if (j == ShowBoxIndex - 4)
  3098. {
  3099. row1.Cells[j].SetCellValue(DataTable.Rows[i - 1]["ch_pbcode"].ToString());
  3100. row1.Cells[j].CellStyle = styleborder;
  3101. }
  3102. else
  3103. {
  3104. row1.Cells[j].CellStyle = styleborder;
  3105. }
  3106. }
  3107. row1 = sheet.CreateRow(PaintIndex);
  3108. PaintIndex = PaintIndex + 1;
  3109. for (int j = 0; j < ShowColumnCount; j++)
  3110. {
  3111. row1.CreateCell(j);
  3112. if (j == 0)
  3113. {
  3114. row1.Cells[j].SetCellValue(小计);
  3115. row1.Cells[j].CellStyle = styleborder;
  3116. }
  3117. else if (j == ShowPieceIndex)
  3118. {
  3119. row1.Cells[ShowPieceIndex].SetCellValue(PageNum - 1 + 片);
  3120. row1.Cells[j].CellStyle = styleborder;
  3121. }
  3122. else if (j == ShowCountIndex)
  3123. {
  3124. row1.Cells[j].SetCellValue(sumCount);
  3125. row1.Cells[j].CellStyle = styleborder;
  3126. }
  3127. else if (j == ShowBoxIndex - 4)
  3128. {
  3129. row1.Cells[j].SetCellValue(DataTable.Rows[i - 1]["ch_pbcode"].ToString());
  3130. row1.Cells[j].CellStyle = styleborder;
  3131. }
  3132. else
  3133. {
  3134. row1.Cells[j].CellStyle = styleborder;
  3135. }
  3136. }
  3137. sumCount = 0;
  3138. row1 = sheet.CreateRow(PaintIndex);
  3139. sheet.SetRowBreak(PaintIndex - 1);
  3140. sheet.Footer.Center = "第&P页,共&N页";
  3141. PaintIndex = PaintIndex + 1;
  3142. PageNum = 0;
  3143. }
  3144. //每次到了页数开始分页
  3145. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()) || i == rowNum - 1)
  3146. {
  3147. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  3148. //第一行添加客户信息
  3149. //if (i != rowNum - 1)
  3150. {
  3151. for (int j = 0; j < columnNum - 3; j++)
  3152. {
  3153. if (j == 0)
  3154. {
  3155. row1.CreateCell(j);
  3156. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  3157. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  3158. }
  3159. else if (j == ShowDataIndex)
  3160. {
  3161. row1.CreateCell(j);
  3162. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  3163. }
  3164. else
  3165. {
  3166. row1.CreateCell(j);
  3167. }
  3168. row1.GetCell(j).CellStyle = style;
  3169. }
  3170. row1 = sheet.CreateRow(PaintIndex);
  3171. PaintIndex = PaintIndex + 1;
  3172. //第二行添加型号
  3173. for (int j = 0; j < columnNum - 3; j++)
  3174. {
  3175. if (j == 0)
  3176. {
  3177. row1.CreateCell(j);
  3178. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  3179. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  3180. }
  3181. else if (j == ShowSizeIndex)
  3182. {
  3183. row1.CreateCell(j);
  3184. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  3185. }
  3186. else if (j == ShowDataIndex)
  3187. {
  3188. row1.CreateCell(j);
  3189. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  3190. }
  3191. else
  3192. {
  3193. row1.CreateCell(j);
  3194. }
  3195. row1.GetCell(j).CellStyle = style;
  3196. }
  3197. //添加列名
  3198. row1 = sheet.CreateRow(PaintIndex);
  3199. PaintIndex = PaintIndex + 1;
  3200. int showcount = 0;
  3201. for (int j = 4; j < columnNum; j++)
  3202. {
  3203. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  3204. {
  3205. showcount = showcount + 1;
  3206. row1.CreateCell(j - 4);
  3207. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3208. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  3209. }
  3210. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  3211. {
  3212. showcount = showcount + 1;
  3213. row1.CreateCell(j - 4);
  3214. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3215. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  3216. }
  3217. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  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_itemname3"].ToString());
  3223. }
  3224. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3225. {
  3226. }
  3227. else
  3228. {
  3229. showcount = showcount + 1;
  3230. row1.CreateCell(j - 4);
  3231. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3232. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  3233. }
  3234. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  3235. {
  3236. ShowBoxIndex = j;
  3237. }
  3238. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  3239. {
  3240. NumIndex = j;
  3241. if (ShowCountIndex == NumIndex - 4)
  3242. {
  3243. ShowCountIndex = ShowCountIndex + 1;
  3244. }
  3245. }
  3246. }
  3247. ShowColumnCount = showcount;
  3248. row1 = sheet.CreateRow(PaintIndex);
  3249. PaintIndex = PaintIndex + 1;
  3250. }
  3251. }
  3252. //添加数据内容
  3253. for (int j = 4; j < columnNum; j++)
  3254. {
  3255. string Data = DataTable.Rows[i][j].ToString();
  3256. row1.CreateCell(j - 4);
  3257. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3258. {
  3259. }
  3260. else
  3261. {
  3262. row1.Cells[j - 4].SetCellValue(Data);
  3263. row1.GetCell(j - 4).CellStyle = styleborder;
  3264. }
  3265. if (DataTable.Columns[j].ColumnName == "io_qty")
  3266. {
  3267. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3268. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  3269. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  3270. }
  3271. if (DataTable.Columns[j].ColumnName == "rownum")
  3272. {
  3273. row1.Cells[j - 4].SetCellValue(i + 1);
  3274. }
  3275. if (DataTable.Columns[j].ColumnName == "ch_code")
  3276. {
  3277. sheet.AutoSizeColumn(j - 4);
  3278. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  3279. }
  3280. }
  3281. if (i == rowNum - 1)
  3282. {
  3283. row1 = sheet.CreateRow(PaintIndex);
  3284. PaintIndex = PaintIndex + 1;
  3285. for (int j = 0; j < ShowColumnCount; j++)
  3286. {
  3287. row1.CreateCell(j);
  3288. if (j == 0)
  3289. {
  3290. row1.Cells[j].SetCellValue(批小计);
  3291. row1.Cells[j].CellStyle = styleborder;
  3292. }
  3293. else if (j == ShowPieceIndex)
  3294. {
  3295. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  3296. row1.Cells[j].CellStyle = styleborder;
  3297. }
  3298. else if (j == ShowCountIndex)
  3299. {
  3300. row1.Cells[j].SetCellValue(sumCount);
  3301. row1.Cells[j].CellStyle = styleborder;
  3302. }
  3303. else
  3304. {
  3305. row1.Cells[j].CellStyle = styleborder;
  3306. }
  3307. }
  3308. row1 = sheet.CreateRow(PaintIndex);
  3309. PaintIndex = PaintIndex + 1;
  3310. for (int j = 0; j < ShowColumnCount; j++)
  3311. {
  3312. row1.CreateCell(j);
  3313. if (j == 0)
  3314. {
  3315. row1.Cells[j].SetCellValue(小计);
  3316. row1.Cells[j].CellStyle = styleborder;
  3317. }
  3318. else if (j == ShowPieceIndex)
  3319. {
  3320. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  3321. row1.Cells[j].CellStyle = styleborder;
  3322. }
  3323. else if (j == ShowCountIndex)
  3324. {
  3325. row1.Cells[j].SetCellValue(sumCount);
  3326. row1.Cells[j].CellStyle = styleborder;
  3327. }
  3328. else
  3329. {
  3330. row1.Cells[j].CellStyle = styleborder;
  3331. }
  3332. }
  3333. //创建备注内容
  3334. row1 = sheet.CreateRow(PaintIndex);
  3335. for (int j = 0; j < columnNum - 3; j++)
  3336. {
  3337. if (j == 0)
  3338. {
  3339. row1.CreateCell(j);
  3340. row1.Cells[j].SetCellValue("备注");
  3341. }
  3342. else if (j == ShowCountIndex)
  3343. {
  3344. row1.CreateCell(j);
  3345. row1.Cells[j].SetCellValue(totalCount);
  3346. }
  3347. else if (j == ShowRemarkPiece)
  3348. {
  3349. row1.CreateCell(j);
  3350. row1.Cells[j].SetCellValue(rowNum + 片);
  3351. }
  3352. else
  3353. {
  3354. row1.CreateCell(j);
  3355. }
  3356. row1.Cells[j].CellStyle = style;
  3357. }
  3358. sheet.SetRowBreak(PaintIndex);
  3359. sheet.Footer.Center = "第&P页,共&N页";
  3360. PaintIndex = PaintIndex + 1;
  3361. PageNum = 0;
  3362. }
  3363. PageNum = PageNum + 1;
  3364. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3365. pib_outboxcode1.Add(BoxCode.ToString());
  3366. }
  3367. break;
  3368. case "BoxCode":
  3369. string LastBoxCode = "";
  3370. int PageNum1 = 0;
  3371. for (int i = 0; i < rowNum; i++)
  3372. {
  3373. IRow row1 = sheet.CreateRow(PaintIndex);
  3374. PaintIndex = PaintIndex + 1;
  3375. row1.HeightInPoints = RowHeight;
  3376. //如果批号不相等的时候
  3377. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  3378. {
  3379. BoxCode = BoxCode + 1;
  3380. for (int j = 0; j < ShowColumnCount; j++)
  3381. {
  3382. row1.CreateCell(j);
  3383. if (j == 0)
  3384. {
  3385. row1.Cells[j].SetCellValue(批小计);
  3386. row1.Cells[j].CellStyle = styleborder;
  3387. }
  3388. else if (j == ShowPieceIndex)
  3389. {
  3390. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3391. row1.Cells[j].CellStyle = styleborder;
  3392. }
  3393. else if (j == ShowCountIndex)
  3394. {
  3395. row1.Cells[j].SetCellValue(sumCount);
  3396. row1.Cells[j].CellStyle = styleborder;
  3397. }
  3398. else if (j == ShowBoxIndex - 4)
  3399. {
  3400. row1.Cells[j].SetCellValue(DataTable.Rows[i - 1]["ch_pbcode"].ToString());
  3401. row1.Cells[j].CellStyle = styleborder;
  3402. }
  3403. else
  3404. {
  3405. row1.Cells[j].CellStyle = styleborder;
  3406. }
  3407. }
  3408. row1 = sheet.CreateRow(PaintIndex);
  3409. PaintIndex = PaintIndex + 1;
  3410. for (int j = 0; j < ShowColumnCount; j++)
  3411. {
  3412. row1.CreateCell(j);
  3413. if (j == 0)
  3414. {
  3415. row1.Cells[j].SetCellValue(小计);
  3416. row1.Cells[j].CellStyle = styleborder;
  3417. }
  3418. else if (j == ShowPieceIndex)
  3419. {
  3420. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3421. row1.Cells[j].CellStyle = styleborder;
  3422. }
  3423. else if (j == ShowCountIndex)
  3424. {
  3425. row1.Cells[j].SetCellValue(sumCount);
  3426. row1.Cells[j].CellStyle = styleborder;
  3427. }
  3428. else if (j == ShowBoxIndex - 4)
  3429. {
  3430. row1.Cells[j].SetCellValue(DataTable.Rows[i - 1]["ch_pbcode"].ToString());
  3431. row1.Cells[j].CellStyle = styleborder;
  3432. }
  3433. else
  3434. {
  3435. row1.Cells[j].CellStyle = styleborder;
  3436. }
  3437. }
  3438. sumCount = 0;
  3439. row1 = sheet.CreateRow(PaintIndex);
  3440. sheet.SetRowBreak(PaintIndex - 1);
  3441. sheet.Footer.Center = "第&P页,共&N页";
  3442. PaintIndex = PaintIndex + 1;
  3443. PageNum1 = 0;
  3444. }
  3445. //每次到了页数开始分页
  3446. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  3447. {
  3448. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  3449. //第一行添加客户信息
  3450. //if (i != rowNum - 1)
  3451. {
  3452. for (int j = 0; j < columnNum - 3; j++)
  3453. {
  3454. if (j == 0)
  3455. {
  3456. row1.CreateCell(j);
  3457. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  3458. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  3459. }
  3460. else if (j == ShowDataIndex)
  3461. {
  3462. row1.CreateCell(j);
  3463. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  3464. }
  3465. else
  3466. {
  3467. row1.CreateCell(j);
  3468. }
  3469. row1.GetCell(j).CellStyle = style;
  3470. }
  3471. row1 = sheet.CreateRow(PaintIndex);
  3472. PaintIndex = PaintIndex + 1;
  3473. //第二行添加型号
  3474. for (int j = 0; j < columnNum - 3; j++)
  3475. {
  3476. if (j == 0)
  3477. {
  3478. row1.CreateCell(j);
  3479. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  3480. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  3481. }
  3482. else if (j == ShowSizeIndex)
  3483. {
  3484. row1.CreateCell(j);
  3485. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  3486. }
  3487. else if (j == ShowDataIndex)
  3488. {
  3489. row1.CreateCell(j);
  3490. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  3491. }
  3492. else
  3493. {
  3494. row1.CreateCell(j);
  3495. }
  3496. }
  3497. //添加列名
  3498. row1 = sheet.CreateRow(PaintIndex);
  3499. PaintIndex = PaintIndex + 1;
  3500. int showcount = 0;
  3501. for (int j = 4; j < columnNum; j++)
  3502. {
  3503. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  3504. {
  3505. showcount = showcount + 1;
  3506. row1.CreateCell(j - 4);
  3507. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3508. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname1"].ToString());
  3509. }
  3510. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  3511. {
  3512. showcount = showcount + 1;
  3513. row1.CreateCell(j - 4);
  3514. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3515. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname2"].ToString());
  3516. }
  3517. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  3518. {
  3519. showcount = showcount + 1;
  3520. row1.CreateCell(j - 4);
  3521. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3522. row1.Cells[j - 4].SetCellValue(DataTable.Rows[i]["chw_itemname3"].ToString());
  3523. }
  3524. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3525. {
  3526. }
  3527. else
  3528. {
  3529. showcount = showcount + 1;
  3530. row1.CreateCell(j - 4);
  3531. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3532. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  3533. }
  3534. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  3535. {
  3536. ShowBoxIndex = j;
  3537. }
  3538. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  3539. {
  3540. NumIndex = j;
  3541. if (ShowCountIndex == NumIndex - 4)
  3542. {
  3543. ShowCountIndex = ShowCountIndex + 1;
  3544. }
  3545. }
  3546. }
  3547. ShowColumnCount = showcount;
  3548. row1 = sheet.CreateRow(PaintIndex);
  3549. PaintIndex = PaintIndex + 1;
  3550. }
  3551. }
  3552. //添加数据内容
  3553. for (int j = 4; j < columnNum; j++)
  3554. {
  3555. string Data = DataTable.Rows[i][j].ToString();
  3556. row1.CreateCell(j - 4);
  3557. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3558. {
  3559. }
  3560. else
  3561. {
  3562. row1.Cells[j - 4].SetCellValue(Data);
  3563. row1.GetCell(j - 4).CellStyle = styleborder;
  3564. }
  3565. if (DataTable.Columns[j].ColumnName == "io_qty")
  3566. {
  3567. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3568. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  3569. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  3570. }
  3571. if (DataTable.Columns[j].ColumnName == "rownum")
  3572. {
  3573. row1.Cells[j - 4].SetCellValue(i + 1);
  3574. }
  3575. if (DataTable.Columns[j].ColumnName == "ch_code")
  3576. {
  3577. sheet.AutoSizeColumn(j - 4);
  3578. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  3579. }
  3580. }
  3581. if (i == rowNum - 1)
  3582. {
  3583. PageNum1 = PageNum1 + 1;
  3584. row1 = sheet.CreateRow(PaintIndex);
  3585. PaintIndex = PaintIndex + 1;
  3586. for (int j = 0; j < ShowColumnCount; j++)
  3587. {
  3588. row1.CreateCell(j);
  3589. if (j == 0)
  3590. {
  3591. row1.Cells[j].SetCellValue(批小计);
  3592. row1.Cells[j].CellStyle = styleborder;
  3593. }
  3594. else if (j == ShowPieceIndex)
  3595. {
  3596. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3597. row1.Cells[j].CellStyle = styleborder;
  3598. }
  3599. else if (j == ShowCountIndex)
  3600. {
  3601. row1.Cells[j].SetCellValue(sumCount);
  3602. row1.Cells[j].CellStyle = styleborder;
  3603. }
  3604. else if (j == ShowBoxIndex - 4)
  3605. {
  3606. row1.Cells[j].SetCellValue(DataTable.Rows[i - 1]["ch_pbcode"].ToString());
  3607. row1.Cells[j].CellStyle = styleborder;
  3608. }
  3609. else
  3610. {
  3611. row1.Cells[j].CellStyle = styleborder;
  3612. }
  3613. }
  3614. row1 = sheet.CreateRow(PaintIndex);
  3615. PaintIndex = PaintIndex + 1;
  3616. for (int j = 0; j < ShowColumnCount; j++)
  3617. {
  3618. row1.CreateCell(j);
  3619. if (j == 0)
  3620. {
  3621. row1.Cells[j].SetCellValue(小计);
  3622. row1.Cells[j].CellStyle = styleborder;
  3623. }
  3624. else if (j == ShowPieceIndex)
  3625. {
  3626. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  3627. row1.Cells[j].CellStyle = styleborder;
  3628. }
  3629. else if (j == ShowCountIndex)
  3630. {
  3631. row1.Cells[j].SetCellValue(sumCount);
  3632. row1.Cells[j].CellStyle = styleborder;
  3633. }
  3634. else if (j == ShowBoxIndex - 4)
  3635. {
  3636. row1.Cells[j].SetCellValue(DataTable.Rows[i - 1]["ch_pbcode"].ToString());
  3637. row1.Cells[j].CellStyle = styleborder;
  3638. }
  3639. else
  3640. {
  3641. row1.Cells[j].CellStyle = styleborder;
  3642. }
  3643. }
  3644. row1 = sheet.CreateRow(PaintIndex);
  3645. for (int j = 0; j < columnNum - 3; j++)
  3646. {
  3647. if (j == 0)
  3648. {
  3649. row1.CreateCell(j);
  3650. row1.Cells[j].SetCellValue("备注");
  3651. }
  3652. else if (j == ShowCountIndex)
  3653. {
  3654. row1.CreateCell(j);
  3655. row1.Cells[j].SetCellValue(totalCount);
  3656. }
  3657. else if (j == ShowRemarkPiece)
  3658. {
  3659. row1.CreateCell(j);
  3660. row1.Cells[j].SetCellValue(rowNum + 片);
  3661. }
  3662. else
  3663. {
  3664. row1.CreateCell(j);
  3665. }
  3666. row1.Cells[j].CellStyle = style;
  3667. }
  3668. sheet.SetRowBreak(PaintIndex);
  3669. sheet.Footer.Center = "第&P页,共&N页";
  3670. PaintIndex = PaintIndex + 1;
  3671. PageNum1 = 0;
  3672. }
  3673. PageNum1 = PageNum1 + 1;
  3674. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3675. pib_outboxcode1.Add(BoxCode.ToString());
  3676. }
  3677. break;
  3678. default:
  3679. break;
  3680. }
  3681. 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());
  3682. //删除下载链接再重新插入
  3683. HttpHandler.GenDownLoadLinK(Inoutno);
  3684. //填充首页
  3685. sumCount = 0;
  3686. totalCount = 0;
  3687. PaintIndex = 1;
  3688. ISheet sheet2 = book.CreateSheet("首页");
  3689. row = sheet2.CreateRow(0);
  3690. row.CreateCell(0);
  3691. row.Cells[0].SetCellValue(" " + companyname);
  3692. row.GetCell(0).CellStyle = style;
  3693. rowNum = FirstDT.Rows.Count;
  3694. //不需要显示的列移除
  3695. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  3696. {
  3697. for (int j = 0; j < box.Length; j++)
  3698. {
  3699. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  3700. {
  3701. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  3702. {
  3703. FirstDT.Columns.RemoveAt(i);
  3704. }
  3705. }
  3706. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  3707. {
  3708. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  3709. {
  3710. FirstDT.Columns.RemoveAt(i);
  3711. }
  3712. }
  3713. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  3714. {
  3715. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  3716. {
  3717. FirstDT.Columns.RemoveAt(i);
  3718. }
  3719. }
  3720. }
  3721. }
  3722. columnNum = FirstDT.Columns.Count;
  3723. for (int i = 0; i < rowNum; i++)
  3724. {
  3725. IRow row1 = sheet2.CreateRow(PaintIndex);
  3726. PaintIndex = PaintIndex + 1;
  3727. row1.HeightInPoints = RowHeight;
  3728. //只需要绘制一行
  3729. if (i == 0)
  3730. {
  3731. for (int j = 0; j < columnNum - 3; j++)
  3732. {
  3733. if (j == 0)
  3734. {
  3735. row1.CreateCell(j);
  3736. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString());
  3737. }
  3738. else if (j > 5 && j == columnNum - 5)
  3739. {
  3740. row1.CreateCell(j);
  3741. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  3742. }
  3743. else if (columnNum > 5 && j == columnNum - 5)
  3744. {
  3745. row1.CreateCell(j);
  3746. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  3747. }
  3748. else
  3749. {
  3750. row1.CreateCell(j);
  3751. }
  3752. row1.GetCell(j).CellStyle = style;
  3753. }
  3754. row1 = sheet2.CreateRow(PaintIndex);
  3755. PaintIndex = PaintIndex + 1;
  3756. //第二行添加型号
  3757. for (int j = 0; j < columnNum - 3; j++)
  3758. {
  3759. if (j == 0)
  3760. {
  3761. row1.CreateCell(j);
  3762. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString());
  3763. }
  3764. else if (j > 5 && j == columnNum - 5)
  3765. {
  3766. row1.CreateCell(j);
  3767. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  3768. }
  3769. else if (columnNum > 5 && j == columnNum - 5)
  3770. {
  3771. row1.CreateCell(j);
  3772. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  3773. }
  3774. else
  3775. {
  3776. row1.CreateCell(j);
  3777. }
  3778. row1.GetCell(j).CellStyle = style;
  3779. }
  3780. row1 = sheet2.CreateRow(PaintIndex);
  3781. PaintIndex = PaintIndex + 1;
  3782. //添加列名
  3783. for (int j = 4; j < columnNum; j++)
  3784. {
  3785. row1.CreateCell(j - 4);
  3786. row1.Cells[j - 4].CellStyle = styleborder;
  3787. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  3788. }
  3789. row1 = sheet2.CreateRow(PaintIndex);
  3790. PaintIndex = PaintIndex + 1;
  3791. }
  3792. //添加数据内容
  3793. for (int j = 4; j < columnNum; j++)
  3794. {
  3795. string Data = FirstDT.Rows[i][j].ToString();
  3796. row1.CreateCell(j - 4);
  3797. row1.Cells[j - 4].SetCellValue(Data);
  3798. row1.GetCell(j - 4).CellStyle = styleborder;
  3799. if (FirstDT.Columns[j].ColumnName == "num")
  3800. {
  3801. sumCount += int.Parse(Data);
  3802. }
  3803. if (FirstDT.Columns[j].ColumnName == "io_qty")
  3804. {
  3805. totalCount += int.Parse(Data);
  3806. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3807. }
  3808. }
  3809. //添加总计行
  3810. if (i == rowNum - 1)
  3811. {
  3812. row1 = sheet2.CreateRow(PaintIndex);
  3813. PaintIndex = PaintIndex + 1;
  3814. for (int j = 0; j < columnNum - 4; j++)
  3815. {
  3816. if (j == 0)
  3817. {
  3818. row1.CreateCell(j);
  3819. row1.Cells[j].CellStyle = styleborder;
  3820. row1.Cells[j].SetCellValue(总计);
  3821. }
  3822. else if (j == columnNum - 6)
  3823. {
  3824. row1.CreateCell(j);
  3825. row1.Cells[j].CellStyle = styleborder;
  3826. row1.Cells[j].SetCellValue(sumCount);
  3827. }
  3828. else if (j == columnNum - 5)
  3829. {
  3830. row1.CreateCell(j);
  3831. row1.Cells[j].CellStyle = styleborder;
  3832. row1.Cells[j].SetCellValue(totalCount);
  3833. }
  3834. else
  3835. {
  3836. row1.CreateCell(j);
  3837. row1.Cells[j].CellStyle = styleborder;
  3838. }
  3839. }
  3840. }
  3841. }
  3842. //将book的内容写入内存流中返回
  3843. book.Write(ms);
  3844. return ms;
  3845. }
  3846. }
  3847. }