OrderSendBillExport.cs 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Abp.Extensions;
  8. using Abp.Timing;
  9. using IwbZero.IdentityFramework;
  10. using NPOI.HSSF.UserModel;
  11. using NPOI.HSSF.Util;
  12. using NPOI.SS.UserModel;
  13. using NPOI.SS.Util;
  14. using NPOI.XSSF.UserModel;
  15. using ShwasherSys.Common.Dto;
  16. using ShwasherSys.CustomerInfo;
  17. using ShwasherSys.Inspection;
  18. using ShwasherSys.OrderSendInfo;
  19. using static System.Double;
  20. namespace ShwasherSys.Common
  21. {
  22. public class OrderSendBillExport
  23. {
  24. /// <summary>
  25. /// 艾维尼尔森(伍尔特(上海)工业紧固件有限公司浙江分公司)
  26. /// </summary>
  27. /// <param name="bill"></param>
  28. /// <param name="orderSends"></param>
  29. /// <param name="customer"></param>
  30. /// <param name="templateInfo"></param>
  31. /// <returns></returns>
  32. //public string ExportTempAwens(OrderSendBill bill,List<ViewOrderSend> orderSends,Customer customer,TemplateInfo templateInfo)
  33. //{
  34. // string path = AppDomain.CurrentDomain.BaseDirectory +templateInfo.FilePath;
  35. // var savePath = "Download/Excel/OrderSendBill";
  36. // var work = ExcelHelper.CreateWorkBook07(path);
  37. // var sheet1 = work.GetSheet("Sheet1");
  38. // sheet1.GenerateCell(7, 2).SetCellValue(bill.SendDate?.ToString("D"));
  39. // sheet1.GenerateCell(9, 2).SetCellValue("");
  40. // int index = 0;
  41. // foreach (var send in orderSends)
  42. // {
  43. // sheet1.GenerateCell(19+index, 1).SetCellValue(send.StockNo);
  44. // sheet1.GenerateCell(19+index, 2).SetCellValue(send.PartNo);
  45. // sheet1.GenerateCell(19+index, 3).SetCellValue((send.Model??"")+","+(send.ProductName ?? "") + ","+(send.SurfaceColor ?? "") + ","+(send.Rigidity ?? ""));
  46. // sheet1.GenerateCell(19+index, 4).SetCellValue(send.ProductBatchNum);
  47. // var sendQuantity = Math.Floor(send.SendQuantity * 1000) / 1000;//发货数量
  48. // var quantityPerPack = Math.Floor((send.QuantityPerPack ?? 0)*1000)/1000;
  49. // quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  50. // decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  51. // var sysl = sendQuantity - quantityPerPack * packageCount;
  52. // sheet1.GenerateCell(19+index, 5).SetValue<decimal>(sendQuantity*1000);
  53. // sheet1.GenerateCell(19+index, 8).SetValue<decimal>(quantityPerPack * 1000);
  54. // sheet1.GenerateCell(19+index, 9).SetValue<decimal>(packageCount);
  55. // sheet1.GenerateCell(19+index, 10).SetValue<decimal>(sysl * 1000);
  56. // index++;
  57. // }
  58. // var fileName = $"艾维尼尔森-{Clock.Now:yyMMddHHmmss}.xlsx";
  59. // var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  60. // if (!result.IsNullOrEmpty())
  61. // {
  62. // //CheckErrors(IwbIdentityResult.Failed(result));
  63. // return null;
  64. // }
  65. // return $"/{savePath}/{fileName}";
  66. //}
  67. public void ExportTempAwens(OrderSendMiniExcelDto miniValue)
  68. {
  69. miniValue.Ex1 = miniValue.SendDate?.ToString("D");
  70. foreach (var send in miniValue.send)
  71. {
  72. send.SendQuantity = send.SendQuantity * 1000;
  73. send.QuantityPerPack = send.QuantityPerPack * 1000;
  74. send.Sysl = send.Sysl * 1000;
  75. }
  76. }
  77. /// <summary>
  78. /// 伍尔特贸易有限公司
  79. /// </summary>
  80. /// <param name="bill"></param>
  81. /// <param name="orderSends"></param>
  82. /// <param name="customer"></param>
  83. /// <param name="templateInfo"></param>
  84. /// <returns></returns>
  85. //public string ExportTempWET(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer, TemplateInfo templateInfo)
  86. // {
  87. // string path = AppDomain.CurrentDomain.BaseDirectory + templateInfo.FilePath;
  88. // var savePath = "Download/Excel/OrderSendBill";
  89. // var work = ExcelHelper.CreateWorkBook07(path);
  90. // var sheet1 = work.GetSheet("Sheet1");
  91. // sheet1.GenerateCell(5, 2).SetCellValue(customer.CustomerName);
  92. // sheet1.GenerateCell(7, 2).SetCellValue(bill.SendDate?.ToString("D"));
  93. // sheet1.GenerateCell(9, 2).SetCellValue("");
  94. // int index = 0;
  95. // foreach (var send in orderSends)
  96. // {
  97. // sheet1.GenerateCell(19 + index, 1).SetCellValue(send.StockNo);
  98. // sheet1.GenerateCell(19 + index, 2).SetCellValue(send.PartNo);
  99. // sheet1.GenerateCell(19 + index, 3).SetCellValue((send.Model ?? "") + "," + (send.ProductName ?? "") + "," + (send.SurfaceColor ?? "") + "," + (send.Rigidity ?? ""));
  100. // sheet1.GenerateCell(19 + index, 4).SetCellValue(send.ProductBatchNum);
  101. // var sendQuantity = Math.Floor(send.SendQuantity * 1000) / 1000;//发货数量
  102. // var quantityPerPack = Math.Floor((send.QuantityPerPack ?? 0) * 1000) / 1000;
  103. // quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  104. // decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  105. // var sysl = sendQuantity - quantityPerPack * packageCount;
  106. // sheet1.GenerateCell(19 + index, 5).SetValue<decimal>(sendQuantity * 1000);
  107. // sheet1.GenerateCell(19 + index, 8).SetValue<decimal>(quantityPerPack * 1000);
  108. // sheet1.GenerateCell(19 + index, 9).SetValue<decimal>(packageCount);
  109. // sheet1.GenerateCell(19 + index, 10).SetValue<decimal>(sysl * 1000);
  110. // index++;
  111. // }
  112. // var fileName = $"伍尔特贸易有限公司-{Clock.Now:yyMMddHHmmss}.xlsx";
  113. // var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  114. // if (!result.IsNullOrEmpty())
  115. // {
  116. // //CheckErrors(IwbIdentityResult.Failed(result));
  117. // return null;
  118. // }
  119. // return $"/{savePath}/{fileName}";
  120. // }
  121. public void ExportTempWET(OrderSendMiniExcelDto miniValue)
  122. {
  123. miniValue.Ex1 = miniValue.SendDate?.ToString("D");
  124. foreach (var send in miniValue.send)
  125. {
  126. send.SendQuantity = send.SendQuantity * 1000;
  127. send.QuantityPerPack = send.QuantityPerPack * 1000;
  128. send.Sysl = send.Sysl * 1000;
  129. }
  130. }
  131. /// <summary>
  132. /// 美国柏中
  133. /// </summary>
  134. /// <param name="bill"></param>
  135. /// <param name="orderSends"></param>
  136. /// <param name="customer"></param>
  137. /// <param name="templateInfo"></param>
  138. /// <returns></returns>
  139. //public string ExportTempMgbz(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer, TemplateInfo templateInfo)
  140. //{
  141. // string path = AppDomain.CurrentDomain.BaseDirectory + templateInfo.FilePath;
  142. // var savePath = "Download/Excel/OrderSendBill";
  143. // var work = ExcelHelper.CreateWorkBook07(path);
  144. // var sheet1 = work.GetSheet("Sheet1");
  145. // sheet1.GenerateCell(5, 1).SetCellValue("发货日期"+bill.SendDate?.ToString("yyyy-MM-dd"));
  146. // for (int i = 8; i <= 14; i++)
  147. // {
  148. // sheet1.RemoveRow(sheet1.GenerateRow(i));
  149. // //RemoveMergedRegion(sheet1, i);
  150. // }
  151. // for (int i = 0; i < 6; i++)
  152. // {
  153. // RemoveMergedRegion(sheet1, 8 + i);
  154. // }
  155. // int index = 0;
  156. // decimal totalCount = 0;
  157. // decimal allTotalPrice = 0;
  158. // ICellStyle style1 = SetCellStyle(work,fontHeightInPoints:10,horizontalAlignment:HorizontalAlignment.Left);
  159. // ICellStyle style11 = SetCellStyle(work, boldWeight: (short)FontBoldWeight.Normal,fontHeightInPoints:10);
  160. // foreach (var send in orderSends)
  161. // {
  162. // sheet1.GenerateCell(7 + index, 1).SetValue<int>(index+1, style1);
  163. // sheet1.GenerateCell(7 + index, 2).SetValue(send.StockNo??"", style11);
  164. // sheet1.GenerateCell(7 + index, 3).SetValue(send.PartNo??"", style11);
  165. // sheet1.GenerateCell(7 + index, 4).SetValue(send.ProductName??"", style11);
  166. // sheet1.GenerateCell(7 + index, 5).SetValue(send.SurfaceColor??"", style11);
  167. // sheet1.GenerateCell(7 + index, 6).SetValue<decimal>("", style11);
  168. // var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  169. // sheet1.GenerateCell(7 + index, 7).SetValue<decimal>(sendQuantity * 1000, style11);
  170. // totalCount += sendQuantity * 1000;
  171. // sheet1.GenerateCell(7 + index, 8).SetValue<decimal>(send.Price / 10, style11);
  172. // var afterTotalPrice = send.AfterTaxPrice * send.SendQuantity;
  173. // sheet1.GenerateCell(7 + index, 9).SetValue<decimal>(afterTotalPrice, style11);
  174. // allTotalPrice += afterTotalPrice;
  175. // sheet1.GenerateCell(7 + index, 10).SetValue(send.ProductBatchNum??"", style11);
  176. // index++;
  177. // }
  178. // ICellStyle style2 = SetCellStyle(work, fontHeightInPoints: 11);
  179. // ICellStyle style3 = SetCellStyle(work,fillBackgroundColor: (short)ColorType.Yellow,borderStyle:BorderStyle.None, fontHeightInPoints: 9);
  180. // ICellStyle style4 = SetCellStyle(work,fillBackgroundColor: (short)ColorType.Yellow, boldWeight: (short)FontBoldWeight.Normal, fontHeightInPoints: 9);
  181. // ICellStyle style5 = SetCellStyle(work,fillBackgroundColor: (short)ColorType.Yellow, fontHeightInPoints: 11,horizontalAlignment: HorizontalAlignment.Left);
  182. // sheet1.GenerateCell(7 + index, 1).SetValue("", style2);
  183. // sheet1.GenerateCell(7 + index, 2).SetValue("合计", style2);
  184. // sheet1.GenerateCell(7 + index, 3).SetValue("", style2);
  185. // sheet1.GenerateCell(7 + index, 4).SetValue("", style2);
  186. // sheet1.GenerateCell(7 + index, 5).SetValue("", style2);
  187. // sheet1.GenerateCell(7 + index, 6).SetValue("", style2);
  188. // sheet1.GenerateCell(7 + index, 7).SetValue<decimal>(totalCount, style2);
  189. // sheet1.GenerateCell(7 + index, 8).SetValue("", style2);
  190. // sheet1.GenerateCell(7 + index, 9).SetValue<decimal>(allTotalPrice, style2);
  191. // sheet1.GenerateCell(7 + index, 10).SetValue("", style2);
  192. // for (int i =9; i <= 14; i++)
  193. // {
  194. // sheet1.GenerateCell(i + index, 1).SetValue("", style3);
  195. // sheet1.GenerateCell(i + index, 2).SetValue("", style3);
  196. // sheet1.GenerateCell(i + index, 3).SetValue("", style3);
  197. // sheet1.GenerateCell(i + index, 4).SetValue("", style5);
  198. // sheet1.GenerateCell(i + index, 5).SetValue("", style5);
  199. // sheet1.GenerateCell(i + index, 6).SetValue("", style4);
  200. // sheet1.MergedRegion(i + index, i + index, 7, 8);
  201. // sheet1.GenerateCell(i + index, 7).SetValue("", style4);
  202. // sheet1.GenerateCell(i + index, 8).SetValue("", style4);
  203. // sheet1.GenerateCell(i + index, 9).SetValue("", style3);
  204. // }
  205. // sheet1.GenerateCell(9 + index, 4).SetValue("品名:");
  206. // sheet1.GenerateCell(9 + index, 6).SetValue("重量 KG");
  207. // sheet1.GenerateCell(9 + index, 7).SetValue("数量 PCS");
  208. // sheet1.GenerateCell(10 + index, 4).SetValue("垫片类:");
  209. // sheet1.GenerateCell(10 + index, 6).SetValue("垫片类:");
  210. // sheet1.GenerateCell(11 + index, 4).SetValue("总数量");
  211. // sheet1.GenerateCell(11 + index, 6).SetValue("总数量");
  212. // sheet1.GenerateCell(11 + index,7).SetValue(totalCount+"PCS");
  213. // sheet1.GenerateCell(12 + index, 4).SetValue("总重量:");
  214. // sheet1.GenerateCell(12 + index, 6).SetValue("总重量公斤:");
  215. // sheet1.GenerateCell(13 + index, 4).SetValue("总件数:");
  216. // sheet1.GenerateCell(13 + index, 6).SetValue("总件数:");
  217. // sheet1.GenerateCell(14 + index, 4).SetValue("送货司机:");
  218. // sheet1.GenerateCell(14 + index, 6).SetValue("车牌号:");
  219. // var fileName = $"柏中专用-{Clock.Now:yyMMddHHmmss}.xlsx";
  220. // var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  221. // if (!result.IsNullOrEmpty())
  222. // {
  223. // //CheckErrors(IwbIdentityResult.Failed(result));
  224. // return null;
  225. // }
  226. // return $"/{savePath}/{fileName}";
  227. //}
  228. public void ExportTempMgbz(OrderSendMiniExcelDto miniValue)
  229. {
  230. miniValue.Ex1 = miniValue.SendDate?.ToString("yyyy-MM-dd");
  231. decimal allTotalPrice = 0, allSendQuantity = 0;
  232. foreach (var send in miniValue.send)
  233. {
  234. send.Price = send.Price / 10;
  235. send.TotalPrice = send.AfterTaxPrice * send.SendQuantity;
  236. allTotalPrice += send.TotalPrice;
  237. send.SendQuantity = send.SendQuantity * 1000;
  238. allSendQuantity += send.SendQuantity;
  239. }
  240. miniValue.AllSendQuantity = allSendQuantity;
  241. miniValue.AllTotalPrice = allTotalPrice;
  242. }
  243. /// <summary>
  244. /// 天津柏中
  245. /// </summary>
  246. /// <param name="bill"></param>
  247. /// <param name="orderSends"></param>
  248. /// <param name="customer"></param>
  249. /// <param name="templateInfo"></param>
  250. /// <returns></returns>
  251. //public string ExportTempTjbz(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer, TemplateInfo templateInfo)
  252. //{
  253. // string path = AppDomain.CurrentDomain.BaseDirectory + templateInfo.FilePath;
  254. // var savePath = "Download/Excel/OrderSendBill";
  255. // var work = ExcelHelper.CreateWorkBook07(path);
  256. // var sheet1 = work.GetSheet("Sheet1");
  257. // sheet1.GenerateCell(5, 1).SetCellValue("发货日期" + bill.SendDate?.ToString("yyyy-MM-dd"));
  258. // for (int i = 8; i <= 14; i++)
  259. // {
  260. // sheet1.RemoveRow(sheet1.GenerateRow(i));
  261. // //RemoveMergedRegion(sheet1, i);
  262. // }
  263. // for (int i = 0; i < 6; i++)
  264. // {
  265. // RemoveMergedRegion(sheet1, 8 + i);
  266. // }
  267. // int index = 0;
  268. // decimal totalCount = 0;
  269. // decimal allTotalPrice = 0;
  270. // ICellStyle style1 = SetCellStyle(work, fontHeightInPoints: 10, horizontalAlignment: HorizontalAlignment.Left);
  271. // ICellStyle style11 = SetCellStyle(work, boldWeight: (short)FontBoldWeight.Normal, fontHeightInPoints: 10);
  272. // foreach (var send in orderSends)
  273. // {
  274. // sheet1.GenerateCell(7 + index, 1).SetValue<int>(index + 1, style1);
  275. // sheet1.GenerateCell(7 + index, 2).SetValue(send.StockNo ?? "", style11);
  276. // sheet1.GenerateCell(7 + index, 3).SetValue(send.PartNo ?? "", style11);
  277. // sheet1.GenerateCell(7 + index, 4).SetValue(send.ProductName ?? "", style11);
  278. // sheet1.GenerateCell(7 + index, 5).SetValue(send.SurfaceColor ?? "", style11);
  279. // sheet1.GenerateCell(7 + index, 6).SetValue<decimal>("", style11);
  280. // var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  281. // sheet1.GenerateCell(7 + index, 7).SetValue<decimal>(sendQuantity * 1000, style11);
  282. // totalCount += sendQuantity * 1000;
  283. // sheet1.GenerateCell(7 + index, 8).SetValue<decimal>(send.Price / 10, style11);
  284. // var afterTotalPrice = send.AfterTaxPrice * send.SendQuantity;
  285. // sheet1.GenerateCell(7 + index, 9).SetValue<decimal>(afterTotalPrice, style11);
  286. // allTotalPrice += afterTotalPrice;
  287. // sheet1.GenerateCell(7 + index, 10).SetValue(send.ProductBatchNum ?? "", style11);
  288. // index++;
  289. // }
  290. // ICellStyle style2 = SetCellStyle(work, fontHeightInPoints: 11);
  291. // ICellStyle style3 = SetCellStyle(work, fillBackgroundColor: (short)ColorType.Yellow, borderStyle: BorderStyle.None, fontHeightInPoints: 9);
  292. // ICellStyle style4 = SetCellStyle(work, fillBackgroundColor: (short)ColorType.Yellow, boldWeight: (short)FontBoldWeight.Normal, fontHeightInPoints: 9);
  293. // ICellStyle style5 = SetCellStyle(work, fillBackgroundColor: (short)ColorType.Yellow, fontHeightInPoints: 11, horizontalAlignment: HorizontalAlignment.Left);
  294. // sheet1.GenerateCell(7 + index, 1).SetValue("", style2);
  295. // sheet1.GenerateCell(7 + index, 2).SetValue("合计", style2);
  296. // sheet1.GenerateCell(7 + index, 3).SetValue("", style2);
  297. // sheet1.GenerateCell(7 + index, 4).SetValue("", style2);
  298. // sheet1.GenerateCell(7 + index, 5).SetValue("", style2);
  299. // sheet1.GenerateCell(7 + index, 6).SetValue("", style2);
  300. // sheet1.GenerateCell(7 + index, 7).SetValue<decimal>(totalCount, style2);
  301. // sheet1.GenerateCell(7 + index, 8).SetValue("", style2);
  302. // sheet1.GenerateCell(7 + index, 9).SetValue<decimal>(allTotalPrice, style2);
  303. // sheet1.GenerateCell(7 + index, 10).SetValue("", style2);
  304. // for (int i = 9; i <= 14; i++)
  305. // {
  306. // sheet1.GenerateCell(i + index, 1).SetValue("", style3);
  307. // sheet1.GenerateCell(i + index, 2).SetValue("", style3);
  308. // sheet1.GenerateCell(i + index, 3).SetValue("", style3);
  309. // sheet1.GenerateCell(i + index, 4).SetValue("", style5);
  310. // sheet1.GenerateCell(i + index, 5).SetValue("", style5);
  311. // sheet1.GenerateCell(i + index, 6).SetValue("", style4);
  312. // sheet1.MergedRegion(i + index, i + index, 7, 8);
  313. // sheet1.GenerateCell(i + index, 7).SetValue("", style4);
  314. // sheet1.GenerateCell(i + index, 8).SetValue("", style4);
  315. // sheet1.GenerateCell(i + index, 9).SetValue("", style3);
  316. // }
  317. // sheet1.GenerateCell(9 + index, 4).SetValue("品名:");
  318. // sheet1.GenerateCell(9 + index, 6).SetValue("重量 KG");
  319. // sheet1.GenerateCell(9 + index, 7).SetValue("数量 PCS");
  320. // sheet1.GenerateCell(10 + index, 4).SetValue("垫片类:");
  321. // sheet1.GenerateCell(10 + index, 6).SetValue("垫片类:");
  322. // sheet1.GenerateCell(11 + index, 4).SetValue("总数量");
  323. // sheet1.GenerateCell(11 + index, 6).SetValue("总数量");
  324. // sheet1.GenerateCell(11 + index, 7).SetValue(totalCount + "PCS");
  325. // sheet1.GenerateCell(12 + index, 4).SetValue("总重量:");
  326. // sheet1.GenerateCell(12 + index, 6).SetValue("总重量公斤:");
  327. // sheet1.GenerateCell(13 + index, 4).SetValue("总件数:");
  328. // sheet1.GenerateCell(13 + index, 6).SetValue("总件数:");
  329. // sheet1.GenerateCell(14 + index, 4).SetValue("送货司机:");
  330. // sheet1.GenerateCell(14 + index, 6).SetValue("车牌号:");
  331. // var fileName = $"天津柏中专用-{Clock.Now:yyMMddHHmmss}.xlsx";
  332. // var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  333. // if (!result.IsNullOrEmpty())
  334. // {
  335. // //CheckErrors(IwbIdentityResult.Failed(result));
  336. // return null;
  337. // }
  338. // return $"/{savePath}/{fileName}";
  339. //}
  340. public void ExportTempTjbz(OrderSendMiniExcelDto miniValue)
  341. {
  342. miniValue.Ex1 = miniValue.SendDate?.ToString("yyyy-MM-dd");
  343. decimal allTotalPrice = 0,allSendQuantity=0;
  344. foreach (var send in miniValue.send)
  345. {
  346. send.Price = send.Price / 10;
  347. send.TotalPrice = send.AfterTaxPrice * send.SendQuantity;
  348. allTotalPrice += send.TotalPrice;
  349. send.SendQuantity = send.SendQuantity * 1000;
  350. allSendQuantity += send.SendQuantity;
  351. }
  352. miniValue.AllSendQuantity = allSendQuantity;
  353. miniValue.AllTotalPrice = allTotalPrice;
  354. }
  355. /// <summary>
  356. /// 杭州西门子
  357. /// </summary>
  358. /// <param name="bill"></param>
  359. /// <param name="orderSends"></param>
  360. /// <param name="customer"></param>
  361. /// <param name="templateInfo"></param>
  362. /// <returns></returns>
  363. //public string ExportTempHzxmz(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  364. // TemplateInfo templateInfo)
  365. //{
  366. // string path = AppDomain.CurrentDomain.BaseDirectory + templateInfo.FilePath;
  367. // var savePath = "Download/Excel/OrderSendBill";
  368. // var work = ExcelHelper.CreateWorkBook07(path);
  369. // var sheet1 = work.GetSheet("Sheet1");
  370. // sheet1.GenerateCell(5, 3).SetCellValue(bill.SendDate?.ToString("yyyy/MM/dd"));
  371. // int index = 0;
  372. // ICellStyle style1 = SetCellStyle(work, fontName: "Arial", horizontalAlignment: HorizontalAlignment.Left, boldWeight: (short)FontBoldWeight.Normal,borderColor:(short)ColorType.Black);
  373. // // ICellStyle style11 = SetCellStyle(work, boldWeight: (short)FontBoldWeight.Normal, fontHeightInPoints: 10);
  374. // foreach (var send in orderSends)
  375. // {
  376. // sheet1.GenerateCell(8 + index, 1).SetValue<int>(index + 1, style1);
  377. // sheet1.GenerateCell(8 + index, 2).SetValue(send?.StockNo??"", style1);
  378. // sheet1.GenerateCell(8 + index, 3).SetValue("", style1);
  379. // sheet1.GenerateCell(8 + index, 4).SetValue(send?.PartNo??"", style1);
  380. // sheet1.GenerateCell(8 + index, 5).SetValue("", style1);
  381. // var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  382. // sheet1.GenerateCell(8 + index, 6).SetValue<decimal>(sendQuantity * 1000, style1);
  383. // sheet1.GenerateCell(8 + index, 7).SetValue(send?.Model??"", style1);
  384. // sheet1.GenerateCell(8 + index, 8).SetValue((send?.ProductName ?? "") + "," + (send?.SurfaceColor ?? "") + "," + (send?.Rigidity ?? "") + "", style1);
  385. // sheet1.GenerateCell(8 + index, 9).SetValue("", style1);
  386. // sheet1.GenerateCell(8 + index, 10).SetValue(send?.Remark??"", style1);
  387. // index++;
  388. // }
  389. // for (int i = index+1; i <= 13; i++)
  390. // {
  391. // sheet1.GenerateCell(8 + index, 1).SetValue("", style1);
  392. // sheet1.GenerateCell(8 + index, 2).SetValue("", style1);
  393. // sheet1.GenerateCell(8 + index, 3).SetValue("", style1);
  394. // sheet1.GenerateCell(8 + index, 4).SetValue("", style1);
  395. // sheet1.GenerateCell(8 + index, 5).SetValue("", style1);
  396. // sheet1.GenerateCell(8 + index, 6).SetValue("", style1);
  397. // sheet1.GenerateCell(8 + index, 7).SetValue("", style1);
  398. // sheet1.GenerateCell(8 + index, 8).SetValue("", style1);
  399. // sheet1.GenerateCell(8 + index, 9).SetValue("", style1);
  400. // sheet1.GenerateCell(8 + index, 10).SetValue("", style1);
  401. // index++;
  402. // }
  403. // ICellStyle style2 = SetCellStyle(work, fontName: "宋体", fontHeightInPoints: 11, horizontalAlignment: HorizontalAlignment.Center,borderColor:(short)ColorType.Grey25Percent);
  404. // sheet1.GenerateCell(8 + index, 1).SetValue("", style2);
  405. // sheet1.GenerateCell(8 + index, 2).SetValue("", style2);
  406. // sheet1.GenerateCell(8 + index, 3).SetValue("", style2);
  407. // sheet1.GenerateCell(8 + index, 4).SetValue("", style2);
  408. // sheet1.GenerateCell(8 + index, 5).SetValue("", style2);
  409. // sheet1.GenerateCell(8 + index, 6).SetValue("", style2);
  410. // sheet1.GenerateCell(8 + index, 7).SetValue("", style2);
  411. // sheet1.GenerateCell(8 + index, 8).SetValue("", style2);
  412. // sheet1.MergedRegion(8 + index, 8 + index, 9, 10);
  413. // sheet1.GenerateCell(8 + index, 9).SetValue("合计_箱", style2);
  414. // ICellStyle style3 = SetCellStyle(work, fontName: "宋体", horizontalAlignment: HorizontalAlignment.Left, boldWeight: (short)FontBoldWeight.Normal, borderColor: (short)ColorType.Grey25Percent);
  415. // sheet1.MergedRegion(9 + index, 9 + index, 1, 2);
  416. // sheet1.GenerateCell(9 + index, 1).SetValue(" 送货人:沈", style3);
  417. // sheet1.GenerateCell(9 + index, 3).SetValue("", style3);
  418. // sheet1.GenerateCell(9 + index, 4).SetValue("", style3);
  419. // sheet1.GenerateCell(9 + index, 5).SetValue("签收人:", style3);
  420. // sheet1.GenerateCell(9 + index, 6).SetValue("", style3);
  421. // sheet1.GenerateCell(9 + index, 7).SetValue("", style3);
  422. // sheet1.GenerateCell(9 + index, 8).SetValue("签收日期:", style3);
  423. // sheet1.GenerateCell(9 + index, 9).SetValue("", style3);
  424. // sheet1.GenerateCell(9 + index, 10).SetValue("", style3);
  425. // ICellStyle style4 = SetCellStyle(work, fontName: "Arial",fontHeightInPoints: 10,horizontalAlignment: HorizontalAlignment.Left, borderStyle: BorderStyle.Thin, boldWeight: (short)FontBoldWeight.Normal, borderColor: (short)ColorType.Grey25Percent);
  426. // sheet1.GenerateCell(10 + index, 1).SetValue("Comments:备注", style4);
  427. // sheet1.GenerateCell(10 + index, 2).SetValue("", style4);
  428. // sheet1.GenerateCell(10 + index, 3).SetValue("", style4);
  429. // sheet1.GenerateCell(10 + index, 4).SetValue("", style4);
  430. // sheet1.GenerateCell(10 + index, 5).SetValue("", style4);
  431. // sheet1.GenerateCell(10 + index, 6).SetValue("", style4);
  432. // sheet1.GenerateCell(10 + index, 7).SetValue("", style4);
  433. // sheet1.GenerateCell(10 + index, 8).SetValue("", style4);
  434. // sheet1.GenerateCell(10 + index, 9).SetValue("", style4);
  435. // sheet1.GenerateCell(10 + index, 10).SetValue("", style4);
  436. // for (int i = 0; i < 5; i++)
  437. // {
  438. // sheet1.GenerateCell(11 +index+ i, 1).SetValue("", style4);
  439. // sheet1.GenerateCell(11 +index+ i, 2).SetValue("", style4);
  440. // sheet1.GenerateCell(11 +index+ i, 3).SetValue("", style4);
  441. // sheet1.GenerateCell(11 +index+ i, 4).SetValue("", style4);
  442. // sheet1.GenerateCell(11 +index+ i, 5).SetValue("", style4);
  443. // sheet1.GenerateCell(11 +index+ i, 6).SetValue("", style4);
  444. // sheet1.GenerateCell(11 +index+ i, 7).SetValue("", style4);
  445. // sheet1.GenerateCell(11 +index+ i, 8).SetValue("", style4);
  446. // sheet1.GenerateCell(11 +index+ i, 9).SetValue("", style4);
  447. // sheet1.GenerateCell(11 +index+ i, 10).SetValue("", style4);
  448. // }
  449. // ICellStyle style5 = SetCellStyle(work, fontName: "Arial", fontHeightInPoints: 10, horizontalAlignment: HorizontalAlignment.Left, borderStyle: BorderStyle.Thin,borderColor: (short)ColorType.Grey25Percent);
  450. // sheet1.GenerateCell(11 + index, 2).SetValue("1、The same Drawing No. are consider same Lot / Batch不同订单号但是相同零件图号的为一批;相同订单号,相同零件图号必须在同一行!", style4);
  451. // sheet1.GenerateCell(12 + index, 2).SetValue("2、Only 5 Lots / Batch must be per page !. 一页最多只允许有5批或10行,否则拒收!", style5);
  452. // sheet1.GenerateCell(13 + index, 2).SetValue("3、零件图号和版本号务必填写正确、完整;", style4);
  453. // sheet1.GenerateCell(14 + index, 2).SetValue("4、供应商提供送检单须一式两份,一份给SAP操作员用于入录数据,一份给检验员用于检验记录;", style4);
  454. // sheet1.GenerateCell(15 + index, 2).SetValue("5、检验完成后,一份交予仓库,一份质量部留档。", style4);
  455. // var fileName = $"杭州西门子专用-{Clock.Now:yyMMddHHmmss}.xlsx";
  456. // var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  457. // if (!result.IsNullOrEmpty())
  458. // {
  459. // //CheckErrors(IwbIdentityResult.Failed(result));
  460. // return null;
  461. // }
  462. // return $"/{savePath}/{fileName}";
  463. //}
  464. public void ExportTempHzxmz(OrderSendMiniExcelDto miniValue)
  465. {
  466. miniValue.Ex1 = miniValue.SendDate?.ToString("yyyy/MM/dd");
  467. foreach (var send in miniValue.send)
  468. {
  469. send.SendQuantity = send.SendQuantity * 1000;
  470. }
  471. }
  472. /// <summary>
  473. /// 凯乐金霸
  474. /// </summary>
  475. /// <param name="bill"></param>
  476. /// <param name="orderSends"></param>
  477. /// <param name="customer"></param>
  478. /// <param name="templateInfo"></param>
  479. /// <returns></returns>
  480. //public string ExportTempKlgb(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  481. // TemplateInfo templateInfo)
  482. //{
  483. // string path = AppDomain.CurrentDomain.BaseDirectory + templateInfo.FilePath;
  484. // //var savePath = "Download/Excel/OrderSendBill";
  485. // var work = ExcelHelper.CreateWorkBook07(path);
  486. // var sheet1 = work.GetSheet("Sheet1");
  487. // //int sendCount = orderSends.Count;
  488. // //List<IRow> rows = sheet1.GetRows(91, 101);
  489. // //for (int i = 0; i < rows.Count; i++)
  490. // //{
  491. // // CopyRowEx(work, sheet1.GenerateRow(91+i), sheet1.GenerateRow(7+i+ sendCount), true);
  492. // //}
  493. // sheet1.GenerateCell(1, 10).SetValue(bill.Id);
  494. // int index = 0;
  495. // decimal totalCount = 0;
  496. // ICellStyle style1 = SetCellStyle(work, fontName: "Arial", fontHeightInPoints: 10, horizontalAlignment: HorizontalAlignment.Center, boldWeight: (short)FontBoldWeight.Normal, borderColor: (short)ColorType.Black);
  497. // foreach (var send in orderSends)
  498. // {
  499. // sheet1.GenerateCell(7 + index, 1).SetValue<int>(index + 1, style1);
  500. // sheet1.GenerateCell(7 + index, 2).SetValue(send.StockNo, style1);
  501. // sheet1.GenerateCell(7 + index, 3).SetValue(send.PartNo??"", style1);
  502. // sheet1.GenerateCell(7 + index, 4).SetValue(send.Model??"", style1);
  503. // sheet1.GenerateCell(7 + index, 5).SetValue( (send.ProductName??"") + "," + (send.SurfaceColor??"") + "," + (send.Rigidity??"") , style1);
  504. // var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  505. // var quantityPerPack = send.QuantityPerPack ?? 0;
  506. // quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  507. // decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  508. // var sysl = sendQuantity - quantityPerPack * packageCount;
  509. // sheet1.GenerateCell(7 + index, 6).SetValue<decimal>(sendQuantity * 1000, style1);
  510. // totalCount += sendQuantity * 1000;
  511. // sheet1.GenerateCell(7 + index, 7).SetValue("", style1);
  512. // sheet1.GenerateCell(7 + index, 8).SetValue<decimal>(quantityPerPack*1000, style1);
  513. // sheet1.GenerateCell(7 + index, 9).SetValue(packageCount+"箱"+"*"+ quantityPerPack+ (sysl>0?"+"+sysl:"")+"="+ sendQuantity, style1);
  514. // sheet1.GenerateCell(7 + index, 10).SetValue("", style1);
  515. // sheet1.GenerateCell(7 + index, 11).SetValue(send.Remark ?? "", style1);
  516. // index++;
  517. // }
  518. // for (int i = 1; i <= 11; i++)
  519. // {
  520. // sheet1.GenerateCell(7 + index, i).SetValue("", style1);
  521. // }
  522. // ICellStyle style1_1 = SetCellStyle(work, fontName: "Arial", fontHeightInPoints: 10, horizontalAlignment: HorizontalAlignment.Left, boldWeight: (short)FontBoldWeight.Normal, borderColor: (short)ColorType.Black,wrapText:true);
  523. // sheet1.GenerateCell(8 + index, 1).SetValue("收货验收确认Received Confirmation:", style1_1);
  524. // sheet1.GenerateCell(8 + index, 2).SetValue("", style1);
  525. // sheet1.GenerateCell(8 + index, 3).SetValue("", style1);
  526. // sheet1.GenerateCell(8 + index, 4).SetValue("", style1);
  527. // sheet1.GenerateCell(8 + index, 5).SetValue("", style1);
  528. // sheet1.GenerateCell(8 + index, 6).SetValue<int>(totalCount, style1);
  529. // sheet1.GenerateCell(8 + index, 7).SetValue("", style1);
  530. // sheet1.GenerateCell(8 + index, 8).SetValue("", style1);
  531. // sheet1.MergedRegion(8 + index, 8 + index, 9, 10);
  532. // sheet1.GenerateCell(8 + index, 9).SetValue("合计_箱,附检测报告 ", style1);
  533. // sheet1.GenerateCell(8 + index, 10).SetValue("", style1);
  534. // sheet1.GenerateCell(8 + index, 11).SetValue("", style1);
  535. // ICellStyle style1_2 = SetCellStyle(work, fontName: "Arial", fontHeightInPoints: 10, horizontalAlignment: HorizontalAlignment.Center, boldWeight: (short)FontBoldWeight.Normal, borderColor: (short)ColorType.Black, wrapText: true,fillBackgroundColor:(short)ColorType.Grey25Percent);
  536. // sheet1.GenerateCell(9 + index, 1).SetValue("日期及签字/Date & Signature:", style1_2);
  537. // sheet1.GenerateCell(9 + index, 2).SetValue("", style1_2);
  538. // sheet1.GenerateCell(9 + index, 3).SetValue("___日期____沈再红", style1_2);
  539. // sheet1.GenerateCell(9 + index, 4).SetValue("", style1_2);
  540. // sheet1.GenerateCell(9 + index, 5).SetValue("", style1_2);
  541. // sheet1.GenerateCell(9 + index, 6).SetValue("送货人:", style1_2);
  542. // sheet1.MergedRegion(9 + index, 9 + index, 7, 8);
  543. // sheet1.GenerateCell(9 + index, 7).SetValue("", style1_2);
  544. // sheet1.GenerateCell(9 + index, 8).SetValue("", style1_2);
  545. // sheet1.GenerateCell(9 + index, 9).SetValue("收货人", style1_2);
  546. // sheet1.MergedRegion(9 + index, 9 + index, 10, 11);
  547. // sheet1.GenerateCell(9 + index, 10).SetValue("", style1_2);
  548. // sheet1.GenerateCell(9 + index, 11).SetValue("", style1_2);
  549. // ICellStyle style2= SetCellStyle(work, fontName: "Arial", fontHeightInPoints: 10, horizontalAlignment: HorizontalAlignment.Left, boldWeight: (short)FontBoldWeight.Normal, borderColor: (short)ColorType.Grey25Percent);
  550. // for (int i = 0; i < 8; i++)
  551. // {
  552. // sheet1.GenerateCell(10+i + index, 1).SetValue("", style2);
  553. // sheet1.MergedRegion(10 + i + index, 10 + i + index, 2, 7);
  554. // sheet1.GenerateCell(10+i + index, 2).SetValue("", style2);
  555. // sheet1.GenerateCell(10 + i + index, 3).SetValue("", style2);
  556. // sheet1.GenerateCell(10 + i + index, 4).SetValue("", style2);
  557. // sheet1.GenerateCell(10 + i + index, 5).SetValue("", style2);
  558. // sheet1.GenerateCell(10 + i + index, 6).SetValue("", style2);
  559. // sheet1.GenerateCell(10 + i + index, 7).SetValue("", style2);
  560. // sheet1.GenerateCell(10+i + index, 8).SetValue("", style2);
  561. // sheet1.GenerateCell(10+i + index, 9).SetValue("", style2);
  562. // sheet1.GenerateCell(10 + i + index, 10).SetValue("", style2);
  563. // sheet1.GenerateCell(10+i + index, 11).SetValue("", style2);
  564. // }
  565. // sheet1.GenerateCell(10 + index, 1).SetValue("送货及物品包装要求");
  566. // sheet1.GenerateCell(10 + index, 2).SetValue("1: 物品包装箱子必须为纸箱,不允许麻布袋形式包装,含油性物料必须在包装箱内增加塑料袋");
  567. // sheet1.GenerateCell(11 + index, 2).SetValue("2: 包装箱尺寸必须一致,推荐尺寸为320*220*120的包装箱");
  568. // sheet1.GenerateCell(12 + index, 2).SetValue("3: 同一款物料每箱数量必须一致,只留一个尾箱,且必须在包装箱上标注尾数箱");
  569. // sheet1.GenerateCell(13 + index, 2).SetValue("4: 每个物品独立包装箱,不可多个物料摆放在一个包装箱,避免造成混料");
  570. // sheet1.GenerateCell(14 + index, 2).SetValue("5: 每箱物料重量必须控制在20KG以下");
  571. // sheet1.GenerateCell(15 + index, 2).SetValue("6:物料箱上必须贴有物料标示,必须具备订单号/KK物料号/尺寸描述/装箱数量/最小包装量");
  572. // sheet1.GenerateCell(16 + index, 2).SetValue("7: 严禁包装箱破损与无包装裸露送货,不满足的包装,仓库一律拒收");
  573. // sheet1.GenerateCell(17 + index, 2).SetValue("8: 供应商送货数量必须与送货单数量一致");
  574. // for (int i = 1; i <= 11; i++)
  575. // {
  576. // ICellStyle ss = work.CreateCellStyle();
  577. // ss.BorderTop = BorderStyle.Thin;
  578. // ss.TopBorderColor = (short)ColorType.Black;
  579. // sheet1.GenerateCell(18 + index, i).CellStyle = ss;
  580. // sheet1.GenerateCell(18 + index, i).SetValue("");
  581. // }
  582. // for (int i = 0; i < 8; i++)
  583. // {
  584. // ICellStyle ss = work.CreateCellStyle();
  585. // ss.BorderLeft = BorderStyle.Thin;
  586. // ss.LeftBorderColor = (short) ColorType.Black;
  587. // sheet1.GenerateCell(10 + i + index, 12).CellStyle = ss;
  588. // sheet1.GenerateCell(10 + i + index, 12).SetValue("");
  589. // }
  590. // var fileName = $"凯乐金霸专用-{Clock.Now:yyMMddHHmmss}.xlsx";
  591. // //var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  592. // //if (!result.IsNullOrEmpty())
  593. // //{
  594. // // //CheckErrors(IwbIdentityResult.Failed(result));
  595. // // return null;
  596. // //}
  597. // //return $"/{savePath}/{fileName}";
  598. // return Save(sheet1, fileName);
  599. //}
  600. public void ExportTempKlgb(OrderSendMiniExcelDto miniValue)
  601. {
  602. decimal allSendCount = 0;
  603. foreach (var send in miniValue.send)
  604. {
  605. send.Ext1 = send.PackageCount + "箱*" + send.QuantityPerPack + (send.Sysl > 0 ? "+" + send.Sysl : "") +
  606. "=" + send.SendQuantity;
  607. send.SendQuantity = send.SendQuantity * 1000;
  608. send.QuantityPerPack = send.QuantityPerPack * 1000;
  609. allSendCount += send.SendQuantity;
  610. }
  611. miniValue.AllSendQuantity = allSendCount;
  612. }
  613. /// <summary>
  614. /// 杭州德特
  615. /// </summary>
  616. /// <param name="bill"></param>
  617. /// <param name="orderSends"></param>
  618. /// <param name="customer"></param>
  619. /// <param name="templateInfo"></param>
  620. /// <returns></returns>
  621. //public string ExportTempHzdt(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  622. // TemplateInfo templateInfo)
  623. //{
  624. // var sheet1 = GetSheet1(templateInfo);
  625. // int index = 0;
  626. // sheet1.GenerateCell(3, 4).SetValue(DateTime.Now.ToString("yyyy.M.dd"));
  627. // sheet1.InsertRows(6, orderSends.Count);
  628. // var viewOrderSends = orderSends.OrderBy(i => i.PartNo);
  629. // foreach (var send in viewOrderSends)
  630. // {
  631. // sheet1.GenerateCell(6 + index,1).SetValue<int>(index + 1);
  632. // sheet1.GenerateCell(6 + index,2).SetValue(send.StockNo ?? "");
  633. // sheet1.GenerateCell(6 + index,3).SetValue(send.PartNo ?? "");
  634. // sheet1.GenerateCell(6 + index, 4).SetValue((send.Model ?? "") + "," + (send.ProductName ?? "") + "," +
  635. // (send.SurfaceColor ?? "") + "," + (send.Rigidity ?? ""));
  636. // var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  637. // var quantityPerPack = Math.Floor((send.QuantityPerPack ?? 0)*1000)/1000;
  638. // quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  639. // decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  640. // var sysl = sendQuantity - quantityPerPack * packageCount;
  641. // sheet1.GenerateCell(6 + index, 5).SetValue<decimal>(sendQuantity);
  642. // sheet1.GenerateCell(6 + index, 6).SetValue((packageCount + (sysl > 0 ? 1 : 0)) + "箱" );
  643. // sheet1.GenerateCell(6 + index, 7).SetValue(send.ProductBatchNum);
  644. // index++;
  645. // }
  646. // var fileName = $"杭州德特专用-{Clock.Now:yyMMddHHmmss}.xlsx";
  647. // return Save(sheet1, fileName);
  648. //}
  649. public void ExportTempHzdt(OrderSendMiniExcelDto miniValue)
  650. {
  651. var oSds = miniValue.send.OrderBy(i => i.PartNo).ToList();
  652. foreach (var send in oSds)
  653. {
  654. send.Ext1 = send.PackageCount + ((send.Sysl > 0 ? 1 : 0)) + "箱";
  655. }
  656. miniValue.Ex1 = DateTime.Now.ToString("yyyy.M.dd");
  657. miniValue.send = oSds;
  658. }
  659. //上海泛得五金配件厂
  660. //public string ExportTempShFd(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  661. // TemplateInfo templateInfo)
  662. //{
  663. // var sheet1 = GetSheet1(templateInfo);
  664. // int index = 0;
  665. // //sheet1.GenerateCell(3, 4).SetValue(DateTime.Now.ToString("yyyy.MM.dd"));
  666. // var orderSendCount = orderSends.Count;
  667. // if (orderSendCount < 20)
  668. // {
  669. // orderSendCount = 20;
  670. // }
  671. // sheet1.InsertRows(7, orderSendCount);
  672. // var viewOrderSends = orderSends.OrderBy(i => i.PartNo);
  673. // decimal allSendCount = 0;
  674. // foreach (var send in viewOrderSends)
  675. // {
  676. // sheet1.GenerateCell(7 + index, 1).SetValue<int>(index + 1);
  677. // sheet1.GenerateCell(7 + index, 2).SetValue(DateTime.Now.ToString("yyyy.MM.dd"));
  678. // sheet1.GenerateCell(7 + index, 3).SetValue(send.StockNo ?? "");
  679. // sheet1.GenerateCell(7 + index, 4).SetValue(send.PartNo ?? "");
  680. // sheet1.GenerateCell(7 + index, 5).SetValue((send.Model ?? "") + "," + (send.ProductName ?? "") + "," +
  681. // (send.SurfaceColor ?? "") + "," + (send.Rigidity ?? ""));
  682. // var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  683. // var quantityPerPack = Math.Floor((send.QuantityPerPack ?? 0) * 1000) / 1000;
  684. // quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  685. // decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  686. // var sysl = sendQuantity - quantityPerPack * packageCount;
  687. // sheet1.GenerateCell(7 + index, 6).SetValue<decimal>(sendQuantity*1000);
  688. // sheet1.GenerateCell(7 + index, 7).SetValue((packageCount + (sysl > 0 ? 1 : 0))+"");
  689. // sheet1.GenerateCell(7 + index, 8).SetValue(send.ProductBatchNum);
  690. // allSendCount += sendQuantity * 1000;
  691. // index++;
  692. // }
  693. // sheet1.MergedRegion(7 + orderSendCount+2, 7 + orderSendCount+2, 7, 9);
  694. // sheet1.GenerateCell(7 + orderSendCount+2, 7).SetValue("合计:"+ allSendCount);
  695. // //sheet1.GenerateCell(7 + orderSendCount, 8).SetValue(send.ProductBatchNum);
  696. // var fileName = $"上海泛得五金配件厂-{Clock.Now:yyMMddHHmmss}.xlsx";
  697. // return Save(sheet1, fileName);
  698. //}
  699. public void ExportTempShFd(OrderSendMiniExcelDto miniValue)
  700. {
  701. decimal allSendCount = 0;
  702. var oSds = miniValue.send.OrderBy(i => i.PartNo).ToList();
  703. foreach (var send in oSds)
  704. {
  705. send.SendDateStr = DateTime.Now.ToString("yyyy.MM.dd");
  706. send.SendQuantity = send.SendQuantity * 1000;
  707. send.Ext1 = send.PackageCount + ((send.Sysl > 0 ? 1 : 0))+"";
  708. allSendCount += send.SendQuantity;
  709. }
  710. miniValue.AllSendQuantity = allSendCount;
  711. miniValue.send = oSds;
  712. }
  713. //太仓慧鱼
  714. //public string ExportTempTCHY(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  715. // TemplateInfo templateInfo)
  716. //{
  717. // var sheet1 = GetSheet1(templateInfo);
  718. // int index = 0;
  719. // //sheet1.GenerateCell(3, 4).SetValue(DateTime.Now.ToString("yyyy.MM.dd"));
  720. // var orderSendCount = orderSends.Count;
  721. // if (orderSendCount < 7)
  722. // {
  723. // orderSendCount = 7;
  724. // }
  725. // sheet1.InsertRows(14, orderSendCount);
  726. // var viewOrderSends = orderSends.OrderBy(i => i.PartNo);
  727. // //decimal allSendCount = 0;
  728. // sheet1.GenerateCell(7, 3).SetValue(DateTime.Now.ToString("yyyy/MM/dd"));
  729. // foreach (var send in viewOrderSends)
  730. // {
  731. // sheet1.GenerateCell(14 + index, 1).SetValue(send?.PartNo);
  732. // sheet1.GenerateCell(14 + index, 2).SetValue(send.StockNo ?? "");
  733. // var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  734. // var quantityPerPack = Math.Floor((send.QuantityPerPack ?? 0) * 1000) / 1000;
  735. // quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  736. // decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  737. // var sysl = sendQuantity - quantityPerPack * packageCount;
  738. // sheet1.GenerateCell(14 + index, 3).SetValue<decimal>(sendQuantity * 1000);
  739. // sheet1.GenerateCell(14 + index, 5).SetValue(send.ProductBatchNum);
  740. // sheet1.GenerateCell(14 + index, 6).SetValue((send.ProductName ?? "") + " " + (send.Model ?? "") + " " +
  741. // (send.SurfaceColor ?? "") + " " + (send.Rigidity ?? ""));
  742. // sheet1.GenerateCell(14 + index, 7).SetValue("太仓");
  743. // sheet1.GenerateCell(14 + index, 8).SetValue(send.OrderDate.ToString("yyyy/MM/dd"));
  744. // sheet1.GenerateCell(14 + index, 9).SetValue(packageCount + "箱*" + quantityPerPack + (sysl > 0 ? " + " + (sysl * 1000) : "") + "PCS");
  745. // //allSendCount += sendQuantity * 1000;
  746. // index++;
  747. // }
  748. // //sheet1.MergedRegion(7 + orderSendCount + 2, 7 + orderSendCount + 2, 7, 9);
  749. // // sheet1.GenerateCell(7 + orderSendCount + 2, 7).SetValue("合计:" + allSendCount);
  750. // //sheet1.GenerateCell(7 + orderSendCount, 8).SetValue(send.ProductBatchNum);
  751. // var fileName = $"太仓慧鱼送货单-{Clock.Now:yyMMddHHmmss}.xlsx";
  752. // return Save(sheet1, fileName);
  753. //}
  754. public void ExportTempTCHY(OrderSendMiniExcelDto miniValue)
  755. {
  756. foreach (var send in miniValue.send)
  757. {
  758. send.SendQuantity = send.SendQuantity * 1000;
  759. send.SendDateStr = send.SendDate?.ToString("yyyy/MM/dd");
  760. send.Ext1 = "太仓";
  761. send.Desc = send.PackageCount + "箱*" + Math.Round(send.QuantityPerPack) +
  762. (send.Sysl > 0 ? " + " + (send.Sysl * 1000) : "") + "PCS";
  763. }
  764. var oSds = miniValue.send.OrderBy(i => i.PartNo).ToList();
  765. miniValue.send = oSds;
  766. miniValue.Ex1 = DateTime.Now.ToString("yyyy/MM/dd");
  767. }
  768. //上海特强汽车紧固件有限公司
  769. public string ExportTempTq(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  770. TemplateInfo templateInfo)
  771. {
  772. var sheet1 = GetSheet1(templateInfo);
  773. int index = 0;
  774. //sheet1.GenerateCell(3, 4).SetValue(DateTime.Now.ToString("yyyy.MM.dd"));
  775. var orderSendCount = orderSends.Count;
  776. //if (orderSendCount < 7)
  777. //{
  778. // orderSendCount = 7;
  779. //}
  780. sheet1.InsertRows(10, orderSendCount);
  781. var viewOrderSends = orderSends.OrderBy(i => i.PartNo);
  782. //decimal allSendCount = 0;
  783. sheet1.GenerateCell(2, 1).SetValue("单号:" + bill.Id);
  784. sheet1.GenerateCell(7, 1).SetValue("日期:" + DateTime.Now.ToString("yyyy年MM月dd日"));
  785. sheet1.GenerateCell(5, 2).SetValue("客户:" + customer.CustomerName);
  786. sheet1.GenerateCell(5, 9).SetValue("地址:" + customer.Address);
  787. sheet1.GenerateCell(6, 2).SetValue("联系电话:" + customer.Telephone);
  788. sheet1.GenerateCell(6, 9).SetValue("联系人:" + customer.LinkMan);
  789. foreach (var send in viewOrderSends)
  790. {
  791. sheet1.GenerateCell(10 + index, 1).SetValue($"{index + 1}");
  792. sheet1.GenerateCell(10 + index, 2).SetValue(send.StockNo ?? "");
  793. var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  794. var quantityPerPack = Math.Floor((send.QuantityPerPack ?? 0) * 1000) / 1000;
  795. quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  796. decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  797. var sysl = sendQuantity - quantityPerPack * packageCount;
  798. //sheet1.GenerateCell(10 + index, 3).SetValue<decimal>(sendQuantity * 1000);
  799. sheet1.GenerateCell(10 + index, 3).SetValue(send.ProductName ?? "");
  800. sheet1.GenerateCell(10 + index, 4).SetValue(send.Model ?? "");
  801. sheet1.GenerateCell(10 + index, 5).SetValue(send.SurfaceColor ?? "");
  802. sheet1.GenerateCell(10 + index, 6).SetValue(send.Material ?? "");
  803. sheet1.GenerateCell(10 + index, 7).SetValue(send.Rigidity ?? "");
  804. sheet1.GenerateCell(10 + index, 8).SetValue("千件");
  805. sheet1.GenerateCell(10 + index, 9).SetValue<decimal>(sendQuantity);
  806. sheet1.GenerateCell(10 + index, 10).SetValue<decimal>(packageCount);
  807. sheet1.GenerateCell(10 + index, 11).SetValue<decimal>(quantityPerPack);
  808. sheet1.GenerateCell(10 + index, 12).SetValue<decimal>(sysl);
  809. sheet1.GenerateCell(10 + index, 13).SetValue<decimal>(sendQuantity);
  810. sheet1.GenerateCell(10 + index, 14).SetValue(send.ProductBatchNum ?? "");
  811. index++;
  812. }
  813. sheet1.GenerateCell(13 + index, 11).SetValue("送货日期:" + Clock.Now.ToString("yyyy-MM-dd"));
  814. //sheet1.MergedRegion(7 + orderSendCount + 2, 7 + orderSendCount + 2, 7, 9);
  815. // sheet1.GenerateCell(7 + orderSendCount + 2, 7).SetValue("合计:" + allSendCount);
  816. //sheet1.GenerateCell(7 + orderSendCount, 8).SetValue(send.ProductBatchNum);
  817. var fileName = $"上海特强送货单-{Clock.Now:yyMMddHHmmss}.xlsx";
  818. return Save(sheet1, fileName);
  819. }
  820. //public void ExportTempTq(OrderPrintMiniExcelDto miniValue)
  821. //{
  822. //}
  823. //上海巧耐森科技有限公司
  824. //public string ExportTempQNS(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  825. // TemplateInfo templateInfo)
  826. //{
  827. // var sheet1 = GetSheet1(templateInfo);
  828. // int index = 0;
  829. // sheet1.GenerateCell(2, 5).SetValue(bill.Id);
  830. // var orderSendCount = orderSends.Count;
  831. // //if (orderSendCount < 7)
  832. // //{
  833. // // orderSendCount = 7;
  834. // //}
  835. // sheet1.InsertRows(8, orderSendCount);
  836. // //var viewOrderSends = orderSends.OrderBy(i => i.PartNo);
  837. // //decimal allSendCount = 0;
  838. // //sheet1.GenerateCell(2, 1).SetValue("单号:" + bill.Id);
  839. // //sheet1.GenerateCell(7, 1).SetValue("日期:" + DateTime.Now.ToString("yyyy年MM月dd日"));
  840. // //sheet1.GenerateCell(5, 2).SetValue("客户:" + customer.CustomerName);
  841. // //sheet1.GenerateCell(5, 9).SetValue("地址:" + customer.Address);
  842. // //sheet1.GenerateCell(6, 2).SetValue("联系电话:" + customer.Telephone);
  843. // //sheet1.GenerateCell(6, 9).SetValue("联系人:" + customer.LinkMan);
  844. // decimal allQuantity = 0;
  845. // foreach (var send in orderSends)
  846. // {
  847. // sheet1.GenerateCell(8 + index, 1).SetValue($"{index + 1}");
  848. // sheet1.GenerateCell(8 + index, 2).SetValue(send.SendDate?.ToString("yyyy.MM.dd"));
  849. // sheet1.GenerateCell(8 + index, 3).SetValue(send.StockNo ?? "");
  850. // var sendQuantity = Math.Round(send.SendQuantity * 1000);//发货数量
  851. // sheet1.GenerateCell(8 + index, 4).SetValue(send.PartNo ?? "");
  852. // sheet1.GenerateCell(8 + index, 5).SetValue((send.Model ?? "")+","+(send.ProductName??"") + "," + (send.SurfaceColor??"") + "," + (send.Rigidity??""));
  853. // sheet1.GenerateCell(8 + index, 6).SetValue<decimal>(sendQuantity);
  854. // sheet1.GenerateCell(8 + index, 7).SetValue<decimal>(1);
  855. // sheet1.GenerateCell(8 + index, 8).SetValue(send.ProductBatchNum ?? "");
  856. // allQuantity += sendQuantity;
  857. // index++;
  858. // }
  859. // sheet1.GenerateCell(8 + index+1, 7).SetValue("合计:" + allQuantity);
  860. // var fileName = $"上海巧耐森科技有限公司-{Clock.Now:yyMMddHHmmss}.xlsx";
  861. // return Save(sheet1, fileName);
  862. //}
  863. public void ExportTempQNS(OrderSendMiniExcelDto miniValue)
  864. {
  865. decimal allQuantity = 0;
  866. foreach (var send in miniValue.send)
  867. {
  868. send.SendQuantity = send.SendQuantity * 1000;
  869. send.SendDateStr = send.SendDate?.ToString("yyyy.MM.dd");
  870. allQuantity += send.SendQuantity;
  871. }
  872. miniValue.AllSendQuantity = allQuantity;
  873. miniValue.Ex3 = "1";
  874. }
  875. private ISheet GetSheet1(TemplateInfo templateInfo)
  876. {
  877. string path = AppDomain.CurrentDomain.BaseDirectory + templateInfo.FilePath;
  878. //var savePath = "Download/Excel/OrderSendBill";
  879. var work = ExcelHelper.CreateWorkBook07(path);
  880. var sheet1 = work.GetSheet("Sheet1");
  881. return sheet1;
  882. }
  883. private string Save(ISheet sheet,string fileName)
  884. {
  885. IWorkbook work = sheet.Workbook;
  886. var savePath = "Download/Excel/OrderSendBill";
  887. //var fileName = $"杭州德特专用-{Clock.Now:yyMMddHHmmss}.xlsx";
  888. var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  889. if (!result.IsNullOrEmpty())
  890. {
  891. //CheckErrors(IwbIdentityResult.Failed(result));
  892. return null;
  893. }
  894. return $"/{savePath}/{fileName}";
  895. }
  896. #region ex
  897. private void RemoveMergedRegion(ISheet sheet, int rowIndex)
  898. {
  899. int mergedCount = sheet.NumMergedRegions;
  900. for (int i = mergedCount - 1; i >= 0; i--)
  901. {
  902. /**
  903. CellRangeAddress对象属性有:FirstColumn,FirstRow,LastColumn,LastRow 进行操作 取消合并单元格
  904. **/
  905. var temp = sheet.GetMergedRegion(i);
  906. if (temp.FirstRow == rowIndex)
  907. {
  908. sheet.RemoveMergedRegion(i);
  909. }
  910. }
  911. }
  912. public static ICellStyle SetCellStyle(IWorkbook work, BorderStyle borderStyle= BorderStyle.Thin, short borderColor = 0, short topBorderColor = 0, short rightBorderColor = 0, short leftBorderColor = 0, short bottomBorderColor = 0, short fillBackgroundColor = (short)ColorType.White,bool wrapText=false, VerticalAlignment verticalAlignment= VerticalAlignment.Center, HorizontalAlignment horizontalAlignment= HorizontalAlignment.Center,string fontName= "微软雅黑", short fontColor = (short)ColorType.Black, short boldWeight= (short)FontBoldWeight.Bold,int fontHeightInPoints=12,bool isItalic=false)
  913. {
  914. ExportTemplateFont fontStyle = new ExportTemplateFont()
  915. {
  916. FontName = fontName,
  917. BoldWeight = boldWeight,
  918. Color = fontColor,
  919. FontHeightInPoints = fontHeightInPoints,
  920. IsItalic = isItalic
  921. };
  922. ExportTemplateCss cssStyle = new ExportTemplateCss()
  923. {
  924. BorderStyle = borderStyle,
  925. FillBackgroundColor = fillBackgroundColor,
  926. HorizontalAlignment = horizontalAlignment,
  927. VerticalAlignment = verticalAlignment,
  928. WrapText = wrapText,
  929. FontStyle = fontStyle,
  930. BorderColor = borderColor,
  931. TopBorderColor = topBorderColor,
  932. BottomBorderColor = bottomBorderColor,
  933. LeftBorderColor = leftBorderColor,
  934. RightBorderColor = rightBorderColor
  935. };
  936. return SetCellStyle(work, cssStyle);
  937. }
  938. public static ICellStyle SetCellStyle(IWorkbook work, ExportTemplateCss cssStyle)
  939. {
  940. ICellStyle style = work.CreateCellStyle();
  941. style.BorderBottom = cssStyle.BorderStyle;
  942. style.BorderTop = cssStyle.BorderStyle;
  943. style.BorderLeft = cssStyle.BorderStyle;
  944. style.BorderRight = cssStyle.BorderStyle;
  945. if (cssStyle.BorderColor > 0)
  946. {
  947. style.BottomBorderColor = cssStyle.BorderColor;
  948. style.TopBorderColor = cssStyle.BorderColor;
  949. style.LeftBorderColor = cssStyle.BorderColor;
  950. style.RightBorderColor = cssStyle.BorderColor;
  951. }
  952. if (cssStyle.BottomBorderColor > 0)
  953. {
  954. style.BottomBorderColor = cssStyle.BottomBorderColor;
  955. }
  956. if (cssStyle.TopBorderColor > 0)
  957. {
  958. style.TopBorderColor = cssStyle.TopBorderColor;
  959. }
  960. if (cssStyle.RightBorderColor > 0)
  961. {
  962. style.RightBorderColor = cssStyle.RightBorderColor;
  963. }
  964. if (cssStyle.LeftBorderColor > 0)
  965. {
  966. style.LeftBorderColor = cssStyle.LeftBorderColor;
  967. }
  968. style.FillForegroundColor = cssStyle.FillBackgroundColor;
  969. style.FillPattern = FillPattern.Squares;
  970. style.FillBackgroundColor = cssStyle.FillBackgroundColor;
  971. style.WrapText = cssStyle.WrapText;
  972. style.VerticalAlignment = cssStyle.VerticalAlignment;
  973. style.Alignment = cssStyle.HorizontalAlignment;
  974. ExportTemplateFont fontStyle = cssStyle.FontStyle;
  975. IFont font = work.CreateFont();
  976. font.FontName = fontStyle.FontName;
  977. font.Color = fontStyle.Color;
  978. font.IsItalic = fontStyle.IsItalic;
  979. font.Boldweight = fontStyle.BoldWeight;
  980. font.FontHeightInPoints = fontStyle.FontHeightInPoints;
  981. style.SetFont(font);
  982. return style;
  983. }
  984. #region copy
  985. public static void CopyCellStyle(IWorkbook wb, ICellStyle fromStyle, ICellStyle toStyle)
  986. {
  987. toStyle.Alignment = fromStyle.Alignment;
  988. //边框和边框颜色
  989. toStyle.BorderBottom = fromStyle.BorderBottom;
  990. toStyle.BorderLeft = fromStyle.BorderLeft;
  991. toStyle.BorderRight = fromStyle.BorderRight;
  992. toStyle.BorderTop = fromStyle.BorderTop;
  993. toStyle.TopBorderColor = fromStyle.TopBorderColor;
  994. toStyle.BottomBorderColor = fromStyle.BottomBorderColor;
  995. toStyle.RightBorderColor = fromStyle.RightBorderColor;
  996. toStyle.LeftBorderColor = fromStyle.LeftBorderColor;
  997. //背景和前景
  998. toStyle.FillBackgroundColor = fromStyle.FillBackgroundColor;
  999. toStyle.FillForegroundColor = fromStyle.FillForegroundColor;
  1000. toStyle.DataFormat = fromStyle.DataFormat;
  1001. toStyle.FillPattern = fromStyle.FillPattern;
  1002. //toStyle.Hidden=fromStyle.Hidden;
  1003. toStyle.IsHidden = fromStyle.IsHidden;
  1004. toStyle.Indention = fromStyle.Indention;//首行缩进
  1005. toStyle.IsLocked = fromStyle.IsLocked;
  1006. toStyle.Rotation = fromStyle.Rotation;//旋转
  1007. toStyle.VerticalAlignment = fromStyle.VerticalAlignment;
  1008. toStyle.WrapText = fromStyle.WrapText;
  1009. toStyle.SetFont(fromStyle.GetFont(wb));
  1010. }
  1011. /// <summary>
  1012. /// 复制行
  1013. /// </summary>
  1014. /// <param name="wb"></param>
  1015. /// <param name="fromRow"></param>
  1016. /// <param name="toRow"></param>
  1017. /// <param name="copyValueFlag"></param>
  1018. public static void CopyRowEx(IWorkbook wb, IRow fromRow, IRow toRow, bool copyValueFlag)
  1019. {
  1020. System.Collections.IEnumerator cells = fromRow.GetEnumerator();//.GetRowEnumerator();
  1021. toRow.Height = fromRow.Height;
  1022. while (cells.MoveNext())
  1023. {
  1024. ICell cell = null;
  1025. //ICell cell = (wb is HSSFWorkbook) ? cells.Current as HSSFCell : cells.Current as NPOI.XSSF.UserModel.XSSFCell;
  1026. if (wb is HSSFWorkbook)
  1027. cell = cells.Current as HSSFCell;
  1028. else
  1029. cell = cells.Current as NPOI.XSSF.UserModel.XSSFCell;
  1030. ICell newCell = toRow.CreateCell(cell.ColumnIndex);
  1031. CopyCell(wb, cell, newCell, copyValueFlag);
  1032. }
  1033. }
  1034. /// <summary>
  1035. /// 复制原有sheet的合并单元格到新创建的sheet
  1036. /// </summary>
  1037. /// <param name="fromSheet"></param>
  1038. /// <param name="toSheet"></param>
  1039. public static void MergerRegion(ISheet fromSheet, ISheet toSheet)
  1040. {
  1041. int sheetMergerCount = fromSheet.NumMergedRegions;
  1042. for (int i = 0; i < sheetMergerCount; i++)
  1043. {
  1044. //Region mergedRegionAt = fromSheet.GetMergedRegion(i); //.MergedRegionAt(i);
  1045. //CellRangeAddress[] cra = new CellRangeAddress[1];
  1046. //cra[0] = fromSheet.GetMergedRegion(i);
  1047. //Region[] rg = Region.ConvertCellRangesToRegions(cra);
  1048. toSheet.AddMergedRegion(fromSheet.GetMergedRegion(i));
  1049. }
  1050. }
  1051. /// <summary>
  1052. /// 复制单元格
  1053. /// </summary>
  1054. /// <param name="wb"></param>
  1055. /// <param name="srcCell"></param>
  1056. /// <param name="distCell"></param>
  1057. /// <param name="copyValueFlag"></param>
  1058. public static void CopyCell(IWorkbook wb, ICell srcCell, ICell distCell, bool copyValueFlag)
  1059. {
  1060. ICellStyle newstyle = wb.CreateCellStyle();
  1061. CopyCellStyle(wb, srcCell.CellStyle, newstyle);
  1062. //样式
  1063. distCell.CellStyle = newstyle;
  1064. //评论
  1065. if (srcCell.CellComment != null)
  1066. {
  1067. distCell.CellComment = srcCell.CellComment;
  1068. }
  1069. // 不同数据类型处理
  1070. CellType srcCellType = srcCell.CellType;
  1071. distCell.SetCellType(srcCellType);
  1072. if (copyValueFlag)
  1073. {
  1074. if (srcCellType == CellType.Numeric)
  1075. {
  1076. if (DateUtil.IsCellDateFormatted(srcCell))
  1077. {
  1078. distCell.SetCellValue(srcCell.DateCellValue);
  1079. }
  1080. else
  1081. {
  1082. distCell.SetCellValue(srcCell.NumericCellValue);
  1083. }
  1084. }
  1085. else if (srcCellType == CellType.String)
  1086. {
  1087. distCell.SetCellValue(srcCell.RichStringCellValue);
  1088. }
  1089. else if (srcCellType == CellType.Blank)
  1090. {
  1091. // nothing21
  1092. }
  1093. else if (srcCellType == CellType.Boolean)
  1094. {
  1095. distCell.SetCellValue(srcCell.BooleanCellValue);
  1096. }
  1097. else if (srcCellType == CellType.Error)
  1098. {
  1099. distCell.SetCellErrorValue(srcCell.ErrorCellValue);
  1100. }
  1101. else if (srcCellType == CellType.Formula)
  1102. {
  1103. distCell.SetCellFormula(srcCell.CellFormula);
  1104. }
  1105. else
  1106. {
  1107. // nothing29
  1108. }
  1109. }
  1110. }
  1111. #endregion
  1112. #endregion
  1113. }
  1114. public class ExportTemplateCss
  1115. {
  1116. /// <summary>
  1117. /// 上下左右边框
  1118. /// </summary>
  1119. public BorderStyle BorderStyle { get; set; } = BorderStyle.Thin;
  1120. public short TopBorderColor { get; set; }
  1121. public short RightBorderColor { get; set; }
  1122. public short LeftBorderColor { get; set; }
  1123. public short BottomBorderColor { get; set; }
  1124. public short BorderColor { get; set; }
  1125. /// <summary>
  1126. /// 背景色
  1127. /// </summary>
  1128. public short FillBackgroundColor { get; set; } = (short) ColorType.White;
  1129. /// <summary>
  1130. /// 文字换行
  1131. /// </summary>
  1132. public bool WrapText { get; set; } = false;
  1133. public VerticalAlignment VerticalAlignment { get; set; } = VerticalAlignment.Center;
  1134. public HorizontalAlignment HorizontalAlignment { get; set; } = HorizontalAlignment.Center;
  1135. public ExportTemplateFont FontStyle { get; set; }
  1136. }
  1137. public class ExportTemplateFont
  1138. {
  1139. public string FontName { get; set; } = "微软雅黑";
  1140. public bool IsItalic { get; set; } = false;
  1141. public short Color { get; set; } = (short) ColorType.Black;
  1142. public short BoldWeight { get; set; } = (short) FontBoldWeight.Bold;
  1143. public int FontHeightInPoints { get; set; } = 12;
  1144. //public bool IsBold { get; set; } = false;
  1145. }
  1146. }