Açıklama Yok

NPOIHelper.cs 198KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Web;
  9. using NPOI.HSSF.UserModel;
  10. using NPOI.OpenXmlFormats.Wordprocessing;
  11. using NPOI.SS.UserModel;
  12. using NPOI.SS.Util;
  13. using NPOI.XSSF.UserModel;
  14. namespace CallCenter.Utility
  15. {
  16. public class NPOIHelper
  17. {
  18. private string _title;
  19. private string _sheetName;
  20. private string _filePath;
  21. /// <summary>
  22. /// 导出到Excel
  23. /// </summary>
  24. /// <param name="table"></param>
  25. /// <returns></returns>
  26. public bool ToExcel(DataTable table, string[] columns = null)
  27. {
  28. FileStream fs = new FileStream(this._filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
  29. IWorkbook workBook = new HSSFWorkbook();
  30. if (string.IsNullOrWhiteSpace(this._sheetName))
  31. {
  32. this._sheetName = "sheet1";
  33. }
  34. ISheet sheet = workBook.CreateSheet(this._sheetName);
  35. //处理表格标题
  36. IRow row = sheet.CreateRow(0);
  37. row.CreateCell(0).SetCellValue(this._title);
  38. sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, table.Columns.Count - 1));
  39. row.Height = 500;
  40. ICellStyle cellStyle = workBook.CreateCellStyle();
  41. IFont font = workBook.CreateFont();
  42. font.FontName = "微软雅黑";
  43. font.FontHeightInPoints = 17;
  44. cellStyle.SetFont(font);
  45. cellStyle.VerticalAlignment = VerticalAlignment.Center;
  46. cellStyle.Alignment = HorizontalAlignment.Center;
  47. row.Cells[0].CellStyle = cellStyle;
  48. //处理表格列头
  49. row = sheet.CreateRow(1);
  50. if (columns == null)
  51. {
  52. for (int i = 0; i < table.Columns.Count; i++)
  53. {
  54. row.CreateCell(i).SetCellValue(table.Columns[i].ColumnName);
  55. row.Height = 350;
  56. sheet.AutoSizeColumn(i);
  57. }
  58. }
  59. else
  60. {
  61. for (int i = 0; i < columns.Length; i++)
  62. {
  63. row.CreateCell(i).SetCellValue(columns[i]);
  64. row.Height = 350;
  65. sheet.AutoSizeColumn(i);
  66. }
  67. }
  68. //处理数据内容
  69. for (int i = 0; i < table.Rows.Count; i++)
  70. {
  71. row = sheet.CreateRow(2 + i);
  72. row.Height = 250;
  73. for (int j = 0; j < table.Columns.Count; j++)
  74. {
  75. row.CreateCell(j).SetCellValue(table.Rows[i][j].ToString());
  76. sheet.SetColumnWidth(j, 256 * 15);
  77. }
  78. }
  79. //写入数据流
  80. workBook.Write(fs);
  81. fs.Flush();
  82. fs.Close();
  83. return true;
  84. }
  85. /// <summary>
  86. /// 导出到Excel
  87. /// </summary>
  88. /// <param name="table"></param>
  89. /// <param name="title"></param>
  90. /// <param name="sheetName">空字符串或null的话默认sheet1</param>
  91. /// <param name="columns">自定义表格列头,默认null</param>
  92. /// <returns></returns>
  93. public bool ToExcel(DataTable table, string title, string sheetName, string filePath, string[] columns = null)
  94. {
  95. this._title = title;
  96. this._sheetName = sheetName;
  97. this._filePath = filePath;
  98. return ToExcel(table, columns);
  99. }
  100. /// <summary>
  101. /// 投诉产品日期分布表
  102. /// </summary>
  103. /// <param name="ds"></param>
  104. /// <returns></returns>
  105. public string SatisfiedToExcel(string Name, IOrderedEnumerable<deptSatisfiedReport> deptSatisfied, string[] cols = null)
  106. {
  107. try
  108. {
  109. //if (dt.Rows.Count > 0)
  110. //{
  111. HSSFWorkbook workbook = new HSSFWorkbook();
  112. ISheet sheet = workbook.CreateSheet("Sheet1");
  113. ICellStyle HeadercellStyle = workbook.CreateCellStyle();
  114. HeadercellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  115. HeadercellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  116. HeadercellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  117. HeadercellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  118. HeadercellStyle.Alignment = HorizontalAlignment.Center;
  119. HeadercellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  120. HeadercellStyle.FillPattern = FillPattern.SolidForeground;
  121. HeadercellStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  122. //字体
  123. NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
  124. headerfont.Boldweight = (short)FontBoldWeight.Bold;
  125. headerfont.FontHeightInPoints = 12;
  126. HeadercellStyle.SetFont(headerfont);
  127. //用column name 作为列名
  128. int icolIndex = 0;
  129. IRow headerRow = sheet.CreateRow(0);
  130. foreach (string dc in cols)
  131. {
  132. ICell cell = headerRow.CreateCell(icolIndex);
  133. cell.SetCellValue(dc);
  134. cell.CellStyle = HeadercellStyle;
  135. icolIndex++;
  136. }
  137. ICellStyle cellStyle = workbook.CreateCellStyle();
  138. //为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
  139. cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
  140. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  141. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  142. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  143. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  144. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  145. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  146. cellStyle.SetFont(cellfont);
  147. //建立内容行
  148. int iRowIndex = 0;
  149. string strsj = "";
  150. foreach (var dr in deptSatisfied )
  151. {
  152. IRow irow = sheet.CreateRow(iRowIndex + 1);
  153. for (int i = 0; i <5 ; i++)
  154. {
  155. switch (i )
  156. {
  157. case 0:
  158. strsj = dr.deptname;
  159. ICell cell = irow.CreateCell(i);
  160. cell.SetCellValue(strsj);
  161. cell.CellStyle = cellStyle;
  162. break;
  163. case 1:
  164. strsj = dr.count.ToString ();
  165. ICell cell1 = irow.CreateCell(i);
  166. cell1.SetCellValue(strsj);
  167. cell1.CellStyle = cellStyle;
  168. break;
  169. case 2:
  170. strsj = dr.satisfiedcount.ToString();
  171. ICell cell2 = irow.CreateCell(i);
  172. cell2.SetCellValue(strsj);
  173. cell2.CellStyle = cellStyle;
  174. break;
  175. case 3:
  176. strsj = dr.notsatisfiedcount.ToString();
  177. ICell cell3 = irow.CreateCell(i);
  178. cell3.SetCellValue(strsj);
  179. cell3.CellStyle = cellStyle;
  180. break;
  181. case 4:
  182. strsj = dr.satisfiedrate;
  183. ICell cell4 = irow.CreateCell(i);
  184. cell4.SetCellValue(strsj);
  185. cell4.CellStyle = cellStyle;
  186. break;
  187. }
  188. }
  189. iRowIndex++;
  190. }
  191. //自适应列宽度
  192. for (int i = 0; i < icolIndex; i++)
  193. {
  194. sheet.AutoSizeColumn(i);
  195. }
  196. using (MemoryStream ms = new MemoryStream())
  197. {
  198. workbook.Write(ms);
  199. HttpContext curContext = HttpContext.Current;
  200. // 设置编码和附件格式
  201. curContext.Response.ContentType = "application/vnd.ms-excel";
  202. curContext.Response.ContentEncoding = Encoding.UTF8;
  203. curContext.Response.Charset = "";
  204. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  205. curContext.Response.AppendHeader("Content-Disposition",
  206. "attachment;filename=" + HttpUtility.UrlEncode(Name + ".xls", Encoding.UTF8));
  207. curContext.Response.BinaryWrite(ms.GetBuffer());
  208. workbook = null;
  209. ms.Close();
  210. ms.Dispose();
  211. curContext.Response.End();
  212. }
  213. //}
  214. return "";
  215. }
  216. catch
  217. {
  218. return "导出失败!";
  219. }
  220. }
  221. /// <summary>
  222. /// 弹出下载框导出excel
  223. /// </summary>
  224. /// <param name="Name"></param>
  225. /// <param name="dt"></param>
  226. /// <returns></returns>
  227. public string ExportToExcel(string Name, DataTable dt, string[] cols = null, int issort = 0)
  228. {
  229. try
  230. {
  231. //if (dt.Rows.Count > 0)
  232. //{
  233. HSSFWorkbook workbook = new HSSFWorkbook();
  234. ISheet sheet = workbook.CreateSheet(Name);
  235. ICellStyle HeadercellStyle = workbook.CreateCellStyle();
  236. HeadercellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  237. HeadercellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  238. HeadercellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  239. HeadercellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  240. HeadercellStyle.Alignment = HorizontalAlignment.Center;
  241. HeadercellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  242. HeadercellStyle.FillPattern = FillPattern.SolidForeground;
  243. HeadercellStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  244. //字体
  245. NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
  246. headerfont.Boldweight = (short)FontBoldWeight.Bold;
  247. headerfont.FontHeightInPoints = 12;
  248. HeadercellStyle.SetFont(headerfont);
  249. //用column name 作为列名
  250. int icolIndex = 0;
  251. IRow headerRow = sheet.CreateRow(0);
  252. if (issort == 1)
  253. {
  254. ICell cell = headerRow.CreateCell(icolIndex);
  255. cell.SetCellValue("序号");
  256. cell.CellStyle = HeadercellStyle;
  257. icolIndex++;
  258. }
  259. if (cols == null || (cols != null && cols.Length == 0))
  260. {
  261. foreach (DataColumn dc in dt.Columns)
  262. {
  263. ICell cell = headerRow.CreateCell(icolIndex);
  264. cell.SetCellValue(dc.ColumnName);
  265. cell.CellStyle = HeadercellStyle;
  266. icolIndex++;
  267. }
  268. }
  269. else
  270. {
  271. foreach (string dc in cols)
  272. {
  273. ICell cell = headerRow.CreateCell(icolIndex);
  274. cell.SetCellValue(dc);
  275. cell.CellStyle = HeadercellStyle;
  276. icolIndex++;
  277. }
  278. }
  279. ICellStyle cellStyle = workbook.CreateCellStyle();
  280. //为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
  281. cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
  282. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  283. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  284. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  285. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  286. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  287. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  288. cellStyle.SetFont(cellfont);
  289. //建立内容行
  290. int iRowIndex = 0;
  291. foreach (DataRow dr in dt.Rows)
  292. {
  293. int iCellIndex = 0;
  294. IRow irow = sheet.CreateRow(iRowIndex + 1);
  295. if (issort == 1)
  296. {
  297. ICell cell = irow.CreateCell(iCellIndex);
  298. cell.SetCellValue(iRowIndex + 1);
  299. cell.CellStyle = cellStyle;
  300. iCellIndex++;
  301. }
  302. for (int i = 0; i < icolIndex; i++)
  303. {
  304. string strsj = string.Empty;
  305. if (dr[i] != null)
  306. {
  307. strsj = dr[i].ToString();
  308. }
  309. ICell cell = irow.CreateCell(iCellIndex);
  310. cell.SetCellValue(strsj);
  311. cell.CellStyle = cellStyle;
  312. iCellIndex++;
  313. }
  314. iRowIndex++;
  315. }
  316. //自适应列宽度
  317. for (int i = 0; i < icolIndex; i++)
  318. {
  319. sheet.AutoSizeColumn(i);
  320. }
  321. using (MemoryStream ms = new MemoryStream())
  322. {
  323. workbook.Write(ms);
  324. HttpContext curContext = HttpContext.Current;
  325. // 设置编码和附件格式
  326. curContext.Response.ContentType = "application/vnd.ms-excel";
  327. curContext.Response.ContentEncoding = Encoding.UTF8;
  328. curContext.Response.Charset = "";
  329. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  330. curContext.Response.AppendHeader("Content-Disposition",
  331. "attachment;filename=" + HttpUtility.UrlEncode(Name + "_导出文件_" + DateTime.Now.Ticks + ".xls", Encoding.UTF8));
  332. curContext.Response.BinaryWrite(ms.GetBuffer());
  333. workbook = null;
  334. ms.Close();
  335. ms.Dispose();
  336. curContext.Response.End();
  337. }
  338. //}
  339. return "";
  340. }
  341. catch
  342. {
  343. return "导出失败!";
  344. }
  345. }
  346. /// <summary>
  347. /// 导入excel转换为datatable
  348. /// </summary>
  349. /// <param name="upfile"></param>
  350. /// <param name="headrow"></param>
  351. /// <returns></returns>
  352. public DataTable ExcelToTable(HttpPostedFile upfile, int headrow)
  353. {
  354. DataTable dt = new DataTable();
  355. IWorkbook workbook = null;
  356. Stream stream = upfile.InputStream;
  357. string suffix = upfile.FileName.Substring(upfile.FileName.LastIndexOf(".") + 1).ToLower();
  358. if (suffix == "xlsx") // 2007版本
  359. {
  360. workbook = new XSSFWorkbook(stream);
  361. }
  362. else if (suffix == "xls") // 2003版本
  363. {
  364. workbook = new HSSFWorkbook(stream);
  365. }
  366. //获取excel的第一个sheet
  367. ISheet sheet = workbook.GetSheetAt(0);
  368. //获取sheet的第一行
  369. IRow headerRow = sheet.GetRow(headrow);
  370. //一行最后一个方格的编号 即总的列数
  371. int cellCount = headerRow.LastCellNum;
  372. //最后一列的标号 即总的行数
  373. int rowCount = sheet.LastRowNum;
  374. //列名
  375. for (int i = 0; i < cellCount; i++)
  376. {
  377. dt.Columns.Add(headerRow.GetCell(i).ToString());
  378. }
  379. for (int i = (sheet.FirstRowNum + headrow + 1); i <= sheet.LastRowNum; i++)
  380. {
  381. DataRow dr = dt.NewRow();
  382. IRow row = sheet.GetRow(i);
  383. for (int j = row.FirstCellNum; j < cellCount; j++)
  384. {
  385. if (row.GetCell(j) != null)
  386. {
  387. dr[j] = row.GetCell(j).ToString();
  388. }
  389. }
  390. dt.Rows.Add(dr);
  391. }
  392. sheet = null;
  393. workbook = null;
  394. return dt;
  395. }
  396. /// <summary>
  397. /// 导入excel转换为datatable
  398. /// </summary>
  399. /// <param name="upfile"></param>
  400. /// <param name="headrow"></param>
  401. /// <returns></returns>
  402. public DataTable ExcelToTable(HttpPostedFileBase upfile, int headrow)
  403. {
  404. DataTable dt = new DataTable();
  405. IWorkbook workbook = null;
  406. Stream stream = upfile.InputStream;
  407. string suffix = upfile.FileName.Substring(upfile.FileName.LastIndexOf(".") + 1).ToLower();
  408. if (suffix == "xlsx") // 2007版本
  409. {
  410. workbook = new XSSFWorkbook(stream);
  411. }
  412. else if (suffix == "xls") // 2003版本
  413. {
  414. workbook = new HSSFWorkbook(stream);
  415. }
  416. //获取excel的第一个sheet
  417. ISheet sheet = workbook.GetSheetAt(0);
  418. //获取sheet的第一行
  419. IRow headerRow = sheet.GetRow(headrow);
  420. //一行最后一个方格的编号 即总的列数
  421. int cellCount = headerRow.LastCellNum;
  422. //最后一列的标号 即总的行数
  423. int rowCount = sheet.LastRowNum;
  424. //列名
  425. for (int i = 0; i < cellCount; i++)
  426. {
  427. dt.Columns.Add(headerRow.GetCell(i).ToString());
  428. }
  429. for (int i = (sheet.FirstRowNum + headrow + 1); i <= sheet.LastRowNum; i++)
  430. {
  431. DataRow dr = dt.NewRow();
  432. IRow row = sheet.GetRow(i);
  433. for (int j = row.FirstCellNum; j < cellCount; j++)
  434. {
  435. if (row.GetCell(j) != null)
  436. {
  437. dr[j] = row.GetCell(j).ToString().Trim(' ').Trim('\t');
  438. }
  439. }
  440. dt.Rows.Add(dr);
  441. }
  442. sheet = null;
  443. workbook = null;
  444. return dt;
  445. }
  446. private string GetCellValue(DataRow dr,int index,int i )
  447. {
  448. string str = "";
  449. switch (i)
  450. {
  451. case 0:
  452. str = index.ToString();
  453. break;
  454. case 1:
  455. str = dr["deptname"].ToString();
  456. break;
  457. case 2:
  458. str = dr["Undertakers"].ToString();
  459. break;
  460. case 3:
  461. str = dr["Undertakersrate"].ToString();
  462. break;
  463. case 4:
  464. str = dr["Undertakersscore"].ToString();
  465. break;
  466. case 5:
  467. str = dr["overdue"].ToString();
  468. break;
  469. case 6:
  470. str = dr["overduerate"].ToString();
  471. break;
  472. case 7:
  473. str = dr["overduescore"].ToString();
  474. break;
  475. case 8:
  476. str = dr["unsuccessful"].ToString();
  477. break;
  478. case 9:
  479. str = dr["unsuccessfulrate"].ToString();
  480. break;
  481. case 10:
  482. str = dr["unsuccessfulscore"].ToString();
  483. break;
  484. case 11:
  485. str = dr["Chargeback"].ToString();
  486. break;
  487. case 12:
  488. str = dr["Chargebackrate"].ToString();
  489. break;
  490. case 13:
  491. str = dr["Chargebackscore"].ToString();
  492. break;
  493. case 14:
  494. str = dr["Comment"].ToString();
  495. break;
  496. case 15:
  497. str = dr["Oncedissatisfied"].ToString();
  498. break;
  499. case 16:
  500. str = dr["twocedissatisfied"].ToString();
  501. break;
  502. case 17:
  503. str = dr["dissatisfied"].ToString();
  504. break;
  505. case 18:
  506. str = dr["satisfiedrate"].ToString();
  507. break;
  508. case 19:
  509. str = dr["satisfiedscore"].ToString();
  510. break;
  511. case 20:
  512. str = dr["total"].ToString();
  513. break;
  514. case 21:
  515. str = index.ToString();
  516. break;
  517. }
  518. return str;
  519. }
  520. public string ExcelMergerHotline(List <MergerHot.MergerHotSource> mergerHotSources
  521. )
  522. {
  523. return "";
  524. }
  525. public class Incoming
  526. {
  527. public string time { set; get; }
  528. public int IncomingCount { set; get; }//呼入量
  529. public int Oncapacity { set; get; }//接通量
  530. public int seatsCount { set; get; }
  531. public string seats { set; get; }
  532. public int newIncomingCount { set; get; }//呼入量
  533. public int newOncapacity { set; get; }//接通量
  534. public string newseats { set; get; }
  535. public int newseatsCount { set; get; }
  536. }
  537. /// <summary>
  538. /// 数据报表导出
  539. /// </summary>
  540. /// <param name="ds"></param>
  541. /// <returns></returns>
  542. public string IncomingCalls(List <Incoming> incomings )
  543. {
  544. try
  545. {
  546. HSSFWorkbook workbook = new HSSFWorkbook();
  547. ISheet sheet = workbook.CreateSheet("12345来电情况统计表");
  548. ICellStyle cellStyle = workbook.CreateCellStyle();
  549. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  550. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  551. cellStyle.SetFont(cellfont);
  552. ICellStyle cellStylebt = workbook.CreateCellStyle();
  553. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  554. cellfontbt.Boldweight = (short)FontBoldWeight.Normal;
  555. cellStylebt.SetFont(cellfontbt);
  556. cellfontbt.FontHeightInPoints = 10;
  557. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  558. cellStylebt.Alignment = HorizontalAlignment.Center;
  559. cellStylebt.WrapText = true;
  560. IRow irow1 = sheet.CreateRow(0);
  561. ICell cell1 = irow1.CreateCell(0);
  562. cell1.SetCellValue("12345来电情况统计表");
  563. cell1.CellStyle = cellStylebt;
  564. irow1.Height = 50 * 20;
  565. sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 4));
  566. string[] cols = {"时间段","来电总量","接听总量(呼入已接通)","12345来电量","12345接听量(呼入已接通)",
  567. "12345坐席个数","12345坐席姓名" ,
  568. "专家坐席个数","专家坐席姓名" };
  569. IRow irow4 = sheet.CreateRow(1);
  570. int icolIndex = 0;
  571. foreach (string dc in cols)
  572. {
  573. ICell cell = irow4.CreateCell(icolIndex);
  574. cell.SetCellValue(dc);
  575. cell.CellStyle = cellStylebt;
  576. irow4.Height = 50*15;
  577. icolIndex++;
  578. }
  579. int iRowIndex = 2;
  580. int index = 0;
  581. foreach (var dr in incomings)
  582. {
  583. index++;
  584. IRow irow = sheet.CreateRow(iRowIndex);
  585. ICell cell = irow.CreateCell(0);
  586. cell.SetCellValue(dr.time );
  587. cell.CellStyle = cellStylebt;
  588. ICell cel2 = irow.CreateCell(1);
  589. cel2.SetCellValue(dr.newIncomingCount );
  590. cel2.CellStyle = cellStylebt;
  591. ICell cel3 = irow.CreateCell(2);
  592. cel3.SetCellValue(dr.newOncapacity );
  593. cel3.CellStyle = cellStylebt;
  594. ICell cel5 = irow.CreateCell(3);
  595. cel5.SetCellValue(dr.IncomingCount);
  596. cel5.CellStyle = cellStylebt;
  597. ICell cel6 = irow.CreateCell(4);
  598. cel6.SetCellValue(dr.Oncapacity);
  599. cel6.CellStyle = cellStylebt;
  600. if (dr.time=="共计")
  601. {
  602. ICell cel4 = irow.CreateCell(5);
  603. cel4.SetCellValue("");
  604. cel4.CellStyle = cellStylebt;
  605. }
  606. else
  607. {
  608. ICell cel4 = irow.CreateCell(5);
  609. cel4.SetCellValue(dr.seatsCount);
  610. cel4.CellStyle = cellStylebt;
  611. }
  612. ICell cel8 = irow.CreateCell(6);
  613. cel8.SetCellValue(dr.seats );
  614. cel8.CellStyle = cellStylebt;
  615. if (dr.time == "共计")
  616. {
  617. ICell cel9 = irow.CreateCell(7);
  618. cel9.SetCellValue("");
  619. cel9.CellStyle = cellStylebt;
  620. }
  621. else
  622. {
  623. ICell cel9 = irow.CreateCell(7);
  624. cel9.SetCellValue(dr.newseatsCount);
  625. cel9.CellStyle = cellStylebt;
  626. }
  627. ICell cel0 = irow.CreateCell(8);
  628. cel0.SetCellValue(dr.newseats);
  629. cel0.CellStyle = cellStylebt;
  630. irow.Height = 50*15;
  631. iRowIndex++;
  632. }
  633. //自适应列宽度
  634. for (int i = 0; i < 5; i++)
  635. {
  636. sheet.AutoSizeColumn(i);
  637. // sheet.SetColumnWidth(i, 20 * 256);
  638. }
  639. using (MemoryStream ms = new MemoryStream())
  640. {
  641. workbook.Write(ms);
  642. HttpContext curContext = HttpContext.Current;
  643. // 设置编码和附件格式
  644. curContext.Response.ContentType = "application/vnd.ms-excel";
  645. curContext.Response.ContentEncoding = Encoding.UTF8;
  646. curContext.Response.Charset = "";
  647. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  648. curContext.Response.AppendHeader("Content-Disposition",
  649. "attachment;filename=" + HttpUtility.UrlEncode("12345来电情况统计表" + ".xls", Encoding.UTF8));
  650. curContext.Response.BinaryWrite(ms.GetBuffer());
  651. workbook = null;
  652. ms.Close();
  653. ms.Dispose();
  654. curContext.Response.End();
  655. }
  656. return "";
  657. }
  658. catch
  659. {
  660. return "导出失败!";
  661. }
  662. }
  663. public int Evaluation(string message,DataTable dt ,int index, ISheet sheet, ICellStyle cellStylebt, HSSFWorkbook workbook)
  664. {
  665. IRow irow01 = sheet.CreateRow(index);
  666. ICell cell01 = irow01.CreateCell(0);
  667. cell01.SetCellValue(message);
  668. cell01.CellStyle = cellStylebt;
  669. irow01.Height = 40 * 20;
  670. sheet.AddMergedRegion(new CellRangeAddress(index, index, 0, 16));
  671. index = index + 1;
  672. IRow irow1 = sheet.CreateRow(index);
  673. ICell cell1 = irow1.CreateCell(0);
  674. cell1.SetCellValue("序号");
  675. cell1.CellStyle = cellStylebt;
  676. sheet.AddMergedRegion(new CellRangeAddress(2, 3, 0, 0));
  677. ICell cell2 = irow1.CreateCell(1);
  678. cell2.SetCellValue("部门名称");
  679. cell2.CellStyle = cellStylebt;
  680. sheet.AddMergedRegion(new CellRangeAddress(2, 3, 1, 1));
  681. ICell cell14 = irow1.CreateCell(10);
  682. cell14.SetCellValue("回访量");
  683. cell14.CellStyle = cellStylebt;
  684. sheet.AddMergedRegion(new CellRangeAddress(2, 3, 10, 10));
  685. ICell cell15 = irow1.CreateCell(11);
  686. cell15.SetCellValue("满意量");
  687. cell15.CellStyle = cellStylebt;
  688. sheet.AddMergedRegion(new CellRangeAddress(2, 3, 11, 11));
  689. ICell cell4 = irow1.CreateCell(12);
  690. cell4.SetCellValue("回访满意度");
  691. cell4.CellStyle = cellStylebt;
  692. sheet.AddMergedRegion(new CellRangeAddress(2, 3, 12, 12));
  693. ICell cell5 = irow1.CreateCell(13);
  694. cell5.SetCellValue("知识库更新");
  695. cell5.CellStyle = cellStylebt;
  696. sheet.AddMergedRegion(new CellRangeAddress(2, 3, 13, 13));
  697. ICell cell8 = irow1.CreateCell(14);
  698. cell8.SetCellValue("热线整合");
  699. cell8.CellStyle = cellStylebt;
  700. sheet.AddMergedRegion(new CellRangeAddress(2, 3, 14, 14));
  701. ICell cell6 = irow1.CreateCell(15);
  702. cell6.SetCellValue("加扣分项");
  703. cell6.CellStyle = cellStylebt;
  704. sheet.AddMergedRegion(new CellRangeAddress(2, 3, 15, 15));
  705. ICell cell7 = irow1.CreateCell(16);
  706. cell7.SetCellValue("总分");
  707. cell7.CellStyle = cellStylebt;
  708. sheet.AddMergedRegion(new CellRangeAddress(2, 3, 16, 16));
  709. ICell cell9 = irow1.CreateCell(2);
  710. cell9.SetCellValue("事项报备");
  711. cell9.CellStyle = cellStylebt;
  712. sheet.AddMergedRegion(new CellRangeAddress(2, 2, 2, 3));
  713. ICell cell10 = irow1.CreateCell(4);
  714. cell10.SetCellValue("事项办理");
  715. cell10.CellStyle = cellStylebt;
  716. sheet.AddMergedRegion(new CellRangeAddress(2, 2, 4, 5));
  717. ICell cell12 = irow1.CreateCell(6);
  718. cell12.SetCellValue("办理时限");
  719. cell12.CellStyle = cellStylebt;
  720. sheet.AddMergedRegion(new CellRangeAddress(2, 2, 6, 7));
  721. ICell cell13 = irow1.CreateCell(8);
  722. cell13.SetCellValue("重办事项");
  723. cell13.CellStyle = cellStylebt;
  724. sheet.AddMergedRegion(new CellRangeAddress(2, 2, 8, 9));
  725. index = index + 1;
  726. IRow irow3 = sheet.CreateRow(index);
  727. ICell cell11 = irow3.CreateCell(2);
  728. cell11.SetCellValue("数量");
  729. cell11.CellStyle = cellStylebt;
  730. ICell cell16 = irow3.CreateCell(3);
  731. cell16.SetCellValue("得分");
  732. cell16.CellStyle = cellStylebt;
  733. ICell cell17 = irow3.CreateCell(4);
  734. cell17.SetCellValue("承办量");
  735. cell17.CellStyle = cellStylebt;
  736. ICell cell18 = irow3.CreateCell(5);
  737. cell18.SetCellValue("得分");
  738. cell18.CellStyle = cellStylebt;
  739. ICell cell19 = irow3.CreateCell(6);
  740. cell19.SetCellValue("逾期量");
  741. cell19.CellStyle = cellStylebt;
  742. ICell cell20 = irow3.CreateCell(7);
  743. cell20.SetCellValue("得分");
  744. cell20.CellStyle = cellStylebt;
  745. ICell cell21 = irow3.CreateCell(8);
  746. cell21.SetCellValue("重办量");
  747. cell21.CellStyle = cellStylebt;
  748. ICell cell22 = irow3.CreateCell(9);
  749. cell22.SetCellValue("得分");
  750. cell22.CellStyle = cellStylebt;
  751. ICellStyle cellStylebt1 = workbook.CreateCellStyle();
  752. NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
  753. cellfontbt1.Boldweight = (short)FontBoldWeight.Normal;
  754. cellStylebt1.SetFont(cellfontbt1);
  755. cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
  756. cellStylebt1.Alignment = HorizontalAlignment.Center;
  757. index = index + 1;
  758. if (dt != null && dt.Rows.Count > 0)
  759. {
  760. int iCellIndex = 0;
  761. foreach (DataRow dr in dt.Rows)
  762. {
  763. IRow irow4 = sheet.CreateRow(index);
  764. index++;
  765. iCellIndex++;
  766. for (int i = 0; i < 17; i++)
  767. {
  768. switch (i)
  769. {
  770. case 0:
  771. ICell cell = irow4.CreateCell(i);
  772. cell.SetCellValue(iCellIndex);
  773. cell.CellStyle = cellStylebt1;
  774. break;
  775. case 1:
  776. ICell cel1 = irow4.CreateCell(i);
  777. cel1.SetCellValue(dr["F_DeptName"].ToString());
  778. cel1.CellStyle = cellStylebt1;
  779. break;
  780. case 2:
  781. ICell cel2 = irow4.CreateCell(i);
  782. cel2.SetCellValue(dr["F_Reporting"].ToString());
  783. cel2.CellStyle = cellStylebt1;
  784. break;
  785. case 3:
  786. ICell cel12 = irow4.CreateCell(i);
  787. cel12.SetCellValue(dr["F_Matter"].ToString());
  788. cel12.CellStyle = cellStylebt1;
  789. break;
  790. case 4:
  791. ICell cel3 = irow4.CreateCell(i);
  792. cel3.SetCellValue(dr["F_Undertake"].ToString());
  793. cel3.CellStyle = cellStylebt1;
  794. break;
  795. case 5:
  796. ICell cel13 = irow4.CreateCell(i);
  797. cel13.SetCellValue(dr["F_Handling"].ToString());
  798. cel13.CellStyle = cellStylebt1;
  799. break;
  800. case 6:
  801. ICell cel4 = irow4.CreateCell(i);
  802. cel4.SetCellValue(dr["F_Boverdue"].ToString());
  803. cel4.CellStyle = cellStylebt1;
  804. break;
  805. case 7:
  806. ICell cel14 = irow4.CreateCell(i);
  807. cel14.SetCellValue(dr["F_Timelimit"].ToString());
  808. cel14.CellStyle = cellStylebt1;
  809. break;
  810. case 8:
  811. ICell cel15 = irow4.CreateCell(i);
  812. cel15.SetCellValue(dr["F_Redovolume"].ToString());
  813. cel15.CellStyle = cellStylebt1;
  814. break;
  815. case 9:
  816. ICell cel5 = irow4.CreateCell(i);
  817. cel5.SetCellValue(dr["F_Redo"].ToString());
  818. cel5.CellStyle = cellStylebt1;
  819. break;
  820. case 10:
  821. ICell cel16 = irow4.CreateCell(i);
  822. cel16.SetCellValue(dr["F_Returnvisit"].ToString());
  823. cel16.CellStyle = cellStylebt1;
  824. break;
  825. case 11:
  826. ICell cel17 = irow4.CreateCell(i);
  827. cel17.SetCellValue(dr["F_Satisfaction"].ToString());
  828. cel17.CellStyle = cellStylebt1;
  829. break;
  830. case 12:
  831. ICell cel6 = irow4.CreateCell(i);
  832. cel6.SetCellValue(dr["F_Satisfied"].ToString());
  833. cel6.CellStyle = cellStylebt1;
  834. break;
  835. case 13:
  836. ICell cel7 = irow4.CreateCell(i);
  837. cel7.SetCellValue(dr["F_knowledge"].ToString());
  838. cel7.CellStyle = cellStylebt1;
  839. break;
  840. case 14:
  841. ICell cel10 = irow4.CreateCell(i);
  842. cel10.SetCellValue(dr["F_Integration"].ToString());
  843. cel10.CellStyle = cellStylebt1;
  844. break;
  845. case 15:
  846. ICell cel8 = irow4.CreateCell(i);
  847. cel8.SetCellValue(dr["F_Buckle"].ToString());
  848. cel8.CellStyle = cellStylebt1;
  849. break;
  850. case 16:
  851. ICell cel9 = irow4.CreateCell(i);
  852. cel9.SetCellValue(dr["F_Total"].ToString());
  853. cel9.CellStyle = cellStylebt1;
  854. break;
  855. }
  856. }
  857. }
  858. }
  859. return index;
  860. }
  861. /// <summary>
  862. /// 督办数据报表导出
  863. /// </summary>
  864. /// <param name="ds"></param>
  865. /// <returns></returns>
  866. public string ExportEvaluation(DataTable dt, DataTable dt1, DataTable dt2, DataTable dt3, string message,string data)
  867. {
  868. try
  869. {
  870. HSSFWorkbook workbook = new HSSFWorkbook();
  871. ISheet sheet = workbook.CreateSheet("月度评价报表");
  872. ICellStyle cellStyle = workbook.CreateCellStyle();
  873. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  874. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  875. cellStyle.SetFont(cellfont);
  876. ICellStyle cellStylebt = workbook.CreateCellStyle();
  877. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  878. cellfontbt.Boldweight = (short)FontBoldWeight.Bold;
  879. cellStylebt.SetFont(cellfontbt);
  880. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  881. cellStylebt.Alignment = HorizontalAlignment.Center;
  882. IRow irow0 = sheet.CreateRow(0);
  883. ICell cell0 = irow0.CreateCell(0);
  884. cell0.SetCellValue(data+"月份市长热线承办单位办理情况统计表");
  885. cell0.CellStyle = cellStylebt;
  886. irow0.Height = 50 * 20;
  887. sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 16));
  888. IRow irow00 = sheet.CreateRow(1);
  889. ICell cell00 = irow00.CreateCell(0);
  890. cell00.SetCellValue(message);
  891. cell00.CellStyle = cellStylebt;
  892. irow00.Height = 40 * 20;
  893. sheet.AddMergedRegion(new CellRangeAddress(1, 1, 0, 16));
  894. int index1 = Evaluation("一、县区", dt, 2, sheet, cellStylebt, workbook);
  895. int index2 = Evaluation("二、市直单位", dt1, index1+1, sheet, cellStylebt, workbook);
  896. int index3 = Evaluation("三、公共服务企业", dt2, index2+1, sheet, cellStylebt, workbook);
  897. int index4 = Evaluation("四、未办件单位", dt3, index3 + 1, sheet, cellStylebt, workbook);
  898. //自适应列宽度
  899. for (int i = 0; i < 10; i++)
  900. {
  901. // sheet.AutoSizeColumn(i);
  902. if (i ==1)
  903. sheet.SetColumnWidth(i, 28 * 256);
  904. else
  905. sheet.SetColumnWidth(i, 15 * 256);
  906. }
  907. using (MemoryStream ms = new MemoryStream())
  908. {
  909. workbook.Write(ms);
  910. HttpContext curContext = HttpContext.Current;
  911. // 设置编码和附件格式
  912. curContext.Response.ContentType = "application/vnd.ms-excel";
  913. curContext.Response.ContentEncoding = Encoding.UTF8;
  914. curContext.Response.Charset = "";
  915. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  916. curContext.Response.AppendHeader("Content-Disposition",
  917. "attachment;filename=" + HttpUtility.UrlEncode("月度评价报表" + ".xls", Encoding.UTF8));
  918. curContext.Response.BinaryWrite(ms.GetBuffer());
  919. workbook = null;
  920. ms.Close();
  921. ms.Dispose();
  922. curContext.Response.End();
  923. }
  924. return "";
  925. }
  926. catch
  927. {
  928. return "导出失败!";
  929. }
  930. }
  931. /// <summary>
  932. /// 督办数据报表导出
  933. /// </summary>
  934. /// <param name="ds"></param>
  935. /// <returns></returns>
  936. public string DBExportToExcel(DataTable dt,string Name,string month,string starttime ,string endtime )
  937. {
  938. try
  939. {
  940. HSSFWorkbook workbook = new HSSFWorkbook();
  941. ISheet sheet = workbook.CreateSheet(Name);
  942. ICellStyle cellStyle = workbook.CreateCellStyle();
  943. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  944. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  945. cellStyle.SetFont(cellfont);
  946. ICellStyle cellStylebt = workbook.CreateCellStyle();
  947. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  948. cellfontbt.Boldweight = (short)FontBoldWeight.Bold;
  949. cellStylebt.SetFont(cellfontbt);
  950. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  951. cellStylebt.Alignment = HorizontalAlignment.Center;
  952. IRow irow1 = sheet.CreateRow(0);
  953. ICell cell1 = irow1.CreateCell(0);
  954. cell1.SetCellValue("12345联动服务工作"+ month + "月份办理情况通报表");
  955. cell1.CellStyle = cellStylebt;
  956. sheet.AddMergedRegion(new CellRangeAddress(0, 1, 0, 19));
  957. IRow irow2 = sheet.CreateRow(2);
  958. ICell cell2 = irow2.CreateCell(0);
  959. cell2.SetCellValue("统计周期:"+ starttime+"至"+ endtime+" 统计时间:"+DateTime .Now.ToString ("yyyy年MM月dd日"));
  960. cell2.CellStyle = cellStylebt;
  961. sheet.AddMergedRegion(new CellRangeAddress(2, 2, 0, 19));
  962. IRow irow3 = sheet.CreateRow(3);
  963. ICell cell3 = irow3.CreateCell(0);
  964. cell3.SetCellValue("一、县(市、区)联动单位");
  965. cell3.CellStyle = cellStylebt;
  966. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 0, 19));
  967. string[] cols = {"序号","联动单位","承办件",
  968. "承办率","得分(5分)","超期件","按时反馈率","得分(20分)",
  969. "未果件","办结率","得分(10分)","退单件","有效回复率",
  970. "得分(15分)","群众评议总数","一次不满意件","二次不满意件","不满意件","满意率","得分(50分)","总分","排名"};
  971. IRow irow4 = sheet.CreateRow(4);
  972. int icolIndex = 0;
  973. foreach (string dc in cols)
  974. {
  975. ICell cell = irow4.CreateCell(icolIndex);
  976. cell.SetCellValue(dc);
  977. cell.CellStyle = cellStylebt;
  978. icolIndex++;
  979. }
  980. int iRowIndex = 5;
  981. DataRow[] rows = dt.Select("category=1");
  982. int index = 0;
  983. foreach (DataRow dr in rows)
  984. {
  985. index++;
  986. int iCellIndex = 0;
  987. IRow irow = sheet.CreateRow(iRowIndex );
  988. for (int i = 0; i < 22; i++)
  989. {
  990. ICell cell = irow.CreateCell(iCellIndex);
  991. cell.SetCellValue(GetCellValue(dr, index,i ));
  992. cell.CellStyle = cellStyle;
  993. iCellIndex++;
  994. }
  995. iRowIndex++;
  996. }
  997. IRow irow5 = sheet.CreateRow(iRowIndex);
  998. ICell cell5 = irow5.CreateCell(0);
  999. cell5.SetCellValue("二、市直机关联动单位一组");
  1000. cell5.CellStyle = cellStylebt;
  1001. sheet.AddMergedRegion(new CellRangeAddress(iRowIndex, iRowIndex, 0, 19));
  1002. iRowIndex++;
  1003. IRow irow6 = sheet.CreateRow(iRowIndex);
  1004. icolIndex = 0;
  1005. foreach (string dc in cols)
  1006. {
  1007. ICell cell = irow6.CreateCell(icolIndex);
  1008. cell.SetCellValue(dc);
  1009. cell.CellStyle = cellStylebt;
  1010. icolIndex++;
  1011. }
  1012. iRowIndex++;
  1013. rows = dt.Select("category=2");
  1014. index = 0;
  1015. foreach (DataRow dr in rows)
  1016. {
  1017. index++;
  1018. int iCellIndex = 0;
  1019. IRow irow = sheet.CreateRow(iRowIndex);
  1020. for (int i = 0; i < 22; i++)
  1021. {
  1022. ICell cell = irow.CreateCell(iCellIndex);
  1023. cell.SetCellValue(GetCellValue(dr, index,i ));
  1024. cell.CellStyle = cellStyle;
  1025. iCellIndex++;
  1026. }
  1027. iRowIndex++;
  1028. }
  1029. IRow irow7 = sheet.CreateRow(iRowIndex);
  1030. ICell cell7 = irow7.CreateCell(0);
  1031. cell7.SetCellValue("三、市直机关联动单位二组");
  1032. cell7.CellStyle = cellStylebt;
  1033. sheet.AddMergedRegion(new CellRangeAddress(iRowIndex, iRowIndex, 0, 19));
  1034. iRowIndex++;
  1035. IRow irow8 = sheet.CreateRow(iRowIndex);
  1036. icolIndex = 0;
  1037. foreach (string dc in cols)
  1038. {
  1039. ICell cell = irow8.CreateCell(icolIndex);
  1040. cell.SetCellValue(dc);
  1041. cell.CellStyle = cellStylebt;
  1042. icolIndex++;
  1043. }
  1044. iRowIndex++;
  1045. rows = dt.Select("category=3");
  1046. index = 0;
  1047. foreach (DataRow dr in rows)
  1048. {
  1049. index++;
  1050. int iCellIndex = 0;
  1051. IRow irow = sheet.CreateRow(iRowIndex);
  1052. for (int i = 0; i < 22; i++)
  1053. {
  1054. ICell cell = irow.CreateCell(iCellIndex);
  1055. cell.SetCellValue(GetCellValue(dr, index,i ));
  1056. cell.CellStyle = cellStyle;
  1057. iCellIndex++;
  1058. }
  1059. iRowIndex++;
  1060. }
  1061. IRow irow9 = sheet.CreateRow(iRowIndex);
  1062. ICell cell9 = irow9.CreateCell(0);
  1063. cell9.SetCellValue("四、公益型企业联动单位");
  1064. cell9.CellStyle = cellStylebt;
  1065. sheet.AddMergedRegion(new CellRangeAddress(iRowIndex, iRowIndex, 0, 19));
  1066. iRowIndex++;
  1067. IRow irow10 = sheet.CreateRow(iRowIndex);
  1068. icolIndex = 0;
  1069. foreach (string dc in cols)
  1070. {
  1071. ICell cell = irow10.CreateCell(icolIndex);
  1072. cell.SetCellValue(dc);
  1073. cell.CellStyle = cellStylebt;
  1074. icolIndex++;
  1075. }
  1076. iRowIndex++;
  1077. rows = dt.Select("category=4");
  1078. index = 0;
  1079. foreach (DataRow dr in rows)
  1080. {
  1081. index++;
  1082. int iCellIndex = 0;
  1083. IRow irow = sheet.CreateRow(iRowIndex);
  1084. for (int i = 0; i < 22; i++)
  1085. {
  1086. ICell cell = irow.CreateCell(iCellIndex);
  1087. cell.SetCellValue(GetCellValue(dr, index,i ));
  1088. cell.CellStyle = cellStyle;
  1089. iCellIndex++;
  1090. }
  1091. iRowIndex++;
  1092. }
  1093. //自适应列宽度
  1094. for (int i = 0; i < 20; i++)
  1095. {
  1096. sheet.AutoSizeColumn(i);
  1097. // sheet.SetColumnWidth(i, 20 * 256);
  1098. }
  1099. using (MemoryStream ms = new MemoryStream())
  1100. {
  1101. workbook.Write(ms);
  1102. HttpContext curContext = HttpContext.Current;
  1103. // 设置编码和附件格式
  1104. curContext.Response.ContentType = "application/vnd.ms-excel";
  1105. curContext.Response.ContentEncoding = Encoding.UTF8;
  1106. curContext.Response.Charset = "";
  1107. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  1108. curContext.Response.AppendHeader("Content-Disposition",
  1109. "attachment;filename=" + HttpUtility.UrlEncode(Name + ".xls", Encoding.UTF8));
  1110. curContext.Response.BinaryWrite(ms.GetBuffer());
  1111. workbook = null;
  1112. ms.Close();
  1113. ms.Dispose();
  1114. curContext.Response.End();
  1115. }
  1116. return "";
  1117. }
  1118. catch
  1119. {
  1120. return "导出失败!";
  1121. }
  1122. }
  1123. /// <summary>
  1124. /// 督办数据报表导出
  1125. /// </summary>
  1126. /// <param name="ds"></param>
  1127. /// <returns></returns>
  1128. public string DBEJExportToExcel(DataTable dt, string Name, string month, string starttime, string endtime)
  1129. {
  1130. try
  1131. {
  1132. HSSFWorkbook workbook = new HSSFWorkbook();
  1133. ISheet sheet = workbook.CreateSheet(Name);
  1134. ICellStyle cellStyle = workbook.CreateCellStyle();
  1135. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  1136. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  1137. cellStyle.SetFont(cellfont);
  1138. ICellStyle cellStylebt = workbook.CreateCellStyle();
  1139. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  1140. cellfontbt.Boldweight = (short)FontBoldWeight.Bold;
  1141. cellStylebt.SetFont(cellfontbt);
  1142. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  1143. cellStylebt.Alignment = HorizontalAlignment.Center;
  1144. IRow irow1 = sheet.CreateRow(0);
  1145. ICell cell1 = irow1.CreateCell(0);
  1146. cell1.SetCellValue("12345联动服务工作" + month + "月份办理情况通报表");
  1147. cell1.CellStyle = cellStylebt;
  1148. sheet.AddMergedRegion(new CellRangeAddress(0, 1, 0, 19));
  1149. IRow irow2 = sheet.CreateRow(2);
  1150. ICell cell2 = irow2.CreateCell(0);
  1151. cell2.SetCellValue("统计周期:" + starttime + "至" + endtime + " 统计时间:" + DateTime.Now.ToString("yyyy年MM月dd日"));
  1152. cell2.CellStyle = cellStylebt;
  1153. sheet.AddMergedRegion(new CellRangeAddress(2, 2, 0, 19));
  1154. IRow irow3 = sheet.CreateRow(3);
  1155. ICell cell3 = irow3.CreateCell(0);
  1156. cell3.SetCellValue("一、县(市、区)联动单位");
  1157. cell3.CellStyle = cellStylebt;
  1158. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 0, 19));
  1159. string[] cols = {"序号","联动单位","承办件",
  1160. "承办率","得分(5分)","超期件","按时反馈率","得分(20分)",
  1161. "未果件","办结率","得分(10分)","退单件","有效回复率",
  1162. "得分(15分)","群众评议总数","一次不满意件","不满意件","满意率","得分(50分)","总分","排名"};
  1163. IRow irow4 = sheet.CreateRow(4);
  1164. int icolIndex = 0;
  1165. foreach (string dc in cols)
  1166. {
  1167. ICell cell = irow4.CreateCell(icolIndex);
  1168. cell.SetCellValue(dc);
  1169. cell.CellStyle = cellStylebt;
  1170. icolIndex++;
  1171. }
  1172. int iRowIndex = 5;
  1173. // DataRow[] rows = dt.Select("category=1");
  1174. int index = 0;
  1175. foreach (DataRow dr in dt.Rows )
  1176. {
  1177. index++;
  1178. int iCellIndex = 0;
  1179. IRow irow = sheet.CreateRow(iRowIndex);
  1180. for (int i = 0; i < 21; i++)
  1181. {
  1182. ICell cell = irow.CreateCell(iCellIndex);
  1183. cell.SetCellValue(GetCellValue(dr, index, i));
  1184. cell.CellStyle = cellStyle;
  1185. iCellIndex++;
  1186. }
  1187. iRowIndex++;
  1188. }
  1189. //自适应列宽度
  1190. for (int i = 0; i < 20; i++)
  1191. {
  1192. sheet.AutoSizeColumn(i);
  1193. // sheet.SetColumnWidth(i, 20 * 256);
  1194. }
  1195. using (MemoryStream ms = new MemoryStream())
  1196. {
  1197. workbook.Write(ms);
  1198. HttpContext curContext = HttpContext.Current;
  1199. // 设置编码和附件格式
  1200. curContext.Response.ContentType = "application/vnd.ms-excel";
  1201. curContext.Response.ContentEncoding = Encoding.UTF8;
  1202. curContext.Response.Charset = "";
  1203. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  1204. curContext.Response.AppendHeader("Content-Disposition",
  1205. "attachment;filename=" + HttpUtility.UrlEncode(Name + ".xls", Encoding.UTF8));
  1206. curContext.Response.BinaryWrite(ms.GetBuffer());
  1207. workbook = null;
  1208. ms.Close();
  1209. ms.Dispose();
  1210. curContext.Response.End();
  1211. }
  1212. return "";
  1213. }
  1214. catch
  1215. {
  1216. return "导出失败!";
  1217. }
  1218. }
  1219. //
  1220. /// <summary>
  1221. /// 督办数据报表导出
  1222. /// </summary>
  1223. /// <param name="ds"></param>
  1224. /// <returns></returns>
  1225. public string ExportMergerToExcel(List<MergerHot.MergerHotSource> MergerHotSource)
  1226. {
  1227. try
  1228. {
  1229. int lenth = 0;
  1230. if (MergerHotSource!=null&& MergerHotSource.Count>0)
  1231. {
  1232. if (MergerHotSource[0]!=null && MergerHotSource[0].MergerHot !=null
  1233. && MergerHotSource[0].MergerHot.Count >0)
  1234. {
  1235. lenth = MergerHotSource[0].MergerHot.Count * 5+4;
  1236. }
  1237. else
  1238. {
  1239. return "";
  1240. }
  1241. }
  1242. else
  1243. {
  1244. return "";
  1245. }
  1246. HSSFWorkbook workbook = new HSSFWorkbook();
  1247. ISheet sheet = workbook.CreateSheet("归并热线每日数据统计");
  1248. ICellStyle cellStyle = workbook.CreateCellStyle();
  1249. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  1250. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  1251. cellStyle.SetFont(cellfont);
  1252. ICellStyle cellStylebt = workbook.CreateCellStyle();
  1253. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  1254. cellfontbt.Boldweight = (short)FontBoldWeight.Bold;
  1255. cellStylebt.SetFont(cellfontbt);
  1256. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  1257. cellStylebt.Alignment = HorizontalAlignment.Center;
  1258. cellStylebt.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1259. cellStylebt.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1260. cellStylebt.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1261. cellStylebt.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1262. IRow irow1 = sheet.CreateRow(0);
  1263. ICell cell1 = irow1.CreateCell(0);
  1264. cell1.SetCellValue("归并热线每日数据统计");
  1265. cell1.CellStyle=cellStylebt;
  1266. ICellStyle cellStylebt1 = workbook.CreateCellStyle();
  1267. NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
  1268. cellfontbt1.Boldweight = (short)FontBoldWeight.Bold;
  1269. cellfontbt1.FontHeightInPoints = 22;
  1270. cellStylebt1.SetFont(cellfontbt1);
  1271. cellStylebt1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1272. cellStylebt1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1273. cellStylebt1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1274. cellStylebt1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1275. cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
  1276. cellStylebt1.Alignment = HorizontalAlignment.Center;
  1277. cell1.CellStyle = cellStylebt1;
  1278. sheet.AddMergedRegion(new CellRangeAddress(0, 2, 0, lenth));
  1279. IRow irow2 = sheet.CreateRow(3);
  1280. int icolIndex = 0;
  1281. ICellStyle cellStylebt2 = workbook.CreateCellStyle();
  1282. NPOI.SS.UserModel.IFont cellfontbt2 = workbook.CreateFont();
  1283. cellfontbt2.Boldweight = (short)FontBoldWeight.Bold;
  1284. cellStylebt2.WrapText = true;//设置换行这个要先设置
  1285. cellfontbt2.FontHeightInPoints = 14;
  1286. cellStylebt2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1287. cellStylebt2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1288. cellStylebt2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1289. cellStylebt2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1290. cellStylebt2.SetFont(cellfontbt2);
  1291. cellStylebt2.VerticalAlignment = VerticalAlignment.Center;
  1292. cellStylebt2.Alignment = HorizontalAlignment.Center;
  1293. HSSFPalette palette = workbook.GetCustomPalette(); //调色板实例
  1294. palette.SetColorAtIndex(8, 237,237, 237);
  1295. NPOI.HSSF.Util.HSSFColor hssFColor = palette.FindColor(237, 237, 237);
  1296. cellStylebt2.FillForegroundColor = hssFColor.Indexed ;
  1297. cellStylebt2.FillPattern = FillPattern.SolidForeground;
  1298. cellStylebt2.FillBackgroundColor = hssFColor.Indexed; ;
  1299. ICellStyle cellStylebt3 = workbook.CreateCellStyle();
  1300. NPOI.SS.UserModel.IFont cellfontbt3 = workbook.CreateFont();
  1301. cellfontbt3.Boldweight = (short)FontBoldWeight.Bold;
  1302. cellStylebt3.WrapText = true;//设置换行这个要先设置
  1303. cellfontbt3.FontHeightInPoints = 14;
  1304. cellStylebt3.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1305. cellStylebt3.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1306. cellStylebt3.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1307. cellStylebt3.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1308. cellStylebt3.SetFont(cellfontbt3);
  1309. cellStylebt3.VerticalAlignment = VerticalAlignment.Center;
  1310. cellStylebt3.Alignment = HorizontalAlignment.Center;
  1311. HSSFPalette palette1 = workbook.GetCustomPalette(); //调色板实例
  1312. palette1.SetColorAtIndex(9, 221,235,247);
  1313. NPOI.HSSF.Util.HSSFColor hssFColor1 = palette1.FindColor(221, 235, 247);
  1314. cellStylebt3.FillForegroundColor = hssFColor1.Indexed ;
  1315. cellStylebt3.FillPattern = FillPattern.SolidForeground;
  1316. cellStylebt3.FillBackgroundColor = hssFColor1.Indexed;
  1317. ICellStyle cellStylebt4 = workbook.CreateCellStyle();
  1318. NPOI.SS.UserModel.IFont cellfontbt4 = workbook.CreateFont();
  1319. cellStylebt4.WrapText = true;//设置换行这个要先设置
  1320. cellfontbt4.Boldweight = (short)FontBoldWeight.Bold;
  1321. cellfontbt4.FontHeightInPoints = 11;
  1322. cellStylebt4.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1323. cellStylebt4.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1324. cellStylebt4.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1325. cellStylebt4.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1326. cellStylebt4.SetFont(cellfontbt4);
  1327. cellStylebt4.VerticalAlignment = VerticalAlignment.Center;
  1328. cellStylebt4.Alignment = HorizontalAlignment.Center;
  1329. ICellStyle cellStylebt5 = workbook.CreateCellStyle();
  1330. NPOI.SS.UserModel.IFont cellfontbt5 = workbook.CreateFont();
  1331. cellfontbt5.Boldweight = (short)FontBoldWeight.Bold;
  1332. cellfontbt5.FontHeightInPoints = 11;
  1333. cellStylebt5.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1334. cellStylebt5.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1335. cellStylebt5.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1336. cellStylebt5.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1337. cellStylebt5.WrapText = true;//设置换行这个要先设置
  1338. cellStylebt5.SetFont(cellfontbt5);
  1339. cellStylebt5.VerticalAlignment = VerticalAlignment.Center;
  1340. cellStylebt5.Alignment = HorizontalAlignment.Center;
  1341. HSSFPalette palette2 = workbook.GetCustomPalette(); //调色板实例
  1342. palette2.SetColorAtIndex(10, 226, 239, 218);
  1343. NPOI.HSSF.Util.HSSFColor hssFColor2 = palette2.FindColor(226, 239, 218);
  1344. cellStylebt5.FillForegroundColor = hssFColor2.Indexed ;
  1345. cellStylebt5.FillPattern = FillPattern.SolidForeground;
  1346. cellStylebt5.FillBackgroundColor = hssFColor2.Indexed;
  1347. ICellStyle cellStylebt8 = workbook.CreateCellStyle();
  1348. NPOI.SS.UserModel.IFont cellfontbt8 = workbook.CreateFont();
  1349. cellfontbt8.FontHeightInPoints = 10;
  1350. cellStylebt8.SetFont(cellfontbt8);
  1351. cellStylebt8.WrapText = true;//设置换行这个要先设置
  1352. cellStylebt8.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1353. cellStylebt8.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1354. cellStylebt8.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1355. cellStylebt8.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1356. cellStylebt8.VerticalAlignment = VerticalAlignment.Center;
  1357. cellStylebt8.Alignment = HorizontalAlignment.Center;
  1358. HSSFPalette palette3 = workbook.GetCustomPalette(); //调色板实例
  1359. palette3.SetColorAtIndex(11, 198, 224, 180);
  1360. NPOI.HSSF.Util.HSSFColor hssFColor3 = palette3.FindColor(198, 224, 180);
  1361. cellStylebt8.FillForegroundColor = hssFColor3.Indexed ;
  1362. cellStylebt8.FillPattern = FillPattern.SolidForeground;
  1363. cellStylebt8.FillBackgroundColor = hssFColor3.Indexed;
  1364. ICellStyle cellStylebt9 = workbook.CreateCellStyle();
  1365. NPOI.SS.UserModel.IFont cellfontbt9 = workbook.CreateFont();
  1366. cellfontbt9.FontHeightInPoints = 11;
  1367. cellfontbt9.Boldweight = (short)FontBoldWeight.Bold;
  1368. cellStylebt9.SetFont(cellfontbt9);
  1369. cellStylebt9.WrapText = true;//设置换行这个要先设置
  1370. cellStylebt9.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1371. cellStylebt9.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1372. cellStylebt9.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1373. cellStylebt9.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1374. cellStylebt9.VerticalAlignment = VerticalAlignment.Center;
  1375. cellStylebt9.Alignment = HorizontalAlignment.Center;
  1376. HSSFPalette palette4 = workbook.GetCustomPalette(); //调色板实例
  1377. palette4.SetColorAtIndex(12, 255, 242, 204);
  1378. NPOI.HSSF.Util.HSSFColor hssFColor4 = palette4.FindColor(255, 242, 204);
  1379. cellStylebt9.FillForegroundColor = hssFColor4.Indexed ; ;
  1380. cellStylebt9.FillPattern = FillPattern.SolidForeground;
  1381. cellStylebt9.FillBackgroundColor = hssFColor4.Indexed; ; ;
  1382. ICellStyle cellStylebt10 = workbook.CreateCellStyle();
  1383. NPOI.SS.UserModel.IFont cellfontbt10 = workbook.CreateFont();
  1384. cellfontbt10.Boldweight = (short)FontBoldWeight.Bold;
  1385. cellfontbt10.FontHeightInPoints = 11;
  1386. cellStylebt10.WrapText = true;//设置换行这个要先设置
  1387. cellStylebt10.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1388. cellStylebt10.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1389. cellStylebt10.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1390. cellStylebt10.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1391. cellStylebt10.SetFont(cellfontbt10);
  1392. cellStylebt10.VerticalAlignment = VerticalAlignment.Center;
  1393. cellStylebt10.Alignment = HorizontalAlignment.Center;
  1394. HSSFPalette palette5 = workbook.GetCustomPalette(); //调色板实例
  1395. palette5.SetColorAtIndex(13, 217, 225, 242);
  1396. NPOI.HSSF.Util.HSSFColor hssFColor5 = palette5.FindColor(217, 225, 242);
  1397. cellStylebt10.FillForegroundColor = hssFColor5.Indexed ;
  1398. cellStylebt10.FillPattern = FillPattern.SolidForeground;
  1399. cellStylebt10.FillBackgroundColor = hssFColor5.Indexed; ;
  1400. ICellStyle cellStylebt6 = workbook.CreateCellStyle();
  1401. NPOI.SS.UserModel.IFont cellfontbt6 = workbook.CreateFont();
  1402. cellfontbt6.Boldweight = (short)FontBoldWeight.Bold;
  1403. cellStylebt6.WrapText = true;//设置换行这个要先设置
  1404. cellfontbt6.FontHeightInPoints = 10;
  1405. cellStylebt6.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1406. cellStylebt6.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1407. cellStylebt6.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1408. cellStylebt6.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1409. cellStylebt6.SetFont(cellfontbt6);
  1410. cellStylebt6.VerticalAlignment = VerticalAlignment.Center;
  1411. cellStylebt6.Alignment = HorizontalAlignment.Center;
  1412. cellStylebt6.FillForegroundColor = hssFColor.Indexed ;
  1413. cellStylebt6.FillPattern = FillPattern.SolidForeground;
  1414. cellStylebt6.FillBackgroundColor = hssFColor.Indexed; ;
  1415. ICellStyle cellStylebt11 = workbook.CreateCellStyle();
  1416. NPOI.SS.UserModel.IFont cellfontbt11 = workbook.CreateFont();
  1417. cellfontbt11.FontHeightInPoints = 10;
  1418. cellStylebt11.WrapText = true;//设置换行这个要先设置
  1419. cellStylebt11.SetFont(cellfontbt11);
  1420. cellStylebt11.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1421. cellStylebt11.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1422. cellStylebt11.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1423. cellStylebt11.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1424. cellStylebt11.VerticalAlignment = VerticalAlignment.Center;
  1425. cellStylebt11.Alignment = HorizontalAlignment.Center;
  1426. ICellStyle cellStylebt12 = workbook.CreateCellStyle();
  1427. NPOI.SS.UserModel.IFont cellfontbt12 = workbook.CreateFont();
  1428. cellfontbt12.Boldweight = (short)FontBoldWeight.Bold;
  1429. cellfontbt12.FontHeightInPoints = 10;
  1430. cellStylebt12.WrapText = true;//设置换行这个要先设置
  1431. cellStylebt12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1432. cellStylebt12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1433. cellStylebt12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1434. cellStylebt12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1435. cellStylebt12.SetFont(cellfontbt12);
  1436. cellStylebt12.VerticalAlignment = VerticalAlignment.Center;
  1437. cellStylebt12.Alignment = HorizontalAlignment.Center;
  1438. cellStylebt12.FillForegroundColor = hssFColor5.Indexed;
  1439. cellStylebt12.FillPattern = FillPattern.SolidForeground;
  1440. cellStylebt12.FillBackgroundColor = hssFColor5.Indexed; ;
  1441. ICellStyle cellStylebt13 = workbook.CreateCellStyle();
  1442. NPOI.SS.UserModel.IFont cellfontbt13 = workbook.CreateFont();
  1443. cellfontbt13.Boldweight = (short)FontBoldWeight.Bold;
  1444. cellStylebt13.WrapText = true;//设置换行这个要先设置
  1445. cellfontbt13.FontHeightInPoints = 11;
  1446. cellStylebt13.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1447. cellStylebt13.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1448. cellStylebt13.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1449. cellStylebt13.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1450. cellStylebt13.SetFont(cellfontbt13);
  1451. cellStylebt13.VerticalAlignment = VerticalAlignment.Center;
  1452. cellStylebt13.Alignment = HorizontalAlignment.Center;
  1453. cellStylebt13.FillForegroundColor = hssFColor.Indexed;
  1454. cellStylebt13.FillPattern = FillPattern.SolidForeground;
  1455. cellStylebt13.FillBackgroundColor = hssFColor.Indexed; ;
  1456. ICellStyle cellStylebt14 = workbook.CreateCellStyle();
  1457. NPOI.SS.UserModel.IFont cellfontbt14 = workbook.CreateFont();
  1458. cellfontbt14.FontHeightInPoints = 10;
  1459. cellStylebt14.SetFont(cellfontbt14);
  1460. cellStylebt14.WrapText = true;//设置换行这个要先设置
  1461. cellStylebt14.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1462. cellStylebt14.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1463. cellStylebt14.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1464. cellStylebt14.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1465. cellStylebt14.VerticalAlignment = VerticalAlignment.Center;
  1466. cellStylebt14.Alignment = HorizontalAlignment.Center;
  1467. cellStylebt14.FillForegroundColor = hssFColor4.Indexed; ;
  1468. cellStylebt14.FillPattern = FillPattern.SolidForeground;
  1469. cellStylebt14.FillBackgroundColor = hssFColor4.Indexed; ; ;
  1470. ICellStyle cellStylebt15 = workbook.CreateCellStyle();
  1471. NPOI.SS.UserModel.IFont cellfontbt15 = workbook.CreateFont();
  1472. cellfontbt15.Boldweight = (short)FontBoldWeight.Bold;
  1473. cellfontbt15.FontHeightInPoints = 10;
  1474. cellStylebt15.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1475. cellStylebt15.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1476. cellStylebt15.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1477. cellStylebt15.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1478. cellStylebt15.WrapText = true;//设置换行这个要先设置
  1479. cellStylebt15.SetFont(cellfontbt15);
  1480. cellStylebt15.VerticalAlignment = VerticalAlignment.Center;
  1481. cellStylebt15.Alignment = HorizontalAlignment.Center;
  1482. cellStylebt15.FillForegroundColor = hssFColor2.Indexed;
  1483. cellStylebt15.FillPattern = FillPattern.SolidForeground;
  1484. cellStylebt15.FillBackgroundColor = hssFColor2.Indexed;
  1485. int indexsource = -1;
  1486. for (int i = 0; i <= MergerHotSource[0].MergerHot.Count
  1487. ;i++)
  1488. {
  1489. if (i == 0)
  1490. {
  1491. ICell cell = irow2.CreateCell(0);
  1492. cell.SetCellValue("来源");
  1493. cell.CellStyle = cellStylebt2;
  1494. indexsource = 0;
  1495. sheet.SetColumnWidth(0, 12 * 300);
  1496. }
  1497. else if (i >0&&i <= MergerHotSource[0].MergerHot.Count-4)
  1498. {
  1499. ICell cell = irow2.CreateCell(indexsource+1);
  1500. cell.SetCellValue(MergerHotSource[0].MergerHot[i - 1].Source);
  1501. cell.CellStyle = cellStylebt2;
  1502. if (i ==1 )
  1503. {
  1504. indexsource = 6;
  1505. for (int z = 2; z <= indexsource - 1; z++)
  1506. {
  1507. ICell cell4 = irow2.CreateCell(z);
  1508. cell4.CellStyle = cellStylebt2;
  1509. }
  1510. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 1, indexsource - 1));
  1511. }
  1512. else
  1513. {
  1514. for (int z = indexsource + 2; z <= indexsource + 5; z++)
  1515. {
  1516. ICell cell4 = irow2.CreateCell(z);
  1517. cell4.CellStyle = cellStylebt2;
  1518. }
  1519. sheet.AddMergedRegion(new CellRangeAddress(3, 3, indexsource + 1, indexsource + 5));
  1520. indexsource += 6;
  1521. }
  1522. }
  1523. else
  1524. {
  1525. ICell cell = irow2.CreateCell(indexsource + 1);
  1526. cell.SetCellValue(MergerHotSource[0].MergerHot[i - 1].Source);
  1527. if (i == MergerHotSource[0].MergerHot.Count - 3)
  1528. {
  1529. for (int z = indexsource + 2; z <= indexsource + 6; z++)
  1530. {
  1531. ICell cell4 = irow2.CreateCell(z);
  1532. cell4.CellStyle = cellStylebt2;
  1533. }
  1534. sheet.AddMergedRegion(new CellRangeAddress(3, 3, indexsource + 1, indexsource + 6));
  1535. cell.CellStyle = cellStylebt3;
  1536. indexsource += 7;
  1537. }
  1538. else
  1539. {
  1540. for (int z = indexsource + 2; z <= indexsource + 5; z++)
  1541. {
  1542. ICell cell4 = irow2.CreateCell(z);
  1543. cell4.CellStyle = cellStylebt2;
  1544. }
  1545. sheet.AddMergedRegion(new CellRangeAddress(3, 3, indexsource + 1, indexsource + 5));
  1546. cell.CellStyle = cellStylebt3;
  1547. indexsource += 6;
  1548. }
  1549. }
  1550. }
  1551. IRow irow3 = sheet.CreateRow(4);
  1552. indexsource = 0;
  1553. sheet.CreateRow(4).Height = 200 * 8;
  1554. for (int i = 0; i <= MergerHotSource[0].MergerHot.Count; i++)
  1555. {
  1556. if (i == 0)
  1557. {
  1558. ICell cell = irow3.CreateCell(0);
  1559. cell.SetCellValue("日期");
  1560. cell.CellStyle = cellStylebt4;
  1561. }
  1562. else if (i > 0 && i <= MergerHotSource[0].MergerHot.Count - 4)
  1563. {
  1564. for (int j = 0; j < 5; j++)
  1565. {
  1566. indexsource += 1;
  1567. ICell cell = irow3.CreateCell(indexsource);
  1568. switch (j)
  1569. {
  1570. case 0:
  1571. cell.SetCellValue("来\n电\n量\n");
  1572. cell.CellStyle = cellStylebt5;
  1573. sheet.AutoSizeColumn(indexsource);
  1574. //sheet.SetColumnWidth(indexsource, 12 * 150);
  1575. break;
  1576. case 1:
  1577. cell.SetCellValue("接\n通\n量\n");
  1578. cell.CellStyle = cellStylebt9;
  1579. sheet.AutoSizeColumn(indexsource);
  1580. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1581. break;
  1582. case 2:
  1583. cell.SetCellValue("未\n接\n通\n");
  1584. cell.CellStyle = cellStylebt4;
  1585. sheet.AutoSizeColumn(indexsource);
  1586. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1587. break;
  1588. case 3:
  1589. cell.SetCellValue("主\n动\n放\n弃\n");
  1590. cell.CellStyle = cellStylebt4;
  1591. sheet.AutoSizeColumn(indexsource);
  1592. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1593. break;
  1594. case 4:
  1595. cell.SetCellValue("接\n通\n率");
  1596. cell.CellStyle = cellStylebt4;
  1597. sheet.AutoSizeColumn(indexsource);
  1598. break;
  1599. }
  1600. }
  1601. indexsource += 1;
  1602. sheet.SetColumnWidth(indexsource, 12 * 35);
  1603. }
  1604. else
  1605. {
  1606. if (MergerHotSource[0].MergerHot[i - 1].Source == "12345")
  1607. {
  1608. for (int j = 0; j < 5; j++)
  1609. {
  1610. indexsource += 1;
  1611. ICell cell = irow3.CreateCell(indexsource);
  1612. switch (j)
  1613. {
  1614. case 0:
  1615. cell.SetCellValue("来\n电\n量\n");
  1616. cell.CellStyle = cellStylebt5;
  1617. sheet.AutoSizeColumn(indexsource);
  1618. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1619. break;
  1620. case 1:
  1621. cell.SetCellValue("接\n通\n量\n");
  1622. cell.CellStyle = cellStylebt9;
  1623. sheet.AutoSizeColumn(indexsource);
  1624. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1625. break;
  1626. case 2:
  1627. cell.SetCellValue("接\n通\n率\n");
  1628. cell.CellStyle = cellStylebt2;
  1629. sheet.AutoSizeColumn(indexsource);
  1630. // sheet.SetColumnWidth(7, 12 * 150);
  1631. break;
  1632. case 3:
  1633. cell.SetCellValue("未\n接\n通\n");
  1634. cell.CellStyle = cellStylebt4;
  1635. sheet.AutoSizeColumn(indexsource);
  1636. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1637. break;
  1638. case 4:
  1639. cell.SetCellValue("主\n动\n放\n弃\n");
  1640. cell.CellStyle = cellStylebt4;
  1641. sheet.AutoSizeColumn(indexsource);
  1642. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1643. break;
  1644. }
  1645. }
  1646. indexsource += 1;
  1647. sheet.SetColumnWidth(indexsource, 12 * 35);
  1648. }
  1649. else if (MergerHotSource[0].MergerHot[i - 1].Source == "归并热线小计")
  1650. {
  1651. for (int j = 0; j < 6; j++)
  1652. {
  1653. indexsource += 1;
  1654. ICell cell = irow3.CreateCell(indexsource);
  1655. switch (j)
  1656. {
  1657. case 0:
  1658. cell.SetCellValue("来\n电\n量\n");
  1659. cell.CellStyle = cellStylebt5;
  1660. sheet.AutoSizeColumn(indexsource);
  1661. //sheet.SetColumnWidth(indexsource, 12 * 150);
  1662. break;
  1663. case 1:
  1664. cell.SetCellValue("接\n通\n量\n");
  1665. cell.CellStyle = cellStylebt9;
  1666. sheet.AutoSizeColumn(indexsource);
  1667. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1668. break;
  1669. case 2:
  1670. cell.SetCellValue("未\n接\n通\n");
  1671. cell.CellStyle = cellStylebt4;
  1672. sheet.AutoSizeColumn(indexsource);
  1673. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1674. break;
  1675. case 3:
  1676. cell.SetCellValue("主\n动\n放\n弃\n");
  1677. cell.CellStyle = cellStylebt4;
  1678. sheet.AutoSizeColumn(indexsource);
  1679. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1680. break;
  1681. case 4:
  1682. cell.SetCellValue("接\n通\n率\n");
  1683. cell.CellStyle = cellStylebt10;
  1684. sheet.AutoSizeColumn(indexsource);
  1685. // sheet.SetColumnWidth(indexsource, 12 * 200);
  1686. break;
  1687. case 5:
  1688. cell.SetCellValue("回\n拨\n量\n");
  1689. cell.CellStyle = cellStylebt4;
  1690. sheet.AutoSizeColumn(indexsource);
  1691. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1692. break;
  1693. }
  1694. }
  1695. indexsource += 1;
  1696. sheet.SetColumnWidth(indexsource, 12 * 35);
  1697. }
  1698. else
  1699. {
  1700. for (int j = 0; j < 5; j++)
  1701. {
  1702. indexsource += 1;
  1703. ICell cell = irow3.CreateCell(indexsource);
  1704. switch (j)
  1705. {
  1706. case 0:
  1707. cell.SetCellValue("来\n电\n量\n");
  1708. cell.CellStyle = cellStylebt5;
  1709. sheet.AutoSizeColumn(indexsource);
  1710. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1711. break;
  1712. case 1:
  1713. cell.SetCellValue("接\n通\n量\n");
  1714. cell.CellStyle = cellStylebt9;
  1715. sheet.AutoSizeColumn(indexsource);
  1716. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1717. break;
  1718. case 2:
  1719. cell.SetCellValue("未\n接\n通\n");
  1720. cell.CellStyle = cellStylebt4;
  1721. sheet.AutoSizeColumn(indexsource);
  1722. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1723. break;
  1724. case 3:
  1725. cell.SetCellValue("主\n动\n放\n弃\n");
  1726. cell.CellStyle = cellStylebt4;
  1727. sheet.AutoSizeColumn(indexsource);
  1728. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1729. break;
  1730. case 4:
  1731. cell.SetCellValue("接\n通\n率\n");
  1732. cell.CellStyle = cellStylebt10;
  1733. sheet.AutoSizeColumn(indexsource);
  1734. // sheet.SetColumnWidth(indexsource, 12 * 200);
  1735. break;
  1736. }
  1737. }
  1738. indexsource += 1;
  1739. sheet.SetColumnWidth(indexsource, 12 * 35);
  1740. }
  1741. }
  1742. }
  1743. for (int i=0;i< MergerHotSource.Count; i++)
  1744. {
  1745. IRow irow4 = sheet.CreateRow(5+i );
  1746. for (int j = 0; j <= MergerHotSource[i].MergerHot.Count; j++)
  1747. {
  1748. if (j == 0)
  1749. {
  1750. ICell cell = irow4.CreateCell(0);
  1751. cell.SetCellValue(MergerHotSource[i].Data);
  1752. cell.CellStyle = cellStylebt11;
  1753. indexsource = 0;
  1754. }
  1755. else
  1756. {
  1757. if (i == MergerHotSource.Count-1)
  1758. {
  1759. if (j == 1)
  1760. {
  1761. for (int z = 0; z < 5; z++)
  1762. {
  1763. indexsource += 1;
  1764. ICell cell = irow4.CreateCell(indexsource);
  1765. switch (z)
  1766. {
  1767. case 0:
  1768. cell.SetCellValue(MergerHotSource[i]
  1769. .MergerHot[j - 1].Call);
  1770. cell.CellStyle = cellStylebt8;
  1771. break;
  1772. case 1:
  1773. cell.SetCellValue(MergerHotSource[i]
  1774. .MergerHot[j - 1].Connect);
  1775. cell.CellStyle = cellStylebt8;
  1776. break;
  1777. case 2:
  1778. cell.SetCellValue(MergerHotSource[i]
  1779. .MergerHot[j - 1].Notconnected);
  1780. cell.CellStyle = cellStylebt8;
  1781. break;
  1782. case 3:
  1783. cell.SetCellValue(MergerHotSource[i]
  1784. .MergerHot[j - 1].voluntarily);
  1785. cell.CellStyle = cellStylebt8;
  1786. break;
  1787. case 4:
  1788. cell.SetCellValue(MergerHotSource[i]
  1789. .MergerHot[j - 1].rate );
  1790. cell.CellStyle = cellStylebt8;
  1791. break;
  1792. }
  1793. }
  1794. indexsource += 1;
  1795. }
  1796. else
  1797. {
  1798. if (MergerHotSource[i].MergerHot[j - 1].Source == "12345")
  1799. {
  1800. for (int z = 0; z < 5; z++)
  1801. {
  1802. indexsource += 1;
  1803. ICell cell = irow4.CreateCell(indexsource);
  1804. switch (z)
  1805. {
  1806. case 0:
  1807. cell.SetCellValue(MergerHotSource[i]
  1808. .MergerHot[j - 1].Call);
  1809. cell.CellStyle = cellStylebt8;
  1810. break;
  1811. case 1:
  1812. cell.SetCellValue(MergerHotSource[i]
  1813. .MergerHot[j - 1].Connect);
  1814. cell.CellStyle = cellStylebt8;
  1815. break;
  1816. case 2:
  1817. cell.SetCellValue(MergerHotSource[i]
  1818. .MergerHot[j - 1].rate);
  1819. cell.CellStyle = cellStylebt8;
  1820. break;
  1821. case 3:
  1822. cell.SetCellValue(MergerHotSource[i]
  1823. .MergerHot[j - 1].Notconnected);
  1824. cell.CellStyle = cellStylebt8;
  1825. break;
  1826. case 4:
  1827. cell.SetCellValue(MergerHotSource[i]
  1828. .MergerHot[j - 1].voluntarily);
  1829. cell.CellStyle = cellStylebt8;
  1830. break;
  1831. }
  1832. }
  1833. indexsource += 1;
  1834. }
  1835. else if (MergerHotSource[i].MergerHot[j - 1].Source == "当日小计"
  1836. || MergerHotSource[i].MergerHot[j - 1].Source == "累计")
  1837. {
  1838. for (int z = 0; z < 5; z++)
  1839. {
  1840. indexsource += 1;
  1841. ICell cell = irow4.CreateCell(indexsource);
  1842. switch (z)
  1843. {
  1844. case 0:
  1845. cell.SetCellValue(MergerHotSource[i]
  1846. .MergerHot[j - 1].Call);
  1847. cell.CellStyle = cellStylebt8;
  1848. break;
  1849. case 1:
  1850. cell.SetCellValue(MergerHotSource[i]
  1851. .MergerHot[j - 1].Connect);
  1852. cell.CellStyle = cellStylebt8;
  1853. break;
  1854. case 2:
  1855. cell.SetCellValue(MergerHotSource[i]
  1856. .MergerHot[j - 1].Notconnected);
  1857. cell.CellStyle = cellStylebt8;
  1858. break;
  1859. case 3:
  1860. cell.SetCellValue(MergerHotSource[i]
  1861. .MergerHot[j - 1].voluntarily);
  1862. cell.CellStyle = cellStylebt8;
  1863. break;
  1864. case 4:
  1865. cell.SetCellValue(MergerHotSource[i]
  1866. .MergerHot[j - 1].rate);
  1867. cell.CellStyle = cellStylebt8;
  1868. break;
  1869. }
  1870. }
  1871. indexsource += 1;
  1872. }
  1873. else if (MergerHotSource[i].MergerHot[j - 1].Source == "归并热线小计"
  1874. )
  1875. {
  1876. for (int z = 0; z < 6; z++)
  1877. {
  1878. indexsource += 1;
  1879. ICell cell = irow4.CreateCell(indexsource);
  1880. switch (z)
  1881. {
  1882. case 0:
  1883. cell.SetCellValue(MergerHotSource[i]
  1884. .MergerHot[j - 1].Call);
  1885. cell.CellStyle = cellStylebt8;
  1886. break;
  1887. case 1:
  1888. cell.SetCellValue(MergerHotSource[i]
  1889. .MergerHot[j - 1].Connect);
  1890. cell.CellStyle = cellStylebt8;
  1891. break;
  1892. case 2:
  1893. cell.SetCellValue(MergerHotSource[i]
  1894. .MergerHot[j - 1].Notconnected);
  1895. cell.CellStyle = cellStylebt8;
  1896. break;
  1897. case 3:
  1898. cell.SetCellValue(MergerHotSource[i]
  1899. .MergerHot[j - 1].voluntarily);
  1900. cell.CellStyle = cellStylebt8;
  1901. break;
  1902. case 4:
  1903. cell.SetCellValue(MergerHotSource[i]
  1904. .MergerHot[j - 1].rate);
  1905. cell.CellStyle = cellStylebt8;
  1906. break;
  1907. case 5:
  1908. cell.SetCellValue(MergerHotSource[i]
  1909. .MergerHot[j - 1].callback );
  1910. cell.CellStyle = cellStylebt8;
  1911. break;
  1912. }
  1913. }
  1914. indexsource += 1;
  1915. }
  1916. else
  1917. {
  1918. for (int z = 0; z < 5; z++)
  1919. {
  1920. indexsource += 1;
  1921. ICell cell = irow4.CreateCell(indexsource);
  1922. switch (z)
  1923. {
  1924. case 0:
  1925. cell.SetCellValue(MergerHotSource[i]
  1926. .MergerHot[j - 1].Call);
  1927. cell.CellStyle = cellStylebt8;
  1928. break;
  1929. case 1:
  1930. cell.SetCellValue(MergerHotSource[i]
  1931. .MergerHot[j - 1].Connect);
  1932. cell.CellStyle = cellStylebt8;
  1933. break;
  1934. case 2:
  1935. cell.SetCellValue(MergerHotSource[i]
  1936. .MergerHot[j - 1].Notconnected);
  1937. cell.CellStyle = cellStylebt8;
  1938. break;
  1939. case 3:
  1940. cell.SetCellValue(MergerHotSource[i]
  1941. .MergerHot[j - 1].voluntarily);
  1942. cell.CellStyle = cellStylebt8;
  1943. break;
  1944. case 4:
  1945. cell.SetCellValue(MergerHotSource[i]
  1946. .MergerHot[j - 1].rate );
  1947. cell.CellStyle = cellStylebt8;
  1948. break;
  1949. }
  1950. }
  1951. indexsource += 1;
  1952. }
  1953. }
  1954. }
  1955. else
  1956. {
  1957. if (j == 1)
  1958. {
  1959. for (int z = 0; z < 5; z++)
  1960. {
  1961. indexsource += 1;
  1962. ICell cell = irow4.CreateCell(indexsource);
  1963. switch (z)
  1964. {
  1965. case 0:
  1966. cell.SetCellValue(MergerHotSource[i]
  1967. .MergerHot[j - 1].Call);
  1968. cell.CellStyle = cellStylebt15;
  1969. break;
  1970. case 1:
  1971. cell.SetCellValue(MergerHotSource[i]
  1972. .MergerHot[j - 1].Connect);
  1973. cell.CellStyle = cellStylebt14;
  1974. break;
  1975. case 2:
  1976. cell.SetCellValue(MergerHotSource[i]
  1977. .MergerHot[j - 1].Notconnected);
  1978. cell.CellStyle = cellStylebt11;
  1979. break;
  1980. case 3:
  1981. cell.SetCellValue(MergerHotSource[i]
  1982. .MergerHot[j - 1].voluntarily);
  1983. cell.CellStyle = cellStylebt11;
  1984. break;
  1985. case 4:
  1986. cell.SetCellValue(MergerHotSource[i]
  1987. .MergerHot[j - 1].rate );
  1988. cell.CellStyle = cellStylebt11;
  1989. break;
  1990. }
  1991. }
  1992. indexsource += 1;
  1993. }
  1994. else
  1995. {
  1996. if (MergerHotSource[i].MergerHot[j - 1].Source == "12345")
  1997. {
  1998. for (int z = 0; z < 5; z++)
  1999. {
  2000. indexsource += 1;
  2001. ICell cell = irow4.CreateCell(indexsource);
  2002. switch (z)
  2003. {
  2004. case 0:
  2005. cell.SetCellValue(MergerHotSource[i]
  2006. .MergerHot[j - 1].Call);
  2007. cell.CellStyle = cellStylebt15;
  2008. break;
  2009. case 1:
  2010. cell.SetCellValue(MergerHotSource[i]
  2011. .MergerHot[j - 1].Connect);
  2012. cell.CellStyle = cellStylebt14;
  2013. break;
  2014. case 2:
  2015. cell.SetCellValue(MergerHotSource[i]
  2016. .MergerHot[j - 1].rate);
  2017. cell.CellStyle = cellStylebt6;
  2018. break;
  2019. case 3:
  2020. cell.SetCellValue(MergerHotSource[i]
  2021. .MergerHot[j - 1].Notconnected);
  2022. cell.CellStyle = cellStylebt11;
  2023. break;
  2024. case 4:
  2025. cell.SetCellValue(MergerHotSource[i]
  2026. .MergerHot[j - 1].voluntarily);
  2027. cell.CellStyle = cellStylebt11;
  2028. break;
  2029. }
  2030. }
  2031. indexsource += 1;
  2032. }
  2033. else if (MergerHotSource[i].MergerHot[j - 1].Source == "当日小计"
  2034. || MergerHotSource[i].MergerHot[j - 1].Source == "累计")
  2035. {
  2036. for (int z = 0; z < 5; z++)
  2037. {
  2038. indexsource += 1;
  2039. ICell cell = irow4.CreateCell(indexsource);
  2040. switch (z)
  2041. {
  2042. case 0:
  2043. cell.SetCellValue(MergerHotSource[i]
  2044. .MergerHot[j - 1].Call);
  2045. cell.CellStyle = cellStylebt15;
  2046. break;
  2047. case 1:
  2048. cell.SetCellValue(MergerHotSource[i]
  2049. .MergerHot[j - 1].Connect);
  2050. cell.CellStyle = cellStylebt14;
  2051. break;
  2052. case 2:
  2053. cell.SetCellValue(MergerHotSource[i]
  2054. .MergerHot[j - 1].Notconnected);
  2055. cell.CellStyle = cellStylebt11;
  2056. break;
  2057. case 3:
  2058. cell.SetCellValue(MergerHotSource[i]
  2059. .MergerHot[j - 1].voluntarily);
  2060. cell.CellStyle = cellStylebt11;
  2061. break;
  2062. case 4:
  2063. cell.SetCellValue(MergerHotSource[i]
  2064. .MergerHot[j - 1].rate);
  2065. cell.CellStyle = cellStylebt12;
  2066. break;
  2067. }
  2068. }
  2069. indexsource += 1;
  2070. }
  2071. else if (MergerHotSource[i].MergerHot[j - 1].Source == "归并热线小计")
  2072. {
  2073. for (int z = 0; z < 6; z++)
  2074. {
  2075. indexsource += 1;
  2076. ICell cell = irow4.CreateCell(indexsource);
  2077. switch (z)
  2078. {
  2079. case 0:
  2080. cell.SetCellValue(MergerHotSource[i]
  2081. .MergerHot[j - 1].Call);
  2082. cell.CellStyle = cellStylebt15;
  2083. break;
  2084. case 1:
  2085. cell.SetCellValue(MergerHotSource[i]
  2086. .MergerHot[j - 1].Connect);
  2087. cell.CellStyle = cellStylebt14;
  2088. break;
  2089. case 2:
  2090. cell.SetCellValue(MergerHotSource[i]
  2091. .MergerHot[j - 1].Notconnected);
  2092. cell.CellStyle = cellStylebt11;
  2093. break;
  2094. case 3:
  2095. cell.SetCellValue(MergerHotSource[i]
  2096. .MergerHot[j - 1].voluntarily);
  2097. cell.CellStyle = cellStylebt11;
  2098. break;
  2099. case 4:
  2100. cell.SetCellValue(MergerHotSource[i]
  2101. .MergerHot[j - 1].rate);
  2102. cell.CellStyle = cellStylebt12;
  2103. break;
  2104. case 5:
  2105. cell.SetCellValue(MergerHotSource[i]
  2106. .MergerHot[j - 1].callback );
  2107. cell.CellStyle = cellStylebt11;
  2108. break;
  2109. }
  2110. }
  2111. indexsource += 1;
  2112. }
  2113. else
  2114. {
  2115. for (int z = 0; z < 5; z++)
  2116. {
  2117. indexsource += 1;
  2118. ICell cell = irow4.CreateCell(indexsource);
  2119. switch (z)
  2120. {
  2121. case 0:
  2122. cell.SetCellValue(MergerHotSource[i]
  2123. .MergerHot[j - 1].Call);
  2124. cell.CellStyle = cellStylebt15;
  2125. break;
  2126. case 1:
  2127. cell.SetCellValue(MergerHotSource[i]
  2128. .MergerHot[j - 1].Connect);
  2129. cell.CellStyle = cellStylebt14;
  2130. break;
  2131. case 2:
  2132. cell.SetCellValue(MergerHotSource[i]
  2133. .MergerHot[j - 1].Notconnected);
  2134. cell.CellStyle = cellStylebt11;
  2135. break;
  2136. case 3:
  2137. cell.SetCellValue(MergerHotSource[i]
  2138. .MergerHot[j - 1].voluntarily);
  2139. cell.CellStyle = cellStylebt11;
  2140. break;
  2141. case 4:
  2142. cell.SetCellValue(MergerHotSource[i]
  2143. .MergerHot[j - 1].rate );
  2144. cell.CellStyle = cellStylebt11;
  2145. break;
  2146. }
  2147. }
  2148. indexsource += 1;
  2149. }
  2150. }
  2151. }
  2152. }
  2153. }
  2154. }
  2155. //自适应列宽度
  2156. //for (int i = 0; i < 20; i++)
  2157. //{
  2158. // sheet.AutoSizeColumn(i);
  2159. // // sheet.SetColumnWidth(i, 20 * 256);
  2160. //}
  2161. using (MemoryStream ms = new MemoryStream())
  2162. {
  2163. workbook.Write(ms);
  2164. HttpContext curContext = HttpContext.Current;
  2165. // 设置编码和附件格式
  2166. curContext.Response.ContentType = "application/vnd.ms-excel";
  2167. curContext.Response.ContentEncoding = Encoding.UTF8;
  2168. curContext.Response.Charset = "";
  2169. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  2170. curContext.Response.AppendHeader("Content-Disposition",
  2171. "attachment;filename=" + HttpUtility.UrlEncode("归并数据统计" + ".xls", Encoding.UTF8));
  2172. curContext.Response.BinaryWrite(ms.GetBuffer());
  2173. workbook = null;
  2174. ms.Close();
  2175. ms.Dispose();
  2176. curContext.Response.End();
  2177. }
  2178. return "";
  2179. }
  2180. catch
  2181. {
  2182. return "导出失败!";
  2183. }
  2184. }
  2185. /// <summary>
  2186. /// 督办数据报表导出
  2187. /// </summary>
  2188. /// <param name="ds"></param>
  2189. /// <returns></returns>
  2190. public string CenterReception(DataSet dt)
  2191. {
  2192. try
  2193. {
  2194. int lenth = 0;
  2195. HSSFWorkbook workbook = new HSSFWorkbook();
  2196. ISheet sheet = workbook.CreateSheet("电话中心受话情况统计表");
  2197. ICellStyle cellStyle = workbook.CreateCellStyle();
  2198. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  2199. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  2200. cellStyle.SetFont(cellfont);
  2201. ICellStyle cellStylebt = workbook.CreateCellStyle();
  2202. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  2203. cellfontbt.Boldweight = (short)FontBoldWeight.Bold;
  2204. cellStylebt.SetFont(cellfontbt);
  2205. cellStylebt.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black .Index ;
  2206. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  2207. cellStylebt.Alignment = HorizontalAlignment.Center;
  2208. cellStylebt.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2209. cellStylebt.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2210. cellStylebt.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2211. cellStylebt.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2212. ICellStyle cellStylebt1 = workbook.CreateCellStyle();
  2213. NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
  2214. cellfontbt1.Boldweight = (short)FontBoldWeight.Bold;
  2215. cellfontbt1.FontHeightInPoints = 22;
  2216. cellStylebt1.SetFont(cellfontbt1);
  2217. cellStylebt1.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2218. cellStylebt1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2219. cellStylebt1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2220. cellStylebt1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2221. cellStylebt1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2222. cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
  2223. cellStylebt1.Alignment = HorizontalAlignment.Center;
  2224. ICellStyle cellStylebt2 = workbook.CreateCellStyle();
  2225. NPOI.SS.UserModel.IFont cellfontbt2 = workbook.CreateFont();
  2226. cellfontbt2.Boldweight = (short)FontBoldWeight.Bold;
  2227. cellStylebt2.WrapText = true;//设置换行这个要先设置
  2228. cellfontbt2.FontHeightInPoints = 14;
  2229. cellStylebt2.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2230. cellStylebt2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2231. cellStylebt2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2232. cellStylebt2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2233. cellStylebt2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2234. cellStylebt2.SetFont(cellfontbt2);
  2235. cellStylebt2.VerticalAlignment = VerticalAlignment.Center;
  2236. cellStylebt2.Alignment = HorizontalAlignment.Center;
  2237. HSSFPalette palette = workbook.GetCustomPalette(); //调色板实例
  2238. palette.SetColorAtIndex(8, 218, 232, 244);
  2239. NPOI.HSSF.Util.HSSFColor hssFColor = palette.FindColor(218, 232, 244);
  2240. cellStylebt2.FillForegroundColor = hssFColor.Indexed;
  2241. cellStylebt2.FillPattern = FillPattern.SolidForeground;
  2242. cellStylebt2.FillBackgroundColor = hssFColor.Indexed; ;
  2243. ICellStyle cellStylebt3 = workbook.CreateCellStyle();
  2244. NPOI.SS.UserModel.IFont cellfontbt3 = workbook.CreateFont();
  2245. cellfontbt3.Boldweight = (short)FontBoldWeight.Bold;
  2246. cellStylebt3.WrapText = true;//设置换行这个要先设置
  2247. cellfontbt3.FontHeightInPoints = 11;
  2248. cellStylebt3.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2249. cellStylebt3.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2250. cellStylebt3.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2251. cellStylebt3.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2252. cellStylebt3.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2253. cellStylebt3.SetFont(cellfontbt3);
  2254. cellStylebt3.VerticalAlignment = VerticalAlignment.Center;
  2255. cellStylebt3.Alignment = HorizontalAlignment.Center;
  2256. ICellStyle cellStylebt4 = workbook.CreateCellStyle();
  2257. NPOI.SS.UserModel.IFont cellfontbt4 = workbook.CreateFont();
  2258. cellfontbt4.Boldweight = (short)FontBoldWeight.Bold;
  2259. cellStylebt4.WrapText = true;//设置换行这个要先设置
  2260. cellfontbt4.FontHeightInPoints = 11;
  2261. cellStylebt4.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2262. cellStylebt4.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2263. cellStylebt4.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2264. cellStylebt4.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2265. cellStylebt4.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2266. cellStylebt4.SetFont(cellfontbt4);
  2267. cellStylebt4.VerticalAlignment = VerticalAlignment.Center;
  2268. cellStylebt4.Alignment = HorizontalAlignment.Center;
  2269. HSSFPalette palette1 = workbook.GetCustomPalette(); //调色板实例
  2270. palette1.SetColorAtIndex(9, 166, 197, 191);
  2271. NPOI.HSSF.Util.HSSFColor hssFColor1 = palette1.FindColor(166, 197, 191);
  2272. cellStylebt4.FillForegroundColor = hssFColor1.Indexed;
  2273. cellStylebt4.FillPattern = FillPattern.SolidForeground;
  2274. cellStylebt4.FillBackgroundColor = hssFColor1.Indexed; ;
  2275. ICellStyle cellStylebt5 = workbook.CreateCellStyle();
  2276. cellStylebt5.WrapText = true;//设置换行这个要先设置
  2277. cellStylebt5.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2278. cellStylebt5.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2279. cellStylebt5.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2280. cellStylebt5.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2281. cellStylebt5.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2282. cellStylebt5.SetFont(cellfontbt4);
  2283. cellStylebt5.VerticalAlignment = VerticalAlignment.Center;
  2284. cellStylebt5.Alignment = HorizontalAlignment.Center;
  2285. HSSFPalette palette2 = workbook.GetCustomPalette(); //调色板实例
  2286. palette2.SetColorAtIndex(10, 216, 243, 198);
  2287. NPOI.HSSF.Util.HSSFColor hssFColor2 = palette2.FindColor(216, 243, 198);
  2288. cellStylebt5.FillForegroundColor = hssFColor2.Indexed;
  2289. cellStylebt5.FillPattern = FillPattern.SolidForeground;
  2290. cellStylebt5.FillBackgroundColor = hssFColor2.Indexed; ;
  2291. ICellStyle cellStylebt6 = workbook.CreateCellStyle();
  2292. cellStylebt6.WrapText = true;//设置换行这个要先设置
  2293. cellStylebt6.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2294. cellStylebt6.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2295. cellStylebt6.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2296. cellStylebt6.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2297. cellStylebt6.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2298. cellStylebt6.SetFont(cellfontbt4);
  2299. cellStylebt6.VerticalAlignment = VerticalAlignment.Center;
  2300. cellStylebt6.Alignment = HorizontalAlignment.Center;
  2301. HSSFPalette palette3 = workbook.GetCustomPalette(); //调色板实例
  2302. palette3.SetColorAtIndex(11, 253, 220, 212);
  2303. NPOI.HSSF.Util.HSSFColor hssFColor3 = palette3.FindColor(253, 220, 212);
  2304. cellStylebt6.FillForegroundColor = hssFColor3.Indexed;
  2305. cellStylebt6.FillPattern = FillPattern.SolidForeground;
  2306. cellStylebt6.FillBackgroundColor = hssFColor3.Indexed; ; ;
  2307. ICellStyle cellStylebt7 = workbook.CreateCellStyle();
  2308. cellStylebt7.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2309. cellStylebt7.WrapText = true;//设置换行这个要先设置
  2310. cellStylebt7.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2311. cellStylebt7.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2312. cellStylebt7.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2313. cellStylebt7.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2314. cellStylebt7.SetFont(cellfontbt4);
  2315. cellStylebt7.VerticalAlignment = VerticalAlignment.Center;
  2316. cellStylebt7.Alignment = HorizontalAlignment.Center;
  2317. HSSFPalette palette4 = workbook.GetCustomPalette(); //调色板实例
  2318. palette4.SetColorAtIndex(12, 248, 231, 187);
  2319. NPOI.HSSF.Util.HSSFColor hssFColor4 = palette4.FindColor(248, 231, 187);
  2320. cellStylebt7.FillForegroundColor = hssFColor4.Indexed;
  2321. cellStylebt7.FillPattern = FillPattern.SolidForeground;
  2322. cellStylebt7.FillBackgroundColor = hssFColor4.Indexed; ; ;
  2323. IRow irow1 = sheet.CreateRow(0);
  2324. ICell cell1 = irow1.CreateCell(0);
  2325. cell1.SetCellValue("电话中心受话情况统计表");
  2326. cell1.CellStyle = cellStylebt1;
  2327. sheet.AddMergedRegion(new CellRangeAddress(0, 2, 0, 9));
  2328. IRow irow2 = sheet.CreateRow(3);
  2329. string[] cols = { "序号", "班组", "坐席人员", "通话量"
  2330. , "呼入接通量", "呼出接通量", "呼出未接通量", "来电总量"
  2331. , "未接通量" , "待回拨量"};
  2332. for (int i = 0; i < cols.Length
  2333. ; i++)
  2334. {
  2335. ICell cell = irow2.CreateCell(i);
  2336. cell.SetCellValue(cols[i]);
  2337. cell.CellStyle = cellStylebt2;
  2338. }
  2339. IRow irow3 = sheet.CreateRow(4);
  2340. for (int i=0;i< dt.Tables [0].Rows.Count;i ++)
  2341. {
  2342. if (i ==0)
  2343. {
  2344. for (int j =0;j <7;j++)
  2345. {
  2346. ICell cell = irow3.CreateCell(j);
  2347. switch (j )
  2348. {
  2349. case 0:
  2350. cell.SetCellValue(i +1);
  2351. cell.CellStyle = cellStylebt3;
  2352. break;
  2353. case 1:
  2354. cell.SetCellValue(dt.Tables[0].Rows[i ]["groupname"].ToString ());
  2355. cell.CellStyle = cellStylebt3;
  2356. break;
  2357. case 2:
  2358. cell.SetCellValue(dt.Tables[0].Rows[i]["username"].ToString());
  2359. cell.CellStyle = cellStylebt3;
  2360. break;
  2361. case 3:
  2362. cell.SetCellValue(dt.Tables[0].Rows[i]["telcount"].ToString());
  2363. cell.CellStyle = cellStylebt4;
  2364. break;
  2365. case 4:
  2366. cell.SetCellValue(dt.Tables[0].Rows[i]["hrcount"].ToString());
  2367. cell.CellStyle = cellStylebt5;
  2368. break;
  2369. case 5:
  2370. cell.SetCellValue(dt.Tables[0].Rows[i]["hccount"].ToString());
  2371. cell.CellStyle = cellStylebt5;
  2372. break;
  2373. case 6:
  2374. cell.SetCellValue(dt.Tables[0].Rows[i]["hcwjtcount"].ToString());
  2375. cell.CellStyle = cellStylebt3;
  2376. break;
  2377. }
  2378. }
  2379. }
  2380. else
  2381. {
  2382. IRow irow4 = sheet.CreateRow(4+i );
  2383. for (int j = 0; j < 7; j++)
  2384. {
  2385. ICell cell = irow4.CreateCell(j );
  2386. switch (j)
  2387. {
  2388. case 0:
  2389. cell.SetCellValue(i + 1);
  2390. cell.CellStyle = cellStylebt3;
  2391. break;
  2392. case 1:
  2393. cell.SetCellValue(dt.Tables[0].Rows[i]["groupname"].ToString());
  2394. cell.CellStyle = cellStylebt3;
  2395. break;
  2396. case 2:
  2397. cell.SetCellValue(dt.Tables[0].Rows[i]["username"].ToString());
  2398. cell.CellStyle = cellStylebt3;
  2399. break;
  2400. case 3:
  2401. cell.SetCellValue(dt.Tables[0].Rows[i]["telcount"].ToString());
  2402. cell.CellStyle = cellStylebt4;
  2403. break;
  2404. case 4:
  2405. cell.SetCellValue(dt.Tables[0].Rows[i]["hrcount"].ToString());
  2406. cell.CellStyle = cellStylebt5;
  2407. break;
  2408. case 5:
  2409. cell.SetCellValue(dt.Tables[0].Rows[i]["hccount"].ToString());
  2410. cell.CellStyle = cellStylebt5;
  2411. break;
  2412. case 6:
  2413. cell.SetCellValue(dt.Tables[0].Rows[i]["hcwjtcount"].ToString());
  2414. cell.CellStyle = cellStylebt3;
  2415. break;
  2416. }
  2417. }
  2418. }
  2419. }
  2420. ICell cell2 = irow3.CreateCell(7);
  2421. cell2.SetCellValue(dt.Tables[1].Rows[0]["telcount"].ToString());
  2422. cell2.CellStyle = cellStylebt6;
  2423. sheet.AddMergedRegion(new CellRangeAddress(4, dt.Tables[0].Rows.Count+3, 7, 7));
  2424. ICell cell3 = irow3.CreateCell(8);
  2425. cell3.SetCellValue(dt.Tables[2].Rows[0]["wjtcount"].ToString());
  2426. cell3.CellStyle = cellStylebt7;
  2427. sheet.AddMergedRegion(new CellRangeAddress(4, dt.Tables[0].Rows.Count+3, 8, 8));
  2428. ICell cell4 = irow3.CreateCell(9);
  2429. cell4.SetCellValue(dt.Tables[3].Rows[0]["dhbcount"].ToString());
  2430. cell4.CellStyle = cellStylebt3;
  2431. sheet.AddMergedRegion(new CellRangeAddress(4, dt.Tables[0].Rows.Count+3, 9, 9));
  2432. for (int i = 0; i < 10; i++)
  2433. {
  2434. sheet.AutoSizeColumn(i);
  2435. }
  2436. using (MemoryStream ms = new MemoryStream())
  2437. {
  2438. workbook.Write(ms);
  2439. HttpContext curContext = HttpContext.Current;
  2440. // 设置编码和附件格式
  2441. curContext.Response.ContentType = "application/vnd.ms-excel";
  2442. curContext.Response.ContentEncoding = Encoding.UTF8;
  2443. curContext.Response.Charset = "";
  2444. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  2445. curContext.Response.AppendHeader("Content-Disposition",
  2446. "attachment;filename=" + HttpUtility.UrlEncode("电话中心受话情况统计表" + ".xls", Encoding.UTF8));
  2447. curContext.Response.BinaryWrite(ms.GetBuffer());
  2448. workbook = null;
  2449. ms.Close();
  2450. ms.Dispose();
  2451. curContext.Response.End();
  2452. }
  2453. return "";
  2454. }
  2455. catch(Exception e)
  2456. {
  2457. return e.Message;
  2458. }
  2459. }
  2460. /// <summary>
  2461. /// 居委办件统计
  2462. /// </summary>
  2463. /// <param name="ds"></param>
  2464. /// <returns></returns>
  2465. public string BureauHandling(DataSet dt)
  2466. {
  2467. try
  2468. {
  2469. int lenth = 0;
  2470. HSSFWorkbook workbook = new HSSFWorkbook();
  2471. ISheet sheet = workbook.CreateSheet("局委办件统计");
  2472. ICellStyle cellStyle = workbook.CreateCellStyle();
  2473. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  2474. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  2475. cellStyle.SetFont(cellfont);
  2476. ICellStyle cellStylebt1 = workbook.CreateCellStyle();
  2477. NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
  2478. cellfontbt1.Boldweight = (short)FontBoldWeight.Bold;
  2479. cellfontbt1.FontHeightInPoints = 20;
  2480. cellStylebt1.SetFont(cellfontbt1);
  2481. cellStylebt1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2482. cellStylebt1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2483. cellStylebt1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2484. cellStylebt1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2485. cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
  2486. cellStylebt1.Alignment = HorizontalAlignment.Center;
  2487. ICellStyle cellStylebt2 = workbook.CreateCellStyle();
  2488. NPOI.SS.UserModel.IFont cellfontbt2 = workbook.CreateFont();
  2489. cellfontbt2.Boldweight = (short)FontBoldWeight.Bold;
  2490. cellStylebt2.WrapText = true;//设置换行这个要先设置
  2491. cellfontbt2.FontHeightInPoints = 16;
  2492. cellStylebt2.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2493. cellStylebt2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2494. cellStylebt2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2495. cellStylebt2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2496. cellStylebt2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2497. cellStylebt2.SetFont(cellfontbt2);
  2498. cellStylebt2.VerticalAlignment = VerticalAlignment.Center;
  2499. cellStylebt2.Alignment = HorizontalAlignment.Center;
  2500. ICellStyle cellStylebt3 = workbook.CreateCellStyle();
  2501. NPOI.SS.UserModel.IFont cellfontbt3 = workbook.CreateFont();
  2502. cellfontbt3.Boldweight = (short)FontBoldWeight.Bold;
  2503. cellStylebt3.WrapText = true;//设置换行这个要先设置
  2504. cellfontbt3.FontHeightInPoints = 14;
  2505. cellStylebt3.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2506. cellStylebt3.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2507. cellStylebt3.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2508. cellStylebt3.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2509. cellStylebt3.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2510. cellStylebt3.SetFont(cellfontbt3);
  2511. cellStylebt3.VerticalAlignment = VerticalAlignment.Center;
  2512. cellStylebt3.Alignment = HorizontalAlignment.Center;
  2513. IRow irow1 = sheet.CreateRow(0);
  2514. ICell cell1 = irow1.CreateCell(0);
  2515. cell1.SetCellValue("局委办件统计");
  2516. cell1.CellStyle = cellStylebt1;
  2517. sheet.AddMergedRegion(new CellRangeAddress(0, 2, 0, 14));
  2518. IRow irow = sheet.CreateRow(3);
  2519. for (int i = 0; i < 15; i++)
  2520. {
  2521. ICell cell4 = irow.CreateCell(i);
  2522. cell4.CellStyle = cellStylebt2;
  2523. }
  2524. ICell cell2 = irow.CreateCell(5);
  2525. cell2.SetCellValue("未办结");
  2526. cell2.CellStyle = cellStylebt2;
  2527. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 5, 6));
  2528. ICell cell3 = irow.CreateCell(7);
  2529. cell3.SetCellValue("已办结");
  2530. cell3.CellStyle = cellStylebt2;
  2531. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 7, 9));
  2532. IRow irow2 = sheet.CreateRow(4);
  2533. string[] cols = { "序号", "承办单位", "承办件", "办结件"
  2534. , "办结率", "正在办理", "超期未果", "正常回复"
  2535. , "超期回复" , "已办未果", "待审核", "局委退件", "延期件", "重置转发", "驳回"};
  2536. for (int i = 0; i < cols.Length
  2537. ; i++)
  2538. {
  2539. ICell cell = irow2.CreateCell(i);
  2540. cell.SetCellValue(cols[i]);
  2541. cell.CellStyle = cellStylebt2;
  2542. }
  2543. if (dt!=null&& dt.Tables [0].Rows .Count >0)
  2544. {
  2545. for (int i=0; i< dt.Tables[0].Rows.Count;i++)
  2546. {
  2547. IRow irow3 = sheet.CreateRow(5+i);
  2548. for (int j = 0; j < cols.Length
  2549. ; j++)
  2550. {
  2551. ICell cell = irow3.CreateCell(j);
  2552. switch (j )
  2553. {
  2554. case 0:
  2555. cell.SetCellValue(i +1);
  2556. cell.CellStyle = cellStylebt3;
  2557. break;
  2558. case 1:
  2559. cell.SetCellValue(dt.Tables[0].Rows[i]["deptname"].ToString());
  2560. cell.CellStyle = cellStylebt3;
  2561. break;
  2562. case 2:
  2563. cell.SetCellValue(dt.Tables[0].Rows[i]["cbcount"].ToString());
  2564. cell.CellStyle = cellStylebt3;
  2565. break;
  2566. case 3:
  2567. cell.SetCellValue(dt.Tables[0].Rows[i]["bjcount"].ToString());
  2568. cell.CellStyle = cellStylebt3;
  2569. break;
  2570. case 4:
  2571. cell.SetCellValue(dt.Tables[0].Rows[i]["bjrate"].ToString());
  2572. cell.CellStyle = cellStylebt3;
  2573. break;
  2574. case 5:
  2575. cell.SetCellValue(dt.Tables[0].Rows[i]["blcount"].ToString());
  2576. cell.CellStyle = cellStylebt3;
  2577. break;
  2578. case 6:
  2579. cell.SetCellValue(dt.Tables[0].Rows[i]["cqwgcount"].ToString());
  2580. cell.CellStyle = cellStylebt3;
  2581. break;
  2582. case 7:
  2583. cell.SetCellValue(dt.Tables[0].Rows[i]["zchf"].ToString());
  2584. cell.CellStyle = cellStylebt3;
  2585. break;
  2586. case 8:
  2587. cell.SetCellValue(dt.Tables[0].Rows[i]["cqhf"].ToString());
  2588. cell.CellStyle = cellStylebt3;
  2589. break;
  2590. case 9:
  2591. cell.SetCellValue(dt.Tables[0].Rows[i]["ybwg"].ToString());
  2592. cell.CellStyle = cellStylebt3;
  2593. break;
  2594. case 10:
  2595. cell.SetCellValue(dt.Tables[0].Rows[i]["dsh"].ToString());
  2596. cell.CellStyle = cellStylebt3;
  2597. break;
  2598. case 11:
  2599. cell.SetCellValue(dt.Tables[0].Rows[i]["jwtj"].ToString());
  2600. cell.CellStyle = cellStylebt3;
  2601. break;
  2602. case 12:
  2603. cell.SetCellValue(dt.Tables[0].Rows[i]["yqcount"].ToString());
  2604. cell.CellStyle = cellStylebt3;
  2605. break;
  2606. case 13:
  2607. cell.SetCellValue(dt.Tables[0].Rows[i]["czzf"].ToString());
  2608. cell.CellStyle = cellStylebt3;
  2609. break;
  2610. case 14:
  2611. cell.SetCellValue(dt.Tables[0].Rows[i]["bh"].ToString());
  2612. cell.CellStyle = cellStylebt3;
  2613. break;
  2614. }
  2615. }
  2616. }
  2617. }
  2618. for (int i = 0; i < 10; i++)
  2619. {
  2620. sheet.AutoSizeColumn(i);
  2621. }
  2622. using (MemoryStream ms = new MemoryStream())
  2623. {
  2624. workbook.Write(ms);
  2625. HttpContext curContext = HttpContext.Current;
  2626. // 设置编码和附件格式
  2627. curContext.Response.ContentType = "application/vnd.ms-excel";
  2628. curContext.Response.ContentEncoding = Encoding.UTF8;
  2629. curContext.Response.Charset = "";
  2630. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  2631. curContext.Response.AppendHeader("Content-Disposition",
  2632. "attachment;filename=" + HttpUtility.UrlEncode("局委办件统计" + ".xls", Encoding.UTF8));
  2633. curContext.Response.BinaryWrite(ms.GetBuffer());
  2634. workbook = null;
  2635. ms.Close();
  2636. ms.Dispose();
  2637. curContext.Response.End();
  2638. }
  2639. return "";
  2640. }
  2641. catch (Exception e)
  2642. {
  2643. return e.Message;
  2644. }
  2645. }
  2646. /// <summary>
  2647. /// 政民互动综合统计
  2648. /// </summary>
  2649. /// <param name="ds"></param>
  2650. /// <returns></returns>
  2651. public string Government(DataSet dt)
  2652. {
  2653. try
  2654. {
  2655. int lenth = 0;
  2656. HSSFWorkbook workbook = new HSSFWorkbook();
  2657. ISheet sheet = workbook.CreateSheet("政民互动综合统计");
  2658. ICellStyle cellStyle = workbook.CreateCellStyle();
  2659. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  2660. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  2661. cellStyle.SetFont(cellfont);
  2662. ICellStyle cellStylebt1 = workbook.CreateCellStyle();
  2663. NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
  2664. cellfontbt1.Boldweight = (short)FontBoldWeight.Bold;
  2665. cellfontbt1.FontHeightInPoints = 20;
  2666. cellStylebt1.SetFont(cellfontbt1);
  2667. cellStylebt1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2668. cellStylebt1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2669. cellStylebt1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2670. cellStylebt1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2671. cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
  2672. cellStylebt1.Alignment = HorizontalAlignment.Center;
  2673. ICellStyle cellStylebt2 = workbook.CreateCellStyle();
  2674. NPOI.SS.UserModel.IFont cellfontbt2 = workbook.CreateFont();
  2675. cellfontbt2.Boldweight = (short)FontBoldWeight.Bold;
  2676. cellStylebt2.WrapText = true;//设置换行这个要先设置
  2677. cellfontbt2.FontHeightInPoints = 16;
  2678. cellStylebt2.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2679. cellStylebt2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2680. cellStylebt2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2681. cellStylebt2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2682. cellStylebt2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2683. cellStylebt2.SetFont(cellfontbt2);
  2684. cellStylebt2.VerticalAlignment = VerticalAlignment.Center;
  2685. cellStylebt2.Alignment = HorizontalAlignment.Center;
  2686. ICellStyle cellStylebt3 = workbook.CreateCellStyle();
  2687. NPOI.SS.UserModel.IFont cellfontbt3 = workbook.CreateFont();
  2688. cellfontbt3.Boldweight = (short)FontBoldWeight.Bold;
  2689. cellStylebt3.WrapText = true;//设置换行这个要先设置
  2690. cellfontbt3.FontHeightInPoints = 14;
  2691. cellStylebt3.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2692. cellStylebt3.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2693. cellStylebt3.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2694. cellStylebt3.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2695. cellStylebt3.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2696. cellStylebt3.SetFont(cellfontbt3);
  2697. cellStylebt3.VerticalAlignment = VerticalAlignment.Center;
  2698. cellStylebt3.Alignment = HorizontalAlignment.Center;
  2699. IRow irow1 = sheet.CreateRow(0);
  2700. ICell cell1 = irow1.CreateCell(0);
  2701. cell1.SetCellValue("政民互动综合统计");
  2702. cell1.CellStyle = cellStylebt1;
  2703. IRow irow = sheet.CreateRow(3);
  2704. sheet.AddMergedRegion(new CellRangeAddress(0, 2, 0, 14));
  2705. for (int i = 0; i < 15; i++)
  2706. {
  2707. ICell cell4 = irow.CreateCell(i );
  2708. cell4.CellStyle = cellStylebt2;
  2709. }
  2710. ICell cell2 = irow.CreateCell(6);
  2711. cell2.SetCellValue("状态");
  2712. cell2.CellStyle = cellStylebt2;
  2713. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 6, 9));
  2714. ICell cell3 = irow.CreateCell(10);
  2715. cell3.SetCellValue("已办结");
  2716. cell3.CellStyle = cellStylebt2;
  2717. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 10, 14));
  2718. IRow irow2 = sheet.CreateRow(4);
  2719. string[] cols = { "序号", "工单来源", "工单总量", "转办量"
  2720. , "退件量", "退件率", "已办结", "已办未果"
  2721. , "超期未果" , "办理率", "评议量", "满意量", "不满意量", "满意率", "重新转办量"};
  2722. for (int i = 0; i < cols.Length
  2723. ; i++)
  2724. {
  2725. ICell cell = irow2.CreateCell(i);
  2726. cell.SetCellValue(cols[i]);
  2727. cell.CellStyle = cellStylebt2;
  2728. }
  2729. if (dt != null && dt.Tables[0].Rows.Count > 0)
  2730. {
  2731. for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
  2732. {
  2733. IRow irow3 = sheet.CreateRow(5 + i);
  2734. for (int j = 0; j < cols.Length
  2735. ; j++)
  2736. {
  2737. ICell cell = irow3.CreateCell(j);
  2738. switch (j)
  2739. {
  2740. case 0:
  2741. cell.SetCellValue(i + 1);
  2742. cell.CellStyle = cellStylebt3;
  2743. break;
  2744. case 1:
  2745. cell.SetCellValue(dt.Tables[0].Rows[i]["name"].ToString());
  2746. cell.CellStyle = cellStylebt3;
  2747. break;
  2748. case 2:
  2749. cell.SetCellValue(dt.Tables[0].Rows[i]["totalcount"].ToString());
  2750. cell.CellStyle = cellStylebt3;
  2751. break;
  2752. case 3:
  2753. cell.SetCellValue(dt.Tables[0].Rows[i]["zb"].ToString());
  2754. cell.CellStyle = cellStylebt3;
  2755. break;
  2756. case 4:
  2757. cell.SetCellValue(dt.Tables[0].Rows[i]["td"].ToString());
  2758. cell.CellStyle = cellStylebt3;
  2759. break;
  2760. case 5:
  2761. cell.SetCellValue(dt.Tables[0].Rows[i]["tdrate"].ToString());
  2762. cell.CellStyle = cellStylebt3;
  2763. break;
  2764. case 6:
  2765. cell.SetCellValue(dt.Tables[0].Rows[i]["bj"].ToString());
  2766. cell.CellStyle = cellStylebt3;
  2767. break;
  2768. case 7:
  2769. cell.SetCellValue(dt.Tables[0].Rows[i]["ybwg"].ToString());
  2770. cell.CellStyle = cellStylebt3;
  2771. break;
  2772. case 8:
  2773. cell.SetCellValue(dt.Tables[0].Rows[i]["cqwg"].ToString());
  2774. cell.CellStyle = cellStylebt3;
  2775. break;
  2776. case 9:
  2777. cell.SetCellValue(dt.Tables[0].Rows[i]["blrate"].ToString());
  2778. cell.CellStyle = cellStylebt3;
  2779. break;
  2780. case 10:
  2781. cell.SetCellValue(dt.Tables[0].Rows[i]["py"].ToString());
  2782. cell.CellStyle = cellStylebt3;
  2783. break;
  2784. case 11:
  2785. cell.SetCellValue(dt.Tables[0].Rows[i]["my"].ToString());
  2786. cell.CellStyle = cellStylebt3;
  2787. break;
  2788. case 12:
  2789. cell.SetCellValue(dt.Tables[0].Rows[i]["bmy"].ToString());
  2790. cell.CellStyle = cellStylebt3;
  2791. break;
  2792. case 13:
  2793. cell.SetCellValue(dt.Tables[0].Rows[i]["myrate"].ToString());
  2794. cell.CellStyle = cellStylebt3;
  2795. break;
  2796. case 14:
  2797. cell.SetCellValue(dt.Tables[0].Rows[i]["cxzb"].ToString());
  2798. cell.CellStyle = cellStylebt3;
  2799. break;
  2800. }
  2801. }
  2802. }
  2803. }
  2804. for (int i = 0; i < 10; i++)
  2805. {
  2806. sheet.AutoSizeColumn(i);
  2807. }
  2808. using (MemoryStream ms = new MemoryStream())
  2809. {
  2810. workbook.Write(ms);
  2811. HttpContext curContext = HttpContext.Current;
  2812. // 设置编码和附件格式
  2813. curContext.Response.ContentType = "application/vnd.ms-excel";
  2814. curContext.Response.ContentEncoding = Encoding.UTF8;
  2815. curContext.Response.Charset = "";
  2816. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  2817. curContext.Response.AppendHeader("Content-Disposition",
  2818. "attachment;filename=" + HttpUtility.UrlEncode("政民互动综合统计" + ".xls", Encoding.UTF8));
  2819. curContext.Response.BinaryWrite(ms.GetBuffer());
  2820. workbook = null;
  2821. ms.Close();
  2822. ms.Dispose();
  2823. curContext.Response.End();
  2824. }
  2825. return "";
  2826. }
  2827. catch (Exception e)
  2828. {
  2829. return e.Message;
  2830. }
  2831. }
  2832. /// <summary>
  2833. /// 弹出下载框导出excel
  2834. /// </summary>
  2835. /// <param name="Name"></param>
  2836. /// <param name="dt"></param>
  2837. /// <returns></returns>
  2838. public string TSExportToExcel(DataTable dt, int tscount)
  2839. {
  2840. try
  2841. {
  2842. //if (dt.Rows.Count > 0)
  2843. //{
  2844. HSSFWorkbook workbook = new HSSFWorkbook();
  2845. ISheet sheet = workbook.CreateSheet("Sheet1");
  2846. ICellStyle HeadercellStyle = workbook.CreateCellStyle();
  2847. HeadercellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2848. HeadercellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2849. HeadercellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2850. HeadercellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2851. HeadercellStyle.Alignment = HorizontalAlignment.Center;
  2852. HeadercellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  2853. HeadercellStyle.FillPattern = FillPattern.SolidForeground;
  2854. HeadercellStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  2855. //字体
  2856. NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
  2857. headerfont.Boldweight = (short)FontBoldWeight.Bold;
  2858. headerfont.FontHeightInPoints = 12;
  2859. HeadercellStyle.SetFont(headerfont);
  2860. //用column name 作为列名
  2861. int icolIndex = 0;
  2862. IRow headerRow = sheet.CreateRow(0);
  2863. foreach (DataColumn dc in dt.Columns)
  2864. {
  2865. ICell cell = headerRow.CreateCell(icolIndex);
  2866. cell.SetCellValue(dc.ColumnName);
  2867. cell.CellStyle = HeadercellStyle;
  2868. icolIndex++;
  2869. }
  2870. ICellStyle cellStyle = workbook.CreateCellStyle();
  2871. //为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
  2872. cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
  2873. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2874. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2875. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2876. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2877. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  2878. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  2879. cellStyle.SetFont(cellfont);
  2880. //建立内容行
  2881. int iRowIndex = 0;
  2882. foreach (DataRow dr in dt.Rows)
  2883. {
  2884. int iCellIndex = 0;
  2885. IRow irow = sheet.CreateRow(iRowIndex + 1);
  2886. for (int i = 0; i < dt.Columns.Count; i++)
  2887. {
  2888. string strsj = string.Empty;
  2889. if (dr[i] != null)
  2890. {
  2891. strsj = dr[i].ToString();
  2892. }
  2893. ICell cell = irow.CreateCell(iCellIndex);
  2894. cell.SetCellValue(strsj);
  2895. cell.CellStyle = cellStyle;
  2896. iCellIndex++;
  2897. }
  2898. iRowIndex++;
  2899. }
  2900. sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 1));
  2901. sheet.AddMergedRegion(new CellRangeAddress(1, tscount, 0, 0));
  2902. for (int i = iRowIndex; i > tscount; i--)
  2903. {
  2904. sheet.AddMergedRegion(new CellRangeAddress(i, i, 0, 1));
  2905. }
  2906. //自适应列宽度
  2907. for (int i = 0; i < icolIndex; i++)
  2908. {
  2909. sheet.AutoSizeColumn(i);
  2910. }
  2911. using (MemoryStream ms = new MemoryStream())
  2912. {
  2913. workbook.Write(ms);
  2914. HttpContext curContext = HttpContext.Current;
  2915. // 设置编码和附件格式
  2916. curContext.Response.ContentType = "application/vnd.ms-excel";
  2917. curContext.Response.ContentEncoding = Encoding.UTF8;
  2918. curContext.Response.Charset = "";
  2919. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  2920. curContext.Response.AppendHeader("Content-Disposition",
  2921. "attachment;filename=" + HttpUtility.UrlEncode("投诉统计_导出文件_" + DateTime.Now.Ticks + ".xls", Encoding.UTF8));
  2922. curContext.Response.BinaryWrite(ms.GetBuffer());
  2923. workbook = null;
  2924. ms.Close();
  2925. ms.Dispose();
  2926. curContext.Response.End();
  2927. }
  2928. //}
  2929. return "";
  2930. }
  2931. catch
  2932. {
  2933. return "导出失败!";
  2934. }
  2935. }
  2936. /// <summary>
  2937. /// 生成excel到路径
  2938. /// </summary>
  2939. /// <param name="Name"></param>
  2940. /// <param name="dt"></param>
  2941. /// <returns></returns>
  2942. public string CreateExcelFile(string Name, DataTable dt, string Path,string[] cols = null)
  2943. {
  2944. try
  2945. {
  2946. if (dt.Rows.Count > 0)
  2947. {
  2948. HSSFWorkbook workbook = new HSSFWorkbook();
  2949. ISheet sheet = workbook.CreateSheet(Name);
  2950. ICellStyle HeadercellStyle = workbook.CreateCellStyle();
  2951. HeadercellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2952. HeadercellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2953. HeadercellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2954. HeadercellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2955. HeadercellStyle.Alignment = HorizontalAlignment.Center;
  2956. HeadercellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  2957. HeadercellStyle.FillPattern = FillPattern.SolidForeground;
  2958. HeadercellStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  2959. //字体
  2960. NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
  2961. headerfont.Boldweight = (short)FontBoldWeight.Bold;
  2962. headerfont.FontHeightInPoints = 12;
  2963. HeadercellStyle.SetFont(headerfont);
  2964. //用column name 作为列名
  2965. int icolIndex = 0;
  2966. IRow headerRow = sheet.CreateRow(0);
  2967. if (cols == null || (cols != null && cols.Length == 0))
  2968. {
  2969. foreach (DataColumn dc in dt.Columns)
  2970. {
  2971. ICell cell = headerRow.CreateCell(icolIndex);
  2972. cell.SetCellValue(dc.ColumnName);
  2973. cell.CellStyle = HeadercellStyle;
  2974. icolIndex++;
  2975. }
  2976. }
  2977. else
  2978. {
  2979. foreach (string dc in cols)
  2980. {
  2981. ICell cell = headerRow.CreateCell(icolIndex);
  2982. cell.SetCellValue(dc);
  2983. cell.CellStyle = HeadercellStyle;
  2984. icolIndex++;
  2985. }
  2986. }
  2987. ICellStyle cellStyle = workbook.CreateCellStyle();
  2988. //为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
  2989. cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
  2990. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2991. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2992. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2993. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2994. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  2995. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  2996. cellStyle.SetFont(cellfont);
  2997. //建立内容行
  2998. int iRowIndex = 0;
  2999. foreach (DataRow dr in dt.Rows)
  3000. {
  3001. int iCellIndex = 0;
  3002. IRow irow = sheet.CreateRow(iRowIndex + 1);
  3003. for (int i = 0; i < dt.Columns.Count; i++)
  3004. {
  3005. string strsj = string.Empty;
  3006. if (dr[i] != null)
  3007. {
  3008. strsj = dr[i].ToString();
  3009. }
  3010. ICell cell = irow.CreateCell(iCellIndex);
  3011. cell.SetCellValue(strsj);
  3012. cell.CellStyle = cellStyle;
  3013. iCellIndex++;
  3014. }
  3015. iRowIndex++;
  3016. }
  3017. //自适应列宽度
  3018. for (int i = 0; i < icolIndex; i++)
  3019. {
  3020. sheet.AutoSizeColumn(i);
  3021. }
  3022. Name = HttpUtility.UrlEncode(Name + "_导出文件_" + DateTime.Now.Ticks + ".xls");
  3023. Path = HttpContext.Current.Server.MapPath("..") + Path;
  3024. if (!Directory.Exists(Path)) Directory.CreateDirectory(Path);
  3025. FileStream fileHSSF = new FileStream(Path+ Name, FileMode.Create);
  3026. workbook.Write(fileHSSF);
  3027. fileHSSF.Close();
  3028. fileHSSF.Dispose();
  3029. workbook = null;
  3030. }
  3031. return "";
  3032. }
  3033. catch
  3034. {
  3035. return "生成失败!";
  3036. }
  3037. }
  3038. /// <summary>
  3039. /// 弹出下载框导出excel
  3040. /// </summary>
  3041. /// <param name="Name"></param>
  3042. /// <param name="dt"></param>
  3043. /// <returns></returns>
  3044. public string ExportToExcel64(string name, string base64url)
  3045. {
  3046. try
  3047. {
  3048. int delLength = base64url.IndexOf(',') + 1;
  3049. string str = base64url.Substring(delLength, base64url.Length - delLength);
  3050. byte[] bData = Convert.FromBase64String(str);
  3051. HttpContext curContext = HttpContext.Current;
  3052. // 设置编码和附件格式
  3053. curContext.Response.ContentType = "application/vnd.ms-excel";
  3054. curContext.Response.ContentEncoding = Encoding.UTF8;
  3055. curContext.Response.Charset = "";
  3056. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  3057. curContext.Response.AppendHeader("Content-Disposition",
  3058. "attachment;filename=" + HttpUtility.UrlEncode(name + "_导出文件_" + DateTime.Now.Ticks + ".xls", Encoding.UTF8));
  3059. curContext.Response.BinaryWrite(bData);
  3060. curContext.Response.End();
  3061. return "";
  3062. }
  3063. catch
  3064. {
  3065. return "导出失败!";
  3066. }
  3067. }
  3068. /// <summary>
  3069. /// 简报导出
  3070. /// </summary>
  3071. /// <param name="ds"></param>
  3072. /// <returns></returns>
  3073. public string SimpleExportToExcel(DataSet ds)
  3074. {
  3075. try
  3076. {
  3077. HSSFWorkbook workbook = new HSSFWorkbook();
  3078. ISheet sheet = workbook.CreateSheet("Sheet1");
  3079. ICellStyle cellStyle = workbook.CreateCellStyle();
  3080. //为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
  3081. //cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
  3082. //cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  3083. //cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  3084. //cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  3085. //cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  3086. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  3087. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  3088. cellStyle.SetFont(cellfont);
  3089. ICellStyle cellStylebt = workbook.CreateCellStyle();
  3090. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  3091. cellfontbt.Boldweight = (short)FontBoldWeight.Bold;
  3092. cellStylebt.SetFont(cellfontbt);
  3093. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  3094. cellStylebt.Alignment = HorizontalAlignment.Center;
  3095. IRow irow1 = sheet.CreateRow(1);
  3096. ICell cell1 = irow1.CreateCell(0);
  3097. cell1.SetCellValue("时间:"+ ds.Tables[5].Rows[0]["sdate"].ToString()+ " 至 "+ ds.Tables[5].Rows[0]["edate"].ToString());
  3098. cell1.CellStyle = cellStylebt;
  3099. sheet.AddMergedRegion(new CellRangeAddress(1, 1, 0, 7));
  3100. //((HSSFSheet)sheet).SetEnclosedBorderOfRegion(new CellRangeAddress(1, 1, 0, 7), BorderStyle.Thin, NPOI.HSSF.Util.HSSFColor.Black.Index);
  3101. #region 话务受理情况
  3102. DataTable dt1 = ds.Tables[0];
  3103. IRow irow2 = sheet.CreateRow(2);
  3104. ICell cell2 = irow2.CreateCell(0);
  3105. cell2.SetCellValue("话务受理情况");
  3106. cell2.CellStyle = cellStylebt;
  3107. sheet.AddMergedRegion(new CellRangeAddress(2, 2, 0, 7));
  3108. IRow irow3 = sheet.CreateRow(3);
  3109. ICell cell31 = irow3.CreateCell(0);
  3110. cell31.SetCellValue("来电");
  3111. cell31.CellStyle = cellStyle;
  3112. ICell cell32 = irow3.CreateCell(1);
  3113. cell32.SetCellValue(Int32.Parse(dt1.Rows[0]["ldcount"].ToString()));
  3114. cell32.CellStyle = cellStyle;
  3115. ICell cell33 = irow3.CreateCell(2);
  3116. cell33.SetCellValue("接听");
  3117. cell33.CellStyle = cellStyle;
  3118. ICell cell34 = irow3.CreateCell(3);
  3119. cell34.SetCellValue(Int32.Parse(dt1.Rows[0]["jtcount"].ToString()));
  3120. cell34.CellStyle = cellStyle;
  3121. ICell cell35 = irow3.CreateCell(4);
  3122. cell35.SetCellValue("有效接听");
  3123. cell35.CellStyle = cellStyle;
  3124. ICell cell36 = irow3.CreateCell(5);
  3125. cell36.SetCellValue(Int32.Parse(dt1.Rows[0]["yxcount"].ToString()));
  3126. cell36.CellStyle = cellStyle;
  3127. #endregion
  3128. #region 工单受理情况
  3129. DataTable dt2 = ds.Tables[1];
  3130. IRow irow4 = sheet.CreateRow(4);
  3131. ICell cell4 = irow4.CreateCell(0);
  3132. cell4.SetCellValue("工单受理情况");
  3133. cell4.CellStyle = cellStylebt;
  3134. sheet.AddMergedRegion(new CellRangeAddress(4, 4, 0, 7));
  3135. IRow irow5 = sheet.CreateRow(5);
  3136. ICell cell51 = irow5.CreateCell(0);
  3137. cell51.SetCellValue("受理");
  3138. cell51.CellStyle = cellStyle;
  3139. ICell cell52 = irow5.CreateCell(1);
  3140. cell52.SetCellValue(Int32.Parse(dt2.Rows[0]["slcount"].ToString()));
  3141. cell52.CellStyle = cellStyle;
  3142. ICell cell53 = irow5.CreateCell(2);
  3143. cell53.SetCellValue("待提交");
  3144. cell53.CellStyle = cellStyle;
  3145. ICell cell54 = irow5.CreateCell(3);
  3146. cell54.SetCellValue(Int32.Parse(dt2.Rows[0]["dtjcount"].ToString()));
  3147. cell54.CellStyle = cellStyle;
  3148. ICell cell55 = irow5.CreateCell(4);
  3149. cell55.SetCellValue("待交办");
  3150. cell55.CellStyle = cellStyle;
  3151. ICell cell56 = irow5.CreateCell(5);
  3152. cell56.SetCellValue(Int32.Parse(dt2.Rows[0]["djbcount"].ToString()));
  3153. cell56.CellStyle = cellStyle;
  3154. ICell cell57 = irow5.CreateCell(6);
  3155. cell57.SetCellValue("待查收");
  3156. cell57.CellStyle = cellStyle;
  3157. ICell cell58 = irow5.CreateCell(7);
  3158. cell58.SetCellValue(Int32.Parse(dt2.Rows[0]["dcscount"].ToString()));
  3159. cell58.CellStyle = cellStyle;
  3160. IRow irow6 = sheet.CreateRow(6);
  3161. ICell cell61 = irow6.CreateCell(0);
  3162. cell61.SetCellValue("待审核退回");
  3163. cell61.CellStyle = cellStyle;
  3164. ICell cell62 = irow6.CreateCell(1);
  3165. cell62.SetCellValue(Int32.Parse(dt2.Rows[0]["dshthcount"].ToString()));
  3166. cell62.CellStyle = cellStyle;
  3167. ICell cell63 = irow6.CreateCell(2);
  3168. cell63.SetCellValue("待办理");
  3169. cell63.CellStyle = cellStyle;
  3170. ICell cell64 = irow6.CreateCell(3);
  3171. cell64.SetCellValue(Int32.Parse(dt2.Rows[0]["dblcount"].ToString()));
  3172. cell64.CellStyle = cellStyle;
  3173. ICell cell65 = irow6.CreateCell(4);
  3174. cell65.SetCellValue("待延时审核");
  3175. cell65.CellStyle = cellStyle;
  3176. ICell cell66 = irow6.CreateCell(5);
  3177. cell66.SetCellValue(Int32.Parse(dt2.Rows[0]["dshyscount"].ToString()));
  3178. cell66.CellStyle = cellStyle;
  3179. ICell cell67 = irow6.CreateCell(6);
  3180. cell67.SetCellValue("待回访");
  3181. cell67.CellStyle = cellStyle;
  3182. ICell cell68 = irow6.CreateCell(7);
  3183. cell68.SetCellValue(Int32.Parse(dt2.Rows[0]["dhfcount"].ToString()));
  3184. cell68.CellStyle = cellStyle;
  3185. IRow irow7 = sheet.CreateRow(7);
  3186. ICell cell71 = irow7.CreateCell(0);
  3187. cell71.SetCellValue("待结案");
  3188. cell71.CellStyle = cellStyle;
  3189. ICell cell72 = irow7.CreateCell(1);
  3190. cell72.SetCellValue(Int32.Parse(dt2.Rows[0]["dwjcount"].ToString()));
  3191. cell72.CellStyle = cellStyle;
  3192. ICell cell73 = irow7.CreateCell(2);
  3193. cell73.SetCellValue("待重办");
  3194. cell73.CellStyle = cellStyle;
  3195. ICell cell74 = irow7.CreateCell(3);
  3196. cell74.SetCellValue(Int32.Parse(dt2.Rows[0]["dcbcount"].ToString()));
  3197. cell74.CellStyle = cellStyle;
  3198. ICell cell75 = irow7.CreateCell(4);
  3199. cell75.SetCellValue("已结案");
  3200. cell75.CellStyle = cellStyle;
  3201. ICell cell76 = irow7.CreateCell(5);
  3202. cell76.SetCellValue(Int32.Parse(dt2.Rows[0]["ywjcount"].ToString()));
  3203. cell76.CellStyle = cellStyle;
  3204. ICell cell77 = irow7.CreateCell(6);
  3205. cell77.SetCellValue("在线办理");
  3206. cell77.CellStyle = cellStyle;
  3207. ICell cell78 = irow7.CreateCell(7);
  3208. cell78.SetCellValue(Int32.Parse(dt2.Rows[0]["zxbjcount"].ToString()));
  3209. cell78.CellStyle = cellStyle;
  3210. IRow irow8 = sheet.CreateRow(8);
  3211. ICell cell81 = irow8.CreateCell(0);
  3212. cell81.SetCellValue("中心转派");
  3213. cell81.CellStyle = cellStyle;
  3214. ICell cell82 = irow8.CreateCell(1);
  3215. cell82.SetCellValue(Int32.Parse(dt2.Rows[0]["zxzpcount"].ToString()));
  3216. cell82.CellStyle = cellStyle;
  3217. ICell cell83 = irow8.CreateCell(2);
  3218. cell83.SetCellValue("在线办理率");
  3219. cell83.CellStyle = cellStyle;
  3220. ICell cell84 = irow8.CreateCell(3);
  3221. cell84.SetCellValue(dt2.Rows[0]["zxbjrate"].ToString());
  3222. cell84.CellStyle = cellStyle;
  3223. #endregion
  3224. #region 政府热线受理情况
  3225. DataTable dt3 = ds.Tables[2];
  3226. IRow irow9 = sheet.CreateRow(9);
  3227. ICell cell9 = irow9.CreateCell(0);
  3228. cell9.SetCellValue("政府热线受理情况");
  3229. cell9.CellStyle = cellStylebt;
  3230. sheet.AddMergedRegion(new CellRangeAddress(9, 9, 0, 7));
  3231. IRow irow10 = sheet.CreateRow(10);
  3232. IRow irow11 = sheet.CreateRow(11);
  3233. int n = 0;
  3234. foreach (DataRow dr3 in dt3.Rows)
  3235. {
  3236. if (n < 4)
  3237. {
  3238. ICell cell101 = irow10.CreateCell(2 * (n + 1) - 2);
  3239. cell101.SetCellValue(dr3["source"].ToString());
  3240. cell101.CellStyle = cellStyle;
  3241. ICell cell102 = irow10.CreateCell(2 * (n + 1) - 1);
  3242. cell102.SetCellValue(Int32.Parse(dr3["count"].ToString()));
  3243. cell102.CellStyle = cellStyle;
  3244. }
  3245. else
  3246. {
  3247. ICell cell111 = irow11.CreateCell(2 * (n -3) - 2);
  3248. cell111.SetCellValue(dr3["source"].ToString());
  3249. cell111.CellStyle = cellStyle;
  3250. ICell cell112 = irow11.CreateCell(2 * (n - 3) - 1);
  3251. cell112.SetCellValue(Int32.Parse(dr3["count"].ToString()));
  3252. cell112.CellStyle = cellStyle;
  3253. }
  3254. n = n + 1;
  3255. }
  3256. #endregion
  3257. #region 工单受理类型情况
  3258. DataTable dt4 = ds.Tables[3];
  3259. IRow irow12 = sheet.CreateRow(12);
  3260. ICell cell12 = irow12.CreateCell(0);
  3261. cell12.SetCellValue("工单受理类型情况");
  3262. cell12.CellStyle = cellStylebt;
  3263. sheet.AddMergedRegion(new CellRangeAddress(12, 12, 0, 7));
  3264. IRow irow13 = sheet.CreateRow(13);
  3265. IRow irow14 = sheet.CreateRow(14);
  3266. int m = 0;
  3267. foreach (DataRow dr4 in dt4.Rows)
  3268. {
  3269. if (m < 4)
  3270. {
  3271. ICell cell131 = irow13.CreateCell(2 * (m + 1) - 2);
  3272. cell131.SetCellValue(dr4["type"].ToString());
  3273. cell131.CellStyle = cellStyle;
  3274. ICell cell132 = irow13.CreateCell(2 * (m + 1) - 1);
  3275. cell132.SetCellValue(Int32.Parse(dr4["count"].ToString()));
  3276. cell132.CellStyle = cellStyle;
  3277. }
  3278. else
  3279. {
  3280. ICell cell141 = irow14.CreateCell(2 * (m - 3) - 2);
  3281. cell141.SetCellValue(dr4["type"].ToString());
  3282. cell141.CellStyle = cellStyle;
  3283. ICell cell152 = irow14.CreateCell(2 * (m - 3) - 1);
  3284. cell152.SetCellValue(Int32.Parse(dr4["count"].ToString()));
  3285. cell152.CellStyle = cellStyle;
  3286. }
  3287. m = m + 1;
  3288. }
  3289. #endregion
  3290. #region 工单事发区域情况
  3291. DataTable dt5 = ds.Tables[4];
  3292. IRow irow15 = sheet.CreateRow(15);
  3293. ICell cell15 = irow15.CreateCell(0);
  3294. cell15.SetCellValue("工单事发区域情况");
  3295. cell15.CellStyle = cellStylebt;
  3296. sheet.AddMergedRegion(new CellRangeAddress(15, 15, 0, 7));
  3297. int rowcount = (dt5.Rows.Count / 4) + 1;
  3298. for (int i = 0; i < rowcount; i++)
  3299. {
  3300. IRow irow = sheet.CreateRow(16 + i);
  3301. for (int j = 0; j < 4; j++)
  3302. {
  3303. int num = i * 4 + j;
  3304. if (num != dt5.Rows.Count)
  3305. {
  3306. var dr = dt5.Rows[num];
  3307. ICell cellname = irow.CreateCell(2 * (j + 1) - 2);
  3308. cellname.SetCellValue(dr["areaname"].ToString());
  3309. cellname.CellStyle = cellStyle;
  3310. ICell cellcount = irow.CreateCell(2 * (j + 1) - 1);
  3311. cellcount.SetCellValue(Int32.Parse(dr["count"].ToString()));
  3312. cellcount.CellStyle = cellStyle;
  3313. }
  3314. else
  3315. {
  3316. break;
  3317. }
  3318. }
  3319. }
  3320. #endregion
  3321. //自适应列宽度
  3322. for (int i = 0; i < 8; i++)
  3323. {
  3324. sheet.AutoSizeColumn(i);
  3325. }
  3326. using (MemoryStream ms = new MemoryStream())
  3327. {
  3328. workbook.Write(ms);
  3329. HttpContext curContext = HttpContext.Current;
  3330. // 设置编码和附件格式
  3331. curContext.Response.ContentType = "application/vnd.ms-excel";
  3332. curContext.Response.ContentEncoding = Encoding.UTF8;
  3333. curContext.Response.Charset = "";
  3334. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  3335. curContext.Response.AppendHeader("Content-Disposition",
  3336. "attachment;filename=" + HttpUtility.UrlEncode("业务简报_导出文件_" + DateTime.Now.Ticks + ".xls", Encoding.UTF8));
  3337. curContext.Response.BinaryWrite(ms.GetBuffer());
  3338. workbook = null;
  3339. ms.Close();
  3340. ms.Dispose();
  3341. curContext.Response.End();
  3342. }
  3343. return "";
  3344. }
  3345. catch
  3346. {
  3347. return "导出失败!";
  3348. }
  3349. }
  3350. /// <summary>
  3351. /// 弹出下载框导出excel(数据第一行为标题)
  3352. /// </summary>
  3353. /// <param name="Name"></param>
  3354. /// <param name="dt"></param>
  3355. /// <returns></returns>
  3356. public string ExportToExcel2(string Name, DataTable dt, string[] cols = null)
  3357. {
  3358. try
  3359. {
  3360. //if (dt.Rows.Count > 0)
  3361. //{
  3362. HSSFWorkbook workbook = new HSSFWorkbook();
  3363. ISheet sheet = workbook.CreateSheet("Sheet1");
  3364. ICellStyle HeadercellStyle = workbook.CreateCellStyle();
  3365. HeadercellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  3366. HeadercellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  3367. HeadercellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  3368. HeadercellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  3369. HeadercellStyle.Alignment = HorizontalAlignment.Center;
  3370. HeadercellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  3371. HeadercellStyle.FillPattern = FillPattern.SolidForeground;
  3372. HeadercellStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  3373. //字体
  3374. NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
  3375. headerfont.Boldweight = (short)FontBoldWeight.Bold;
  3376. headerfont.FontHeightInPoints = 12;
  3377. HeadercellStyle.SetFont(headerfont);
  3378. //用column name 作为列名
  3379. int icolIndex = 0;
  3380. IRow headerRow = sheet.CreateRow(0);
  3381. if (cols == null || (cols != null && cols.Length == 0))
  3382. {
  3383. //foreach (DataColumn dc in dt.Columns)
  3384. //{
  3385. // ICell cell = headerRow.CreateCell(icolIndex);
  3386. // cell.SetCellValue(dc.ColumnName);
  3387. // cell.CellStyle = HeadercellStyle;
  3388. // icolIndex++;
  3389. //}
  3390. for (int i = 0; i < dt.Columns.Count; i++)
  3391. {
  3392. ICell cell = headerRow.CreateCell(icolIndex);
  3393. cell.SetCellValue(dt.Rows[0][i].ToString());
  3394. cell.CellStyle = HeadercellStyle;
  3395. icolIndex++;
  3396. }
  3397. }
  3398. else
  3399. {
  3400. foreach (string dc in cols)
  3401. {
  3402. ICell cell = headerRow.CreateCell(icolIndex);
  3403. cell.SetCellValue(dc);
  3404. cell.CellStyle = HeadercellStyle;
  3405. icolIndex++;
  3406. }
  3407. }
  3408. ICellStyle cellStyle = workbook.CreateCellStyle();
  3409. //为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
  3410. cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
  3411. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  3412. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  3413. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  3414. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  3415. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  3416. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  3417. cellStyle.SetFont(cellfont);
  3418. //建立内容行
  3419. int iRowIndex = 0;
  3420. foreach (DataRow dr in dt.Rows)
  3421. {
  3422. if (iRowIndex > 0)
  3423. {
  3424. int iCellIndex = 0;
  3425. IRow irow = sheet.CreateRow(iRowIndex);
  3426. for (int i = 0; i < dt.Columns.Count; i++)
  3427. {
  3428. string strsj = string.Empty;
  3429. if (dr[i] != null)
  3430. {
  3431. strsj = dr[i].ToString();
  3432. }
  3433. ICell cell = irow.CreateCell(iCellIndex);
  3434. cell.SetCellValue(strsj);
  3435. cell.CellStyle = cellStyle;
  3436. iCellIndex++;
  3437. }
  3438. }
  3439. iRowIndex++;
  3440. }
  3441. //自适应列宽度
  3442. for (int i = 0; i < icolIndex; i++)
  3443. {
  3444. sheet.AutoSizeColumn(i);
  3445. }
  3446. using (MemoryStream ms = new MemoryStream())
  3447. {
  3448. workbook.Write(ms);
  3449. HttpContext curContext = HttpContext.Current;
  3450. // 设置编码和附件格式
  3451. curContext.Response.ContentType = "application/vnd.ms-excel";
  3452. curContext.Response.ContentEncoding = Encoding.UTF8;
  3453. curContext.Response.Charset = "";
  3454. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  3455. curContext.Response.AppendHeader("Content-Disposition",
  3456. "attachment;filename=" + HttpUtility.UrlEncode(Name + ".xls", Encoding.UTF8));
  3457. curContext.Response.BinaryWrite(ms.GetBuffer());
  3458. workbook = null;
  3459. ms.Close();
  3460. ms.Dispose();
  3461. curContext.Response.End();
  3462. }
  3463. //}
  3464. return "";
  3465. }
  3466. catch
  3467. {
  3468. return "导出失败!";
  3469. }
  3470. }
  3471. /// <summary>
  3472. /// 导出word
  3473. /// </summary>
  3474. /// <returns></returns>
  3475. public byte[] ExportToWordDemo()
  3476. {
  3477. try
  3478. {
  3479. //创建document文档对象对象实例
  3480. NPOI.XWPF.UserModel.XWPFDocument document = new NPOI.XWPF.UserModel.XWPFDocument();
  3481. document.CreateParagraph();
  3482. NPOI.XWPF.UserModel.XWPFParagraph paragraph = document.CreateParagraph();//创建段落对象
  3483. paragraph.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.CENTER;//文字显示位置,段落排列(左对齐,居中,右对齐)
  3484. NPOI.XWPF.UserModel.XWPFRun xwpfRun = paragraph.CreateRun();//创建段落文本对象
  3485. xwpfRun.IsBold = true;//文字加粗
  3486. xwpfRun.SetText("安阳市12345政务服务热线交办单");//填充内容
  3487. xwpfRun.FontSize = 18;//设置文字大小
  3488. xwpfRun.SetFontFamily("宋体", NPOI.XWPF.UserModel.FontCharRange.None); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
  3489. document.CreateParagraph();
  3490. //创建文档中的表格对象实例
  3491. NPOI.XWPF.UserModel.XWPFTable table = document.CreateTable(9, 8);//显示的行列数rows:3行,cols:4列
  3492. table.Width = 5200;//总宽度
  3493. table.SetColumnWidth(0, 650); /* 设置列宽 */
  3494. table.SetColumnWidth(1, 650);
  3495. table.SetColumnWidth(2, 650);
  3496. table.SetColumnWidth(3, 650);
  3497. table.SetColumnWidth(4, 650);
  3498. table.SetColumnWidth(5, 650);
  3499. table.SetColumnWidth(6, 650);
  3500. table.SetColumnWidth(7, 650);
  3501. for (int i = 0; i < 9; i++)
  3502. {
  3503. for (int j = 0; j < 8; j++)
  3504. {
  3505. var cp = table.GetRow(i).GetCell(j).GetCTTc().AddNewTcPr();
  3506. cp.AddNewVAlign().val = ST_VerticalJc.center;
  3507. }
  3508. }
  3509. //第一行
  3510. table.GetRow(0).GetCTRow().AddNewTrPr().AddNewTrHeight().val= (ulong)300;
  3511. var cp0 = table.GetRow(0).GetCell(0).GetCTTc().AddNewTcPr();
  3512. cp0.AddNewVMerge().val = ST_Merge.restart;
  3513. cp0.AddNewVAlign().val = ST_VerticalJc.center;
  3514. cp0.tcW = new CT_TblWidth();cp0.tcW.w = "650";cp0.tcW.type = ST_TblWidth.dxa;
  3515. table.GetRow(0).GetCell(0).SetParagraph(GetParagraph(table, true, "事项编号"));
  3516. var cp1 = table.GetRow(0).GetCell(1).GetCTTc().AddNewTcPr();
  3517. cp1.AddNewVMerge().val = ST_Merge.restart;
  3518. cp1.AddNewVAlign().val = ST_VerticalJc.center;
  3519. table.GetRow(0).GetCell(1).SetParagraph(GetParagraph(table, false, "DH9941052721041200351"));
  3520. table.GetRow(0).GetCell(2).SetParagraph(GetParagraph(table, true, "工单来源"));
  3521. table.GetRow(0).GetCell(3).SetParagraph(GetParagraph(table, false, "市长电话"));
  3522. table.GetRow(0).GetCell(4).SetParagraph(GetParagraph(table, true, "办理时限"));
  3523. table.GetRow(0).GetCell(5).SetParagraph(GetParagraph(table, false, "2021-04-21"));
  3524. table.GetRow(0).GetCell(6).SetParagraph(GetParagraph(table, true, "联系电话"));
  3525. table.GetRow(0).GetCell(7).SetParagraph(GetParagraph(table, false, "017185328292"));
  3526. //第二行
  3527. table.GetRow(1).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)300;
  3528. var cp2 = table.GetRow(1).GetCell(0).GetCTTc().AddNewTcPr();
  3529. cp2.AddNewVMerge().val = ST_Merge.@continue;
  3530. var cp3 = table.GetRow(1).GetCell(1).GetCTTc().AddNewTcPr();
  3531. cp3.AddNewVMerge().val = ST_Merge.@continue;
  3532. table.GetRow(1).GetCell(2).SetParagraph(GetParagraph(table, true, "签收时间"));
  3533. table.GetRow(1).GetCell(3).SetParagraph(GetParagraph(table, false, "2021-04-12"));
  3534. table.GetRow(1).GetCell(4).SetParagraph(GetParagraph(table, true, "办理时间"));
  3535. table.GetRow(1).GetCell(5).SetParagraph(GetParagraph(table, false, "2021-04-12"));
  3536. table.GetRow(1).GetCell(6).SetParagraph(GetParagraph(table, true, "来电人"));
  3537. table.GetRow(1).GetCell(7).SetParagraph(GetParagraph(table, false, "徐青田"));
  3538. //第三行
  3539. table.GetRow(2).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)300;
  3540. table.GetRow(2).MergeCells(1, 7);//合并列
  3541. table.GetRow(2).GetCell(0).SetParagraph(GetParagraph(table, true, "事项区域"));
  3542. table.GetRow(2).GetCell(1).SetParagraph(GetParagraph(table, false, "河南省郑州市高新技术开发区大学科技园东区", false));
  3543. //第四行
  3544. table.GetRow(3).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)2000;
  3545. table.GetRow(3).MergeCells(1, 7);//合并列
  3546. table.GetRow(3).GetCell(0).SetParagraph(GetParagraph(table, true, "内容摘要"));
  3547. table.GetRow(3).GetCell(1).SetParagraph(GetParagraph(table, false, "来电人反映:内黄县城关镇宛庄村第四生产队第二、三小组土地至今无法确权(遗留问题),村委会和镇政府承诺给解决,至今未解决,请政府责成相关部门调查处理。", false));
  3548. //第五行
  3549. table.GetRow(4).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)300;
  3550. table.GetRow(4).MergeCells(1, 4);//合并列
  3551. table.GetRow(4).MergeCells(3, 4);//合并列
  3552. table.GetRow(4).GetCell(0).SetParagraph(GetParagraph(table, true, "承办单位"));
  3553. table.GetRow(4).GetCell(1).SetParagraph(GetParagraph(table, false, "内黄县政府"));
  3554. table.GetRow(4).GetCell(2).SetParagraph(GetParagraph(table, true, "协办单位"));
  3555. table.GetRow(4).GetCell(3).SetParagraph(GetParagraph(table, false, "内黄县政府"));
  3556. //第六行
  3557. table.GetRow(5).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)2000;
  3558. table.GetRow(5).MergeCells(1, 7);//合并列
  3559. table.GetRow(5).GetCell(0).SetParagraph(GetParagraph(table, true, "调度意见"));
  3560. table.GetRow(5).GetCell(1).SetParagraph(GetParagraph(table, false, "请按领导批示认真调查处理并答复来电人,在5个工作日内通过网络反馈市市长热线办公室。要求注明主办人、主管领导姓名和联系电话,同时提供有关处理依据。", false));
  3561. //第七行
  3562. table.GetRow(6).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)1500;
  3563. table.GetRow(6).MergeCells(1, 7);//合并列
  3564. table.GetRow(6).GetCell(0).SetParagraph(GetParagraph(table, true, "承办意见"));
  3565. table.GetRow(6).GetCell(1).SetParagraph(GetParagraph(table, false, "请按领导批示认真调查处理并答复来电人,在5个工作日内通过网络反馈市市长热线办公室。要求注明主办人、主管领导姓名和联系电话,同时提供有关处理依据。", false));
  3566. //第八行
  3567. table.GetRow(7).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)1500;
  3568. table.GetRow(7).MergeCells(1, 7);//合并列
  3569. table.GetRow(7).GetCell(0).SetParagraph(GetParagraph(table, true, "领导批示"));
  3570. table.GetRow(7).GetCell(1).SetParagraph(GetParagraph(table, false, "请按领导批示认真调查处理并答复来电人,在5个工作日内通过网络反馈市市长热线办公室。要求注明主办人、主管领导姓名和联系电话,同时提供有关处理依据。", false));
  3571. //第九行
  3572. table.GetRow(8).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)2000;
  3573. table.GetRow(8).MergeCells(1, 7);//合并列
  3574. table.GetRow(8).GetCell(0).SetParagraph(GetParagraph(table, true, "处理结果"));
  3575. table.GetRow(8).GetCell(1).SetParagraph(GetParagraph(table, false, "2021-04-12 10:19:14 内黄县政府部门接到市长电话来源工单(编号:DH9941052721041200351)反映土地确权问题,已联系郑州第三方中标土地确权公司负责人待工作人员到我县后,就可以确权 [办理结果:已办理,承办人:刘志强,职务:城关镇人大主席,联系电话:15824608111,刘志强向当事人进行了反馈,当事人对结果表示未评价。]", false));
  3576. document.CreateParagraph();
  3577. NPOI.XWPF.UserModel.XWPFParagraph paragraph1 = document.CreateParagraph();//创建段落对象
  3578. paragraph1.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.CENTER;//文字显示位置,段落排列(左对齐,居中,右对齐)
  3579. NPOI.XWPF.UserModel.XWPFRun xwpfRun1 = paragraph1.CreateRun();//创建段落文本对象
  3580. xwpfRun1.IsBold = true;//文字加粗
  3581. xwpfRun1.SetText("联系电话:(0372) 12345审核人:8000 调度员:8065");//填充内容
  3582. xwpfRun1.FontSize = 9;//设置文字大小
  3583. xwpfRun1.SetFontFamily("宋体", NPOI.XWPF.UserModel.FontCharRange.None); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
  3584. NPOI.XWPF.UserModel.XWPFParagraph paragraph2 = document.CreateParagraph();//创建段落对象
  3585. paragraph2.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.RIGHT;//文字显示位置,段落排列(左对齐,居中,右对齐)
  3586. NPOI.XWPF.UserModel.XWPFRun xwpfRun2 = paragraph2.CreateRun();//创建段落文本对象
  3587. using (FileStream picData = new FileStream(HttpContext.Current.Server.MapPath("/Upload/Word/word.png"), FileMode.Open, FileAccess.Read))
  3588. {
  3589. //图片的文件流 图片类型 图片名称 设置的宽度以及高度
  3590. xwpfRun2.AddPicture(picData, (int)PictureType.PNG, "word.png", NPOI.Util.Units.ToEMU(100), NPOI.Util.Units.ToEMU(100));
  3591. }
  3592. using (MemoryStream ms = new MemoryStream())
  3593. {
  3594. document.Write(ms);
  3595. return ms.GetBuffer();
  3596. }
  3597. }
  3598. catch(Exception ex)
  3599. {
  3600. return null;
  3601. }
  3602. }
  3603. /// <summary>
  3604. ///
  3605. /// </summary>
  3606. /// <param name="document"></param>
  3607. /// <param name="isbold"></param>
  3608. /// <param name="content"></param>
  3609. /// <returns></returns>
  3610. private NPOI.XWPF.UserModel.XWPFParagraph GetParagraph(NPOI.XWPF.UserModel.XWPFTable table,bool isbold,string content, bool iscenter=true)
  3611. {
  3612. var para = new CT_P();
  3613. //设置单元格文本对齐
  3614. para.AddNewPPr().AddNewTextAlignment();
  3615. NPOI.XWPF.UserModel.XWPFParagraph paragraph = new NPOI.XWPF.UserModel.XWPFParagraph(para,table.Body);
  3616. paragraph.VerticalAlignment = NPOI.XWPF.UserModel.TextAlignment.CENTER;
  3617. if (iscenter)
  3618. {
  3619. paragraph.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.CENTER;
  3620. }
  3621. else
  3622. {
  3623. paragraph.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.LEFT;
  3624. }
  3625. NPOI.XWPF.UserModel.XWPFRun xwpfRun = paragraph.CreateRun();//创建段落文本对象
  3626. xwpfRun.IsBold = isbold;//文字加粗
  3627. xwpfRun.SetText(content);//填充内容
  3628. xwpfRun.FontSize = 9;//设置文字大小
  3629. xwpfRun.SetFontFamily("宋体", NPOI.XWPF.UserModel.FontCharRange.None); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
  3630. return paragraph;
  3631. }
  3632. /// <summary>
  3633. /// 插入图片
  3634. /// </summary>
  3635. /// <param name="table"></param>
  3636. /// <returns></returns>
  3637. private NPOI.XWPF.UserModel.XWPFParagraph GetParagraphImg(NPOI.XWPF.UserModel.XWPFTable table, bool isbold, string content, bool iscenter = true)
  3638. {
  3639. var para = new CT_P();
  3640. //设置单元格文本对齐
  3641. para.AddNewPPr().AddNewTextAlignment();
  3642. NPOI.XWPF.UserModel.XWPFParagraph paragraph = new NPOI.XWPF.UserModel.XWPFParagraph(para, table.Body);
  3643. paragraph.VerticalAlignment = NPOI.XWPF.UserModel.TextAlignment.CENTER;
  3644. if (iscenter)
  3645. {
  3646. paragraph.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.CENTER;
  3647. }
  3648. else
  3649. {
  3650. paragraph.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.LEFT;
  3651. }
  3652. NPOI.XWPF.UserModel.XWPFRun xwpfRun = paragraph.CreateRun();//创建段落文本对象
  3653. xwpfRun.IsBold = isbold;//文字加粗
  3654. xwpfRun.SetText(content);//填充内容
  3655. xwpfRun.FontSize = 9;//设置文字大小
  3656. xwpfRun.SetFontFamily("宋体", NPOI.XWPF.UserModel.FontCharRange.None); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
  3657. using (FileStream picData = new FileStream(HttpContext.Current.Server.MapPath("/Upload/Word/word.png"), FileMode.Open, FileAccess.Read))
  3658. {
  3659. //图片的文件流 图片类型 图片名称 设置的宽度以及高度
  3660. xwpfRun.AddPicture(picData, (int)PictureType.PNG, "word.png", NPOI.Util.Units.ToEMU(100), NPOI.Util.Units.ToEMU(100));
  3661. }
  3662. return paragraph;
  3663. }
  3664. }
  3665. }