Nenhuma Descrição

NPOIHelper.cs 205KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356
  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, 14));
  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(index, index+1, 0, 0));
  677. ICell cell2 = irow1.CreateCell(1);
  678. cell2.SetCellValue("部门名称");
  679. cell2.CellStyle = cellStylebt;
  680. sheet.AddMergedRegion(new CellRangeAddress(index, index + 1, 1, 1));
  681. ICell cell14 = irow1.CreateCell(8);
  682. cell14.SetCellValue("回访量");
  683. cell14.CellStyle = cellStylebt;
  684. sheet.AddMergedRegion(new CellRangeAddress(index, index + 1, 8, 8));
  685. ICell cell15 = irow1.CreateCell(9);
  686. cell15.SetCellValue("满意量");
  687. cell15.CellStyle = cellStylebt;
  688. sheet.AddMergedRegion(new CellRangeAddress(index, index + 1, 9, 9));
  689. ICell cell4 = irow1.CreateCell(10);
  690. cell4.SetCellValue("回访满意度");
  691. cell4.CellStyle = cellStylebt;
  692. sheet.AddMergedRegion(new CellRangeAddress(index, index + 1, 10, 10));
  693. ICell cell5 = irow1.CreateCell(11);
  694. cell5.SetCellValue("知识库更新");
  695. cell5.CellStyle = cellStylebt;
  696. sheet.AddMergedRegion(new CellRangeAddress(index, index + 1, 11, 11));
  697. ICell cell8 = irow1.CreateCell(12);
  698. cell8.SetCellValue("热线整合");
  699. cell8.CellStyle = cellStylebt;
  700. sheet.AddMergedRegion(new CellRangeAddress(index, index + 1, 12, 12));
  701. ICell cell6 = irow1.CreateCell(13);
  702. cell6.SetCellValue("加扣分项");
  703. cell6.CellStyle = cellStylebt;
  704. sheet.AddMergedRegion(new CellRangeAddress(index, index + 1, 13, 13));
  705. ICell cell7 = irow1.CreateCell(14);
  706. cell7.SetCellValue("总分");
  707. cell7.CellStyle = cellStylebt;
  708. sheet.AddMergedRegion(new CellRangeAddress(index, index + 1, 14, 14));
  709. ICell cell9 = irow1.CreateCell(2);
  710. cell9.SetCellValue("工单办理");
  711. cell9.CellStyle = cellStylebt;
  712. sheet.AddMergedRegion(new CellRangeAddress(index, index, 2, 7));
  713. //ICell cell10 = irow1.CreateCell(4);
  714. //cell10.SetCellValue("事项办理");
  715. //cell10.CellStyle = cellStylebt;
  716. //sheet.AddMergedRegion(new CellRangeAddress(index, index, 4, 5));
  717. //ICell cell12 = irow1.CreateCell(6);
  718. //cell12.SetCellValue("办理时限");
  719. //cell12.CellStyle = cellStylebt;
  720. //sheet.AddMergedRegion(new CellRangeAddress(index, index, 6, 7));
  721. //ICell cell13 = irow1.CreateCell(8);
  722. //cell13.SetCellValue("重办事项");
  723. //cell13.CellStyle = cellStylebt;
  724. //sheet.AddMergedRegion(new CellRangeAddress(index, index, 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(2);
  734. cell17.SetCellValue("承办量");
  735. cell17.CellStyle = cellStylebt;
  736. ICell cell18 = irow3.CreateCell(3);
  737. cell18.SetCellValue("事项办理得分");
  738. cell18.CellStyle = cellStylebt;
  739. ICell cell19 = irow3.CreateCell(4);
  740. cell19.SetCellValue("逾期量");
  741. cell19.CellStyle = cellStylebt;
  742. ICell cell20 = irow3.CreateCell(5);
  743. cell20.SetCellValue("办理时限得分");
  744. cell20.CellStyle = cellStylebt;
  745. ICell cell21 = irow3.CreateCell(6);
  746. cell21.SetCellValue("重办量");
  747. cell21.CellStyle = cellStylebt;
  748. ICell cell22 = irow3.CreateCell(7);
  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 < 15; 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 2:
  791. ICell cel3 = irow4.CreateCell(i);
  792. cel3.SetCellValue(dr["F_Undertake"].ToString());
  793. cel3.CellStyle = cellStylebt1;
  794. break;
  795. case 3:
  796. ICell cel13 = irow4.CreateCell(i);
  797. cel13.SetCellValue(dr["F_Handling"].ToString());
  798. cel13.CellStyle = cellStylebt1;
  799. break;
  800. case 4:
  801. ICell cel4 = irow4.CreateCell(i);
  802. cel4.SetCellValue(dr["F_Boverdue"].ToString());
  803. cel4.CellStyle = cellStylebt1;
  804. break;
  805. case 5:
  806. ICell cel14 = irow4.CreateCell(i);
  807. cel14.SetCellValue(dr["F_Timelimit"].ToString());
  808. cel14.CellStyle = cellStylebt1;
  809. break;
  810. case 6:
  811. ICell cel15 = irow4.CreateCell(i);
  812. cel15.SetCellValue(dr["F_Redovolume"].ToString());
  813. cel15.CellStyle = cellStylebt1;
  814. break;
  815. case 7:
  816. ICell cel5 = irow4.CreateCell(i);
  817. cel5.SetCellValue(dr["F_Redo"].ToString());
  818. cel5.CellStyle = cellStylebt1;
  819. break;
  820. case 8:
  821. ICell cel16 = irow4.CreateCell(i);
  822. cel16.SetCellValue(dr["F_Returnvisit"].ToString());
  823. cel16.CellStyle = cellStylebt1;
  824. break;
  825. case 9:
  826. ICell cel17 = irow4.CreateCell(i);
  827. cel17.SetCellValue(dr["F_Satisfaction"].ToString());
  828. cel17.CellStyle = cellStylebt1;
  829. break;
  830. case 10:
  831. ICell cel6 = irow4.CreateCell(i);
  832. cel6.SetCellValue(dr["F_Satisfied"].ToString());
  833. cel6.CellStyle = cellStylebt1;
  834. break;
  835. case 11:
  836. ICell cel7 = irow4.CreateCell(i);
  837. cel7.SetCellValue(dr["F_knowledge"].ToString());
  838. cel7.CellStyle = cellStylebt1;
  839. break;
  840. case 12:
  841. ICell cel10 = irow4.CreateCell(i);
  842. cel10.SetCellValue(dr["F_Integration"].ToString());
  843. cel10.CellStyle = cellStylebt1;
  844. break;
  845. case 13:
  846. ICell cel8 = irow4.CreateCell(i);
  847. cel8.SetCellValue(dr["F_Buckle"].ToString());
  848. cel8.CellStyle = cellStylebt1;
  849. break;
  850. case 14:
  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 ExportPerformance(DataTable dt, DataTable dt1, DataTable dt2, string message)
  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. cellStyle.VerticalAlignment = VerticalAlignment.Center;
  877. cellStyle.Alignment = HorizontalAlignment.Center;
  878. ICellStyle cellStylebt1 = workbook.CreateCellStyle();
  879. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  880. cellfontbt.Boldweight = (short)FontBoldWeight.Bold;
  881. cellStylebt1.SetFont(cellfontbt);
  882. cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
  883. cellStylebt1.Alignment = HorizontalAlignment.Center;
  884. IRow headerRow = sheet.CreateRow(0);
  885. int icolIndex = 0;
  886. foreach (DataColumn dc in dt.Columns)
  887. {
  888. ICell cell = headerRow.CreateCell(icolIndex);
  889. cell.SetCellValue(dc.ColumnName);
  890. cell.CellStyle = cellStylebt1;
  891. icolIndex++;
  892. }
  893. ICellStyle cellStylebt = workbook.CreateCellStyle();
  894. NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
  895. cellfontbt1.Boldweight = (short)FontBoldWeight.Bold;
  896. cellStylebt.SetFont(cellfontbt1);
  897. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  898. cellStylebt.Alignment = HorizontalAlignment.Center;
  899. //为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
  900. cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
  901. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  902. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  903. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  904. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  905. cellStyle.SetFont(cellfont);
  906. //建立内容行
  907. int iRowIndex = 0;
  908. iRowIndex++;
  909. IRow irow01 = sheet.CreateRow(iRowIndex);
  910. ICell cell01 = irow01.CreateCell(0);
  911. cell01.SetCellValue("一、县区");
  912. cell01.CellStyle = cellStylebt;
  913. irow01.Height = 20 * 20;
  914. sheet.AddMergedRegion(new CellRangeAddress(iRowIndex , iRowIndex , 0, icolIndex-1));
  915. foreach (DataRow dr in dt.Rows)
  916. {
  917. int iCellIndex = 0;
  918. IRow irow = sheet.CreateRow(iRowIndex + 1);
  919. for (int i = 0; i < icolIndex; i++)
  920. {
  921. string strsj = string.Empty;
  922. if (dr[i] != null)
  923. {
  924. strsj = dr[i].ToString();
  925. }
  926. ICell cell = irow.CreateCell(iCellIndex);
  927. cell.SetCellValue(strsj);
  928. cell.CellStyle = cellStyle;
  929. iCellIndex++;
  930. }
  931. iRowIndex++;
  932. }
  933. iRowIndex ++;
  934. IRow irow02 = sheet.CreateRow(iRowIndex);
  935. ICell cell02 = irow02.CreateCell(0);
  936. cell02.SetCellValue("二、市直单位");
  937. cell02.CellStyle = cellStylebt;
  938. irow02.Height = 20 * 20;
  939. sheet.AddMergedRegion(new CellRangeAddress(iRowIndex , iRowIndex , 0, icolIndex - 1));
  940. foreach (DataRow dr in dt1.Rows)
  941. {
  942. int iCellIndex = 0;
  943. IRow irow = sheet.CreateRow(iRowIndex + 1);
  944. for (int i = 0; i < icolIndex; i++)
  945. {
  946. string strsj = string.Empty;
  947. if (dr[i] != null)
  948. {
  949. strsj = dr[i].ToString();
  950. }
  951. ICell cell = irow.CreateCell(iCellIndex);
  952. cell.SetCellValue(strsj);
  953. cell.CellStyle = cellStyle;
  954. iCellIndex++;
  955. }
  956. iRowIndex++;
  957. }
  958. iRowIndex++;
  959. IRow irow03 = sheet.CreateRow(iRowIndex);
  960. ICell cell03 = irow03.CreateCell(0);
  961. cell03.SetCellValue("三、公共服务企业");
  962. cell03.CellStyle = cellStylebt;
  963. irow03.Height = 20 * 20;
  964. sheet.AddMergedRegion(new CellRangeAddress(iRowIndex , iRowIndex, 0, icolIndex - 1));
  965. foreach (DataRow dr in dt2.Rows)
  966. {
  967. int iCellIndex = 0;
  968. IRow irow = sheet.CreateRow(iRowIndex + 1);
  969. for (int i = 0; i < icolIndex; i++)
  970. {
  971. string strsj = string.Empty;
  972. if (dr[i] != null)
  973. {
  974. strsj = dr[i].ToString();
  975. }
  976. ICell cell = irow.CreateCell(iCellIndex);
  977. cell.SetCellValue(strsj);
  978. cell.CellStyle = cellStyle;
  979. iCellIndex++;
  980. }
  981. iRowIndex++;
  982. }
  983. //自适应列宽度
  984. for (int i = 0; i < icolIndex; i++)
  985. {
  986. // sheet.AutoSizeColumn(i);
  987. if (i == 0)
  988. sheet.SetColumnWidth(i, 28 * 256);
  989. else
  990. sheet.SetColumnWidth(i, 15 * 256);
  991. }
  992. using (MemoryStream ms = new MemoryStream())
  993. {
  994. workbook.Write(ms);
  995. HttpContext curContext = HttpContext.Current;
  996. // 设置编码和附件格式
  997. curContext.Response.ContentType = "application/vnd.ms-excel";
  998. curContext.Response.ContentEncoding = Encoding.UTF8;
  999. curContext.Response.Charset = "";
  1000. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  1001. curContext.Response.AppendHeader("Content-Disposition",
  1002. "attachment;filename=" + HttpUtility.UrlEncode("月度评价报表" + ".xls", Encoding.UTF8));
  1003. curContext.Response.BinaryWrite(ms.GetBuffer());
  1004. workbook = null;
  1005. ms.Close();
  1006. ms.Dispose();
  1007. curContext.Response.End();
  1008. }
  1009. return "";
  1010. }
  1011. catch
  1012. {
  1013. return "导出失败!";
  1014. }
  1015. }
  1016. /// <summary>
  1017. /// 督办数据报表导出
  1018. /// </summary>
  1019. /// <param name="ds"></param>
  1020. /// <returns></returns>
  1021. public string ExportEvaluation(DataTable dt, DataTable dt1, DataTable dt2, DataTable dt3, string message,string data)
  1022. {
  1023. try
  1024. {
  1025. HSSFWorkbook workbook = new HSSFWorkbook();
  1026. ISheet sheet = workbook.CreateSheet("月度评价报表");
  1027. ICellStyle cellStyle = workbook.CreateCellStyle();
  1028. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  1029. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  1030. cellStyle.SetFont(cellfont);
  1031. ICellStyle cellStylebt = workbook.CreateCellStyle();
  1032. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  1033. cellfontbt.Boldweight = (short)FontBoldWeight.Bold;
  1034. cellStylebt.SetFont(cellfontbt);
  1035. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  1036. cellStylebt.Alignment = HorizontalAlignment.Center;
  1037. IRow irow0 = sheet.CreateRow(0);
  1038. ICell cell0 = irow0.CreateCell(0);
  1039. cell0.SetCellValue(data+"月份市长热线承办单位办理情况统计表");
  1040. cell0.CellStyle = cellStylebt;
  1041. irow0.Height = 50 * 20;
  1042. sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 14));
  1043. IRow irow00 = sheet.CreateRow(1);
  1044. ICell cell00 = irow00.CreateCell(0);
  1045. cell00.SetCellValue(message);
  1046. cell00.CellStyle = cellStylebt;
  1047. irow00.Height = 40 * 20;
  1048. sheet.AddMergedRegion(new CellRangeAddress(1, 1, 0, 14));
  1049. int index1 = Evaluation("一、县区", dt, 2, sheet, cellStylebt, workbook);
  1050. int index2 = Evaluation("二、市直单位", dt1, index1+1, sheet, cellStylebt, workbook);
  1051. int index3 = Evaluation("三、公共服务企业", dt2, index2+1, sheet, cellStylebt, workbook);
  1052. int index4 = Evaluation("四、未办件单位", dt3, index3 + 1, sheet, cellStylebt, workbook);
  1053. //自适应列宽度
  1054. for (int i = 0; i < 14; i++)
  1055. {
  1056. // sheet.AutoSizeColumn(i);
  1057. if (i ==1)
  1058. sheet.SetColumnWidth(i, 28 * 256);
  1059. else
  1060. sheet.SetColumnWidth(i, 15 * 256);
  1061. }
  1062. using (MemoryStream ms = new MemoryStream())
  1063. {
  1064. workbook.Write(ms);
  1065. HttpContext curContext = HttpContext.Current;
  1066. // 设置编码和附件格式
  1067. curContext.Response.ContentType = "application/vnd.ms-excel";
  1068. curContext.Response.ContentEncoding = Encoding.UTF8;
  1069. curContext.Response.Charset = "";
  1070. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  1071. curContext.Response.AppendHeader("Content-Disposition",
  1072. "attachment;filename=" + HttpUtility.UrlEncode("月度评价报表" + ".xls", Encoding.UTF8));
  1073. curContext.Response.BinaryWrite(ms.GetBuffer());
  1074. workbook = null;
  1075. ms.Close();
  1076. ms.Dispose();
  1077. curContext.Response.End();
  1078. }
  1079. return "";
  1080. }
  1081. catch
  1082. {
  1083. return "导出失败!";
  1084. }
  1085. }
  1086. /// <summary>
  1087. /// 督办数据报表导出
  1088. /// </summary>
  1089. /// <param name="ds"></param>
  1090. /// <returns></returns>
  1091. public string DBExportToExcel(DataTable dt,string Name,string month,string starttime ,string endtime )
  1092. {
  1093. try
  1094. {
  1095. HSSFWorkbook workbook = new HSSFWorkbook();
  1096. ISheet sheet = workbook.CreateSheet(Name);
  1097. ICellStyle cellStyle = workbook.CreateCellStyle();
  1098. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  1099. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  1100. cellStyle.SetFont(cellfont);
  1101. ICellStyle cellStylebt = workbook.CreateCellStyle();
  1102. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  1103. cellfontbt.Boldweight = (short)FontBoldWeight.Bold;
  1104. cellStylebt.SetFont(cellfontbt);
  1105. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  1106. cellStylebt.Alignment = HorizontalAlignment.Center;
  1107. IRow irow1 = sheet.CreateRow(0);
  1108. ICell cell1 = irow1.CreateCell(0);
  1109. cell1.SetCellValue("12345联动服务工作"+ month + "月份办理情况通报表");
  1110. cell1.CellStyle = cellStylebt;
  1111. sheet.AddMergedRegion(new CellRangeAddress(0, 1, 0, 19));
  1112. IRow irow2 = sheet.CreateRow(2);
  1113. ICell cell2 = irow2.CreateCell(0);
  1114. cell2.SetCellValue("统计周期:"+ starttime+"至"+ endtime+" 统计时间:"+DateTime .Now.ToString ("yyyy年MM月dd日"));
  1115. cell2.CellStyle = cellStylebt;
  1116. sheet.AddMergedRegion(new CellRangeAddress(2, 2, 0, 19));
  1117. IRow irow3 = sheet.CreateRow(3);
  1118. ICell cell3 = irow3.CreateCell(0);
  1119. cell3.SetCellValue("一、县(市、区)联动单位");
  1120. cell3.CellStyle = cellStylebt;
  1121. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 0, 19));
  1122. string[] cols = {"序号","联动单位","承办件",
  1123. "承办率","得分(5分)","超期件","按时反馈率","得分(20分)",
  1124. "未果件","办结率","得分(10分)","退单件","有效回复率",
  1125. "得分(15分)","群众评议总数","一次不满意件","二次不满意件","不满意件","满意率","得分(50分)","总分","排名"};
  1126. IRow irow4 = sheet.CreateRow(4);
  1127. int icolIndex = 0;
  1128. foreach (string dc in cols)
  1129. {
  1130. ICell cell = irow4.CreateCell(icolIndex);
  1131. cell.SetCellValue(dc);
  1132. cell.CellStyle = cellStylebt;
  1133. icolIndex++;
  1134. }
  1135. int iRowIndex = 5;
  1136. DataRow[] rows = dt.Select("category=1");
  1137. int index = 0;
  1138. foreach (DataRow dr in rows)
  1139. {
  1140. index++;
  1141. int iCellIndex = 0;
  1142. IRow irow = sheet.CreateRow(iRowIndex );
  1143. for (int i = 0; i < 22; i++)
  1144. {
  1145. ICell cell = irow.CreateCell(iCellIndex);
  1146. cell.SetCellValue(GetCellValue(dr, index,i ));
  1147. cell.CellStyle = cellStyle;
  1148. iCellIndex++;
  1149. }
  1150. iRowIndex++;
  1151. }
  1152. IRow irow5 = sheet.CreateRow(iRowIndex);
  1153. ICell cell5 = irow5.CreateCell(0);
  1154. cell5.SetCellValue("二、市直机关联动单位一组");
  1155. cell5.CellStyle = cellStylebt;
  1156. sheet.AddMergedRegion(new CellRangeAddress(iRowIndex, iRowIndex, 0, 19));
  1157. iRowIndex++;
  1158. IRow irow6 = sheet.CreateRow(iRowIndex);
  1159. icolIndex = 0;
  1160. foreach (string dc in cols)
  1161. {
  1162. ICell cell = irow6.CreateCell(icolIndex);
  1163. cell.SetCellValue(dc);
  1164. cell.CellStyle = cellStylebt;
  1165. icolIndex++;
  1166. }
  1167. iRowIndex++;
  1168. rows = dt.Select("category=2");
  1169. index = 0;
  1170. foreach (DataRow dr in rows)
  1171. {
  1172. index++;
  1173. int iCellIndex = 0;
  1174. IRow irow = sheet.CreateRow(iRowIndex);
  1175. for (int i = 0; i < 22; i++)
  1176. {
  1177. ICell cell = irow.CreateCell(iCellIndex);
  1178. cell.SetCellValue(GetCellValue(dr, index,i ));
  1179. cell.CellStyle = cellStyle;
  1180. iCellIndex++;
  1181. }
  1182. iRowIndex++;
  1183. }
  1184. IRow irow7 = sheet.CreateRow(iRowIndex);
  1185. ICell cell7 = irow7.CreateCell(0);
  1186. cell7.SetCellValue("三、市直机关联动单位二组");
  1187. cell7.CellStyle = cellStylebt;
  1188. sheet.AddMergedRegion(new CellRangeAddress(iRowIndex, iRowIndex, 0, 19));
  1189. iRowIndex++;
  1190. IRow irow8 = sheet.CreateRow(iRowIndex);
  1191. icolIndex = 0;
  1192. foreach (string dc in cols)
  1193. {
  1194. ICell cell = irow8.CreateCell(icolIndex);
  1195. cell.SetCellValue(dc);
  1196. cell.CellStyle = cellStylebt;
  1197. icolIndex++;
  1198. }
  1199. iRowIndex++;
  1200. rows = dt.Select("category=3");
  1201. index = 0;
  1202. foreach (DataRow dr in rows)
  1203. {
  1204. index++;
  1205. int iCellIndex = 0;
  1206. IRow irow = sheet.CreateRow(iRowIndex);
  1207. for (int i = 0; i < 22; i++)
  1208. {
  1209. ICell cell = irow.CreateCell(iCellIndex);
  1210. cell.SetCellValue(GetCellValue(dr, index,i ));
  1211. cell.CellStyle = cellStyle;
  1212. iCellIndex++;
  1213. }
  1214. iRowIndex++;
  1215. }
  1216. IRow irow9 = sheet.CreateRow(iRowIndex);
  1217. ICell cell9 = irow9.CreateCell(0);
  1218. cell9.SetCellValue("四、公益型企业联动单位");
  1219. cell9.CellStyle = cellStylebt;
  1220. sheet.AddMergedRegion(new CellRangeAddress(iRowIndex, iRowIndex, 0, 19));
  1221. iRowIndex++;
  1222. IRow irow10 = sheet.CreateRow(iRowIndex);
  1223. icolIndex = 0;
  1224. foreach (string dc in cols)
  1225. {
  1226. ICell cell = irow10.CreateCell(icolIndex);
  1227. cell.SetCellValue(dc);
  1228. cell.CellStyle = cellStylebt;
  1229. icolIndex++;
  1230. }
  1231. iRowIndex++;
  1232. rows = dt.Select("category=4");
  1233. index = 0;
  1234. foreach (DataRow dr in rows)
  1235. {
  1236. index++;
  1237. int iCellIndex = 0;
  1238. IRow irow = sheet.CreateRow(iRowIndex);
  1239. for (int i = 0; i < 22; i++)
  1240. {
  1241. ICell cell = irow.CreateCell(iCellIndex);
  1242. cell.SetCellValue(GetCellValue(dr, index,i ));
  1243. cell.CellStyle = cellStyle;
  1244. iCellIndex++;
  1245. }
  1246. iRowIndex++;
  1247. }
  1248. //自适应列宽度
  1249. for (int i = 0; i < 20; i++)
  1250. {
  1251. sheet.AutoSizeColumn(i);
  1252. // sheet.SetColumnWidth(i, 20 * 256);
  1253. }
  1254. using (MemoryStream ms = new MemoryStream())
  1255. {
  1256. workbook.Write(ms);
  1257. HttpContext curContext = HttpContext.Current;
  1258. // 设置编码和附件格式
  1259. curContext.Response.ContentType = "application/vnd.ms-excel";
  1260. curContext.Response.ContentEncoding = Encoding.UTF8;
  1261. curContext.Response.Charset = "";
  1262. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  1263. curContext.Response.AppendHeader("Content-Disposition",
  1264. "attachment;filename=" + HttpUtility.UrlEncode(Name + ".xls", Encoding.UTF8));
  1265. curContext.Response.BinaryWrite(ms.GetBuffer());
  1266. workbook = null;
  1267. ms.Close();
  1268. ms.Dispose();
  1269. curContext.Response.End();
  1270. }
  1271. return "";
  1272. }
  1273. catch
  1274. {
  1275. return "导出失败!";
  1276. }
  1277. }
  1278. /// <summary>
  1279. /// 督办数据报表导出
  1280. /// </summary>
  1281. /// <param name="ds"></param>
  1282. /// <returns></returns>
  1283. public string DBEJExportToExcel(DataTable dt, string Name, string month, string starttime, string endtime)
  1284. {
  1285. try
  1286. {
  1287. HSSFWorkbook workbook = new HSSFWorkbook();
  1288. ISheet sheet = workbook.CreateSheet(Name);
  1289. ICellStyle cellStyle = workbook.CreateCellStyle();
  1290. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  1291. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  1292. cellStyle.SetFont(cellfont);
  1293. ICellStyle cellStylebt = workbook.CreateCellStyle();
  1294. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  1295. cellfontbt.Boldweight = (short)FontBoldWeight.Bold;
  1296. cellStylebt.SetFont(cellfontbt);
  1297. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  1298. cellStylebt.Alignment = HorizontalAlignment.Center;
  1299. IRow irow1 = sheet.CreateRow(0);
  1300. ICell cell1 = irow1.CreateCell(0);
  1301. cell1.SetCellValue("12345联动服务工作" + month + "月份办理情况通报表");
  1302. cell1.CellStyle = cellStylebt;
  1303. sheet.AddMergedRegion(new CellRangeAddress(0, 1, 0, 19));
  1304. IRow irow2 = sheet.CreateRow(2);
  1305. ICell cell2 = irow2.CreateCell(0);
  1306. cell2.SetCellValue("统计周期:" + starttime + "至" + endtime + " 统计时间:" + DateTime.Now.ToString("yyyy年MM月dd日"));
  1307. cell2.CellStyle = cellStylebt;
  1308. sheet.AddMergedRegion(new CellRangeAddress(2, 2, 0, 19));
  1309. IRow irow3 = sheet.CreateRow(3);
  1310. ICell cell3 = irow3.CreateCell(0);
  1311. cell3.SetCellValue("一、县(市、区)联动单位");
  1312. cell3.CellStyle = cellStylebt;
  1313. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 0, 19));
  1314. string[] cols = {"序号","联动单位","承办件",
  1315. "承办率","得分(5分)","超期件","按时反馈率","得分(20分)",
  1316. "未果件","办结率","得分(10分)","退单件","有效回复率",
  1317. "得分(15分)","群众评议总数","一次不满意件","不满意件","满意率","得分(50分)","总分","排名"};
  1318. IRow irow4 = sheet.CreateRow(4);
  1319. int icolIndex = 0;
  1320. foreach (string dc in cols)
  1321. {
  1322. ICell cell = irow4.CreateCell(icolIndex);
  1323. cell.SetCellValue(dc);
  1324. cell.CellStyle = cellStylebt;
  1325. icolIndex++;
  1326. }
  1327. int iRowIndex = 5;
  1328. // DataRow[] rows = dt.Select("category=1");
  1329. int index = 0;
  1330. foreach (DataRow dr in dt.Rows )
  1331. {
  1332. index++;
  1333. int iCellIndex = 0;
  1334. IRow irow = sheet.CreateRow(iRowIndex);
  1335. for (int i = 0; i < 21; i++)
  1336. {
  1337. ICell cell = irow.CreateCell(iCellIndex);
  1338. cell.SetCellValue(GetCellValue(dr, index, i));
  1339. cell.CellStyle = cellStyle;
  1340. iCellIndex++;
  1341. }
  1342. iRowIndex++;
  1343. }
  1344. //自适应列宽度
  1345. for (int i = 0; i < 20; i++)
  1346. {
  1347. sheet.AutoSizeColumn(i);
  1348. // sheet.SetColumnWidth(i, 20 * 256);
  1349. }
  1350. using (MemoryStream ms = new MemoryStream())
  1351. {
  1352. workbook.Write(ms);
  1353. HttpContext curContext = HttpContext.Current;
  1354. // 设置编码和附件格式
  1355. curContext.Response.ContentType = "application/vnd.ms-excel";
  1356. curContext.Response.ContentEncoding = Encoding.UTF8;
  1357. curContext.Response.Charset = "";
  1358. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  1359. curContext.Response.AppendHeader("Content-Disposition",
  1360. "attachment;filename=" + HttpUtility.UrlEncode(Name + ".xls", Encoding.UTF8));
  1361. curContext.Response.BinaryWrite(ms.GetBuffer());
  1362. workbook = null;
  1363. ms.Close();
  1364. ms.Dispose();
  1365. curContext.Response.End();
  1366. }
  1367. return "";
  1368. }
  1369. catch
  1370. {
  1371. return "导出失败!";
  1372. }
  1373. }
  1374. //
  1375. /// <summary>
  1376. /// 督办数据报表导出
  1377. /// </summary>
  1378. /// <param name="ds"></param>
  1379. /// <returns></returns>
  1380. public string ExportMergerToExcel(List<MergerHot.MergerHotSource> MergerHotSource)
  1381. {
  1382. try
  1383. {
  1384. int lenth = 0;
  1385. if (MergerHotSource!=null&& MergerHotSource.Count>0)
  1386. {
  1387. if (MergerHotSource[0]!=null && MergerHotSource[0].MergerHot !=null
  1388. && MergerHotSource[0].MergerHot.Count >0)
  1389. {
  1390. lenth = MergerHotSource[0].MergerHot.Count * 5+4;
  1391. }
  1392. else
  1393. {
  1394. return "";
  1395. }
  1396. }
  1397. else
  1398. {
  1399. return "";
  1400. }
  1401. HSSFWorkbook workbook = new HSSFWorkbook();
  1402. ISheet sheet = workbook.CreateSheet("归并热线每日数据统计");
  1403. ICellStyle cellStyle = workbook.CreateCellStyle();
  1404. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  1405. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  1406. cellStyle.SetFont(cellfont);
  1407. ICellStyle cellStylebt = workbook.CreateCellStyle();
  1408. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  1409. cellfontbt.Boldweight = (short)FontBoldWeight.Bold;
  1410. cellStylebt.SetFont(cellfontbt);
  1411. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  1412. cellStylebt.Alignment = HorizontalAlignment.Center;
  1413. cellStylebt.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1414. cellStylebt.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1415. cellStylebt.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1416. cellStylebt.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1417. IRow irow1 = sheet.CreateRow(0);
  1418. ICell cell1 = irow1.CreateCell(0);
  1419. cell1.SetCellValue("归并热线每日数据统计");
  1420. cell1.CellStyle=cellStylebt;
  1421. ICellStyle cellStylebt1 = workbook.CreateCellStyle();
  1422. NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
  1423. cellfontbt1.Boldweight = (short)FontBoldWeight.Bold;
  1424. cellfontbt1.FontHeightInPoints = 22;
  1425. cellStylebt1.SetFont(cellfontbt1);
  1426. cellStylebt1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1427. cellStylebt1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1428. cellStylebt1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1429. cellStylebt1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1430. cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
  1431. cellStylebt1.Alignment = HorizontalAlignment.Center;
  1432. cell1.CellStyle = cellStylebt1;
  1433. sheet.AddMergedRegion(new CellRangeAddress(0, 2, 0, lenth));
  1434. IRow irow2 = sheet.CreateRow(3);
  1435. int icolIndex = 0;
  1436. ICellStyle cellStylebt2 = workbook.CreateCellStyle();
  1437. NPOI.SS.UserModel.IFont cellfontbt2 = workbook.CreateFont();
  1438. cellfontbt2.Boldweight = (short)FontBoldWeight.Bold;
  1439. cellStylebt2.WrapText = true;//设置换行这个要先设置
  1440. cellfontbt2.FontHeightInPoints = 14;
  1441. cellStylebt2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1442. cellStylebt2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1443. cellStylebt2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1444. cellStylebt2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1445. cellStylebt2.SetFont(cellfontbt2);
  1446. cellStylebt2.VerticalAlignment = VerticalAlignment.Center;
  1447. cellStylebt2.Alignment = HorizontalAlignment.Center;
  1448. HSSFPalette palette = workbook.GetCustomPalette(); //调色板实例
  1449. palette.SetColorAtIndex(8, 237,237, 237);
  1450. NPOI.HSSF.Util.HSSFColor hssFColor = palette.FindColor(237, 237, 237);
  1451. cellStylebt2.FillForegroundColor = hssFColor.Indexed ;
  1452. cellStylebt2.FillPattern = FillPattern.SolidForeground;
  1453. cellStylebt2.FillBackgroundColor = hssFColor.Indexed; ;
  1454. ICellStyle cellStylebt3 = workbook.CreateCellStyle();
  1455. NPOI.SS.UserModel.IFont cellfontbt3 = workbook.CreateFont();
  1456. cellfontbt3.Boldweight = (short)FontBoldWeight.Bold;
  1457. cellStylebt3.WrapText = true;//设置换行这个要先设置
  1458. cellfontbt3.FontHeightInPoints = 14;
  1459. cellStylebt3.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1460. cellStylebt3.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1461. cellStylebt3.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1462. cellStylebt3.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1463. cellStylebt3.SetFont(cellfontbt3);
  1464. cellStylebt3.VerticalAlignment = VerticalAlignment.Center;
  1465. cellStylebt3.Alignment = HorizontalAlignment.Center;
  1466. HSSFPalette palette1 = workbook.GetCustomPalette(); //调色板实例
  1467. palette1.SetColorAtIndex(9, 221,235,247);
  1468. NPOI.HSSF.Util.HSSFColor hssFColor1 = palette1.FindColor(221, 235, 247);
  1469. cellStylebt3.FillForegroundColor = hssFColor1.Indexed ;
  1470. cellStylebt3.FillPattern = FillPattern.SolidForeground;
  1471. cellStylebt3.FillBackgroundColor = hssFColor1.Indexed;
  1472. ICellStyle cellStylebt4 = workbook.CreateCellStyle();
  1473. NPOI.SS.UserModel.IFont cellfontbt4 = workbook.CreateFont();
  1474. cellStylebt4.WrapText = true;//设置换行这个要先设置
  1475. cellfontbt4.Boldweight = (short)FontBoldWeight.Bold;
  1476. cellfontbt4.FontHeightInPoints = 11;
  1477. cellStylebt4.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1478. cellStylebt4.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1479. cellStylebt4.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1480. cellStylebt4.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1481. cellStylebt4.SetFont(cellfontbt4);
  1482. cellStylebt4.VerticalAlignment = VerticalAlignment.Center;
  1483. cellStylebt4.Alignment = HorizontalAlignment.Center;
  1484. ICellStyle cellStylebt5 = workbook.CreateCellStyle();
  1485. NPOI.SS.UserModel.IFont cellfontbt5 = workbook.CreateFont();
  1486. cellfontbt5.Boldweight = (short)FontBoldWeight.Bold;
  1487. cellfontbt5.FontHeightInPoints = 11;
  1488. cellStylebt5.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1489. cellStylebt5.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1490. cellStylebt5.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1491. cellStylebt5.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1492. cellStylebt5.WrapText = true;//设置换行这个要先设置
  1493. cellStylebt5.SetFont(cellfontbt5);
  1494. cellStylebt5.VerticalAlignment = VerticalAlignment.Center;
  1495. cellStylebt5.Alignment = HorizontalAlignment.Center;
  1496. HSSFPalette palette2 = workbook.GetCustomPalette(); //调色板实例
  1497. palette2.SetColorAtIndex(10, 226, 239, 218);
  1498. NPOI.HSSF.Util.HSSFColor hssFColor2 = palette2.FindColor(226, 239, 218);
  1499. cellStylebt5.FillForegroundColor = hssFColor2.Indexed ;
  1500. cellStylebt5.FillPattern = FillPattern.SolidForeground;
  1501. cellStylebt5.FillBackgroundColor = hssFColor2.Indexed;
  1502. ICellStyle cellStylebt8 = workbook.CreateCellStyle();
  1503. NPOI.SS.UserModel.IFont cellfontbt8 = workbook.CreateFont();
  1504. cellfontbt8.FontHeightInPoints = 10;
  1505. cellStylebt8.SetFont(cellfontbt8);
  1506. cellStylebt8.WrapText = true;//设置换行这个要先设置
  1507. cellStylebt8.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1508. cellStylebt8.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1509. cellStylebt8.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1510. cellStylebt8.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1511. cellStylebt8.VerticalAlignment = VerticalAlignment.Center;
  1512. cellStylebt8.Alignment = HorizontalAlignment.Center;
  1513. HSSFPalette palette3 = workbook.GetCustomPalette(); //调色板实例
  1514. palette3.SetColorAtIndex(11, 198, 224, 180);
  1515. NPOI.HSSF.Util.HSSFColor hssFColor3 = palette3.FindColor(198, 224, 180);
  1516. cellStylebt8.FillForegroundColor = hssFColor3.Indexed ;
  1517. cellStylebt8.FillPattern = FillPattern.SolidForeground;
  1518. cellStylebt8.FillBackgroundColor = hssFColor3.Indexed;
  1519. ICellStyle cellStylebt9 = workbook.CreateCellStyle();
  1520. NPOI.SS.UserModel.IFont cellfontbt9 = workbook.CreateFont();
  1521. cellfontbt9.FontHeightInPoints = 11;
  1522. cellfontbt9.Boldweight = (short)FontBoldWeight.Bold;
  1523. cellStylebt9.SetFont(cellfontbt9);
  1524. cellStylebt9.WrapText = true;//设置换行这个要先设置
  1525. cellStylebt9.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1526. cellStylebt9.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1527. cellStylebt9.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1528. cellStylebt9.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1529. cellStylebt9.VerticalAlignment = VerticalAlignment.Center;
  1530. cellStylebt9.Alignment = HorizontalAlignment.Center;
  1531. HSSFPalette palette4 = workbook.GetCustomPalette(); //调色板实例
  1532. palette4.SetColorAtIndex(12, 255, 242, 204);
  1533. NPOI.HSSF.Util.HSSFColor hssFColor4 = palette4.FindColor(255, 242, 204);
  1534. cellStylebt9.FillForegroundColor = hssFColor4.Indexed ; ;
  1535. cellStylebt9.FillPattern = FillPattern.SolidForeground;
  1536. cellStylebt9.FillBackgroundColor = hssFColor4.Indexed; ; ;
  1537. ICellStyle cellStylebt10 = workbook.CreateCellStyle();
  1538. NPOI.SS.UserModel.IFont cellfontbt10 = workbook.CreateFont();
  1539. cellfontbt10.Boldweight = (short)FontBoldWeight.Bold;
  1540. cellfontbt10.FontHeightInPoints = 11;
  1541. cellStylebt10.WrapText = true;//设置换行这个要先设置
  1542. cellStylebt10.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1543. cellStylebt10.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1544. cellStylebt10.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1545. cellStylebt10.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1546. cellStylebt10.SetFont(cellfontbt10);
  1547. cellStylebt10.VerticalAlignment = VerticalAlignment.Center;
  1548. cellStylebt10.Alignment = HorizontalAlignment.Center;
  1549. HSSFPalette palette5 = workbook.GetCustomPalette(); //调色板实例
  1550. palette5.SetColorAtIndex(13, 217, 225, 242);
  1551. NPOI.HSSF.Util.HSSFColor hssFColor5 = palette5.FindColor(217, 225, 242);
  1552. cellStylebt10.FillForegroundColor = hssFColor5.Indexed ;
  1553. cellStylebt10.FillPattern = FillPattern.SolidForeground;
  1554. cellStylebt10.FillBackgroundColor = hssFColor5.Indexed; ;
  1555. ICellStyle cellStylebt6 = workbook.CreateCellStyle();
  1556. NPOI.SS.UserModel.IFont cellfontbt6 = workbook.CreateFont();
  1557. cellfontbt6.Boldweight = (short)FontBoldWeight.Bold;
  1558. cellStylebt6.WrapText = true;//设置换行这个要先设置
  1559. cellfontbt6.FontHeightInPoints = 10;
  1560. cellStylebt6.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1561. cellStylebt6.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1562. cellStylebt6.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1563. cellStylebt6.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1564. cellStylebt6.SetFont(cellfontbt6);
  1565. cellStylebt6.VerticalAlignment = VerticalAlignment.Center;
  1566. cellStylebt6.Alignment = HorizontalAlignment.Center;
  1567. cellStylebt6.FillForegroundColor = hssFColor.Indexed ;
  1568. cellStylebt6.FillPattern = FillPattern.SolidForeground;
  1569. cellStylebt6.FillBackgroundColor = hssFColor.Indexed; ;
  1570. ICellStyle cellStylebt11 = workbook.CreateCellStyle();
  1571. NPOI.SS.UserModel.IFont cellfontbt11 = workbook.CreateFont();
  1572. cellfontbt11.FontHeightInPoints = 10;
  1573. cellStylebt11.WrapText = true;//设置换行这个要先设置
  1574. cellStylebt11.SetFont(cellfontbt11);
  1575. cellStylebt11.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1576. cellStylebt11.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1577. cellStylebt11.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1578. cellStylebt11.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1579. cellStylebt11.VerticalAlignment = VerticalAlignment.Center;
  1580. cellStylebt11.Alignment = HorizontalAlignment.Center;
  1581. ICellStyle cellStylebt12 = workbook.CreateCellStyle();
  1582. NPOI.SS.UserModel.IFont cellfontbt12 = workbook.CreateFont();
  1583. cellfontbt12.Boldweight = (short)FontBoldWeight.Bold;
  1584. cellfontbt12.FontHeightInPoints = 10;
  1585. cellStylebt12.WrapText = true;//设置换行这个要先设置
  1586. cellStylebt12.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1587. cellStylebt12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1588. cellStylebt12.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1589. cellStylebt12.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1590. cellStylebt12.SetFont(cellfontbt12);
  1591. cellStylebt12.VerticalAlignment = VerticalAlignment.Center;
  1592. cellStylebt12.Alignment = HorizontalAlignment.Center;
  1593. cellStylebt12.FillForegroundColor = hssFColor5.Indexed;
  1594. cellStylebt12.FillPattern = FillPattern.SolidForeground;
  1595. cellStylebt12.FillBackgroundColor = hssFColor5.Indexed; ;
  1596. ICellStyle cellStylebt13 = workbook.CreateCellStyle();
  1597. NPOI.SS.UserModel.IFont cellfontbt13 = workbook.CreateFont();
  1598. cellfontbt13.Boldweight = (short)FontBoldWeight.Bold;
  1599. cellStylebt13.WrapText = true;//设置换行这个要先设置
  1600. cellfontbt13.FontHeightInPoints = 11;
  1601. cellStylebt13.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1602. cellStylebt13.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1603. cellStylebt13.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1604. cellStylebt13.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1605. cellStylebt13.SetFont(cellfontbt13);
  1606. cellStylebt13.VerticalAlignment = VerticalAlignment.Center;
  1607. cellStylebt13.Alignment = HorizontalAlignment.Center;
  1608. cellStylebt13.FillForegroundColor = hssFColor.Indexed;
  1609. cellStylebt13.FillPattern = FillPattern.SolidForeground;
  1610. cellStylebt13.FillBackgroundColor = hssFColor.Indexed; ;
  1611. ICellStyle cellStylebt14 = workbook.CreateCellStyle();
  1612. NPOI.SS.UserModel.IFont cellfontbt14 = workbook.CreateFont();
  1613. cellfontbt14.FontHeightInPoints = 10;
  1614. cellStylebt14.SetFont(cellfontbt14);
  1615. cellStylebt14.WrapText = true;//设置换行这个要先设置
  1616. cellStylebt14.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1617. cellStylebt14.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1618. cellStylebt14.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1619. cellStylebt14.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1620. cellStylebt14.VerticalAlignment = VerticalAlignment.Center;
  1621. cellStylebt14.Alignment = HorizontalAlignment.Center;
  1622. cellStylebt14.FillForegroundColor = hssFColor4.Indexed; ;
  1623. cellStylebt14.FillPattern = FillPattern.SolidForeground;
  1624. cellStylebt14.FillBackgroundColor = hssFColor4.Indexed; ; ;
  1625. ICellStyle cellStylebt15 = workbook.CreateCellStyle();
  1626. NPOI.SS.UserModel.IFont cellfontbt15 = workbook.CreateFont();
  1627. cellfontbt15.Boldweight = (short)FontBoldWeight.Bold;
  1628. cellfontbt15.FontHeightInPoints = 10;
  1629. cellStylebt15.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1630. cellStylebt15.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1631. cellStylebt15.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1632. cellStylebt15.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1633. cellStylebt15.WrapText = true;//设置换行这个要先设置
  1634. cellStylebt15.SetFont(cellfontbt15);
  1635. cellStylebt15.VerticalAlignment = VerticalAlignment.Center;
  1636. cellStylebt15.Alignment = HorizontalAlignment.Center;
  1637. cellStylebt15.FillForegroundColor = hssFColor2.Indexed;
  1638. cellStylebt15.FillPattern = FillPattern.SolidForeground;
  1639. cellStylebt15.FillBackgroundColor = hssFColor2.Indexed;
  1640. int indexsource = -1;
  1641. for (int i = 0; i <= MergerHotSource[0].MergerHot.Count
  1642. ;i++)
  1643. {
  1644. if (i == 0)
  1645. {
  1646. ICell cell = irow2.CreateCell(0);
  1647. cell.SetCellValue("来源");
  1648. cell.CellStyle = cellStylebt2;
  1649. indexsource = 0;
  1650. sheet.SetColumnWidth(0, 12 * 300);
  1651. }
  1652. else if (i >0&&i <= MergerHotSource[0].MergerHot.Count-4)
  1653. {
  1654. ICell cell = irow2.CreateCell(indexsource+1);
  1655. cell.SetCellValue(MergerHotSource[0].MergerHot[i - 1].Source);
  1656. cell.CellStyle = cellStylebt2;
  1657. if (i ==1 )
  1658. {
  1659. indexsource = 6;
  1660. for (int z = 2; z <= indexsource - 1; z++)
  1661. {
  1662. ICell cell4 = irow2.CreateCell(z);
  1663. cell4.CellStyle = cellStylebt2;
  1664. }
  1665. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 1, indexsource - 1));
  1666. }
  1667. else
  1668. {
  1669. for (int z = indexsource + 2; z <= indexsource + 5; z++)
  1670. {
  1671. ICell cell4 = irow2.CreateCell(z);
  1672. cell4.CellStyle = cellStylebt2;
  1673. }
  1674. sheet.AddMergedRegion(new CellRangeAddress(3, 3, indexsource + 1, indexsource + 5));
  1675. indexsource += 6;
  1676. }
  1677. }
  1678. else
  1679. {
  1680. ICell cell = irow2.CreateCell(indexsource + 1);
  1681. cell.SetCellValue(MergerHotSource[0].MergerHot[i - 1].Source);
  1682. if (i == MergerHotSource[0].MergerHot.Count - 3)
  1683. {
  1684. for (int z = indexsource + 2; z <= indexsource + 6; z++)
  1685. {
  1686. ICell cell4 = irow2.CreateCell(z);
  1687. cell4.CellStyle = cellStylebt2;
  1688. }
  1689. sheet.AddMergedRegion(new CellRangeAddress(3, 3, indexsource + 1, indexsource + 6));
  1690. cell.CellStyle = cellStylebt3;
  1691. indexsource += 7;
  1692. }
  1693. else
  1694. {
  1695. for (int z = indexsource + 2; z <= indexsource + 5; z++)
  1696. {
  1697. ICell cell4 = irow2.CreateCell(z);
  1698. cell4.CellStyle = cellStylebt2;
  1699. }
  1700. sheet.AddMergedRegion(new CellRangeAddress(3, 3, indexsource + 1, indexsource + 5));
  1701. cell.CellStyle = cellStylebt3;
  1702. indexsource += 6;
  1703. }
  1704. }
  1705. }
  1706. IRow irow3 = sheet.CreateRow(4);
  1707. indexsource = 0;
  1708. sheet.CreateRow(4).Height = 200 * 8;
  1709. for (int i = 0; i <= MergerHotSource[0].MergerHot.Count; i++)
  1710. {
  1711. if (i == 0)
  1712. {
  1713. ICell cell = irow3.CreateCell(0);
  1714. cell.SetCellValue("日期");
  1715. cell.CellStyle = cellStylebt4;
  1716. }
  1717. else if (i > 0 && i <= MergerHotSource[0].MergerHot.Count - 4)
  1718. {
  1719. for (int j = 0; j < 5; j++)
  1720. {
  1721. indexsource += 1;
  1722. ICell cell = irow3.CreateCell(indexsource);
  1723. switch (j)
  1724. {
  1725. case 0:
  1726. cell.SetCellValue("来\n电\n量\n");
  1727. cell.CellStyle = cellStylebt5;
  1728. sheet.AutoSizeColumn(indexsource);
  1729. //sheet.SetColumnWidth(indexsource, 12 * 150);
  1730. break;
  1731. case 1:
  1732. cell.SetCellValue("接\n通\n量\n");
  1733. cell.CellStyle = cellStylebt9;
  1734. sheet.AutoSizeColumn(indexsource);
  1735. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1736. break;
  1737. case 2:
  1738. cell.SetCellValue("未\n接\n通\n");
  1739. cell.CellStyle = cellStylebt4;
  1740. sheet.AutoSizeColumn(indexsource);
  1741. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1742. break;
  1743. case 3:
  1744. cell.SetCellValue("主\n动\n放\n弃\n");
  1745. cell.CellStyle = cellStylebt4;
  1746. sheet.AutoSizeColumn(indexsource);
  1747. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1748. break;
  1749. case 4:
  1750. cell.SetCellValue("接\n通\n率");
  1751. cell.CellStyle = cellStylebt4;
  1752. sheet.AutoSizeColumn(indexsource);
  1753. break;
  1754. }
  1755. }
  1756. indexsource += 1;
  1757. sheet.SetColumnWidth(indexsource, 12 * 35);
  1758. }
  1759. else
  1760. {
  1761. if (MergerHotSource[0].MergerHot[i - 1].Source == "12345")
  1762. {
  1763. for (int j = 0; j < 5; j++)
  1764. {
  1765. indexsource += 1;
  1766. ICell cell = irow3.CreateCell(indexsource);
  1767. switch (j)
  1768. {
  1769. case 0:
  1770. cell.SetCellValue("来\n电\n量\n");
  1771. cell.CellStyle = cellStylebt5;
  1772. sheet.AutoSizeColumn(indexsource);
  1773. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1774. break;
  1775. case 1:
  1776. cell.SetCellValue("接\n通\n量\n");
  1777. cell.CellStyle = cellStylebt9;
  1778. sheet.AutoSizeColumn(indexsource);
  1779. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1780. break;
  1781. case 2:
  1782. cell.SetCellValue("接\n通\n率\n");
  1783. cell.CellStyle = cellStylebt2;
  1784. sheet.AutoSizeColumn(indexsource);
  1785. // sheet.SetColumnWidth(7, 12 * 150);
  1786. break;
  1787. case 3:
  1788. cell.SetCellValue("未\n接\n通\n");
  1789. cell.CellStyle = cellStylebt4;
  1790. sheet.AutoSizeColumn(indexsource);
  1791. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1792. break;
  1793. case 4:
  1794. cell.SetCellValue("主\n动\n放\n弃\n");
  1795. cell.CellStyle = cellStylebt4;
  1796. sheet.AutoSizeColumn(indexsource);
  1797. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1798. break;
  1799. }
  1800. }
  1801. indexsource += 1;
  1802. sheet.SetColumnWidth(indexsource, 12 * 35);
  1803. }
  1804. else if (MergerHotSource[0].MergerHot[i - 1].Source == "归并热线小计")
  1805. {
  1806. for (int j = 0; j < 6; j++)
  1807. {
  1808. indexsource += 1;
  1809. ICell cell = irow3.CreateCell(indexsource);
  1810. switch (j)
  1811. {
  1812. case 0:
  1813. cell.SetCellValue("来\n电\n量\n");
  1814. cell.CellStyle = cellStylebt5;
  1815. sheet.AutoSizeColumn(indexsource);
  1816. //sheet.SetColumnWidth(indexsource, 12 * 150);
  1817. break;
  1818. case 1:
  1819. cell.SetCellValue("接\n通\n量\n");
  1820. cell.CellStyle = cellStylebt9;
  1821. sheet.AutoSizeColumn(indexsource);
  1822. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1823. break;
  1824. case 2:
  1825. cell.SetCellValue("未\n接\n通\n");
  1826. cell.CellStyle = cellStylebt4;
  1827. sheet.AutoSizeColumn(indexsource);
  1828. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1829. break;
  1830. case 3:
  1831. cell.SetCellValue("主\n动\n放\n弃\n");
  1832. cell.CellStyle = cellStylebt4;
  1833. sheet.AutoSizeColumn(indexsource);
  1834. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1835. break;
  1836. case 4:
  1837. cell.SetCellValue("接\n通\n率\n");
  1838. cell.CellStyle = cellStylebt10;
  1839. sheet.AutoSizeColumn(indexsource);
  1840. // sheet.SetColumnWidth(indexsource, 12 * 200);
  1841. break;
  1842. case 5:
  1843. cell.SetCellValue("回\n拨\n量\n");
  1844. cell.CellStyle = cellStylebt4;
  1845. sheet.AutoSizeColumn(indexsource);
  1846. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1847. break;
  1848. }
  1849. }
  1850. indexsource += 1;
  1851. sheet.SetColumnWidth(indexsource, 12 * 35);
  1852. }
  1853. else
  1854. {
  1855. for (int j = 0; j < 5; j++)
  1856. {
  1857. indexsource += 1;
  1858. ICell cell = irow3.CreateCell(indexsource);
  1859. switch (j)
  1860. {
  1861. case 0:
  1862. cell.SetCellValue("来\n电\n量\n");
  1863. cell.CellStyle = cellStylebt5;
  1864. sheet.AutoSizeColumn(indexsource);
  1865. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1866. break;
  1867. case 1:
  1868. cell.SetCellValue("接\n通\n量\n");
  1869. cell.CellStyle = cellStylebt9;
  1870. sheet.AutoSizeColumn(indexsource);
  1871. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1872. break;
  1873. case 2:
  1874. cell.SetCellValue("未\n接\n通\n");
  1875. cell.CellStyle = cellStylebt4;
  1876. sheet.AutoSizeColumn(indexsource);
  1877. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1878. break;
  1879. case 3:
  1880. cell.SetCellValue("主\n动\n放\n弃\n");
  1881. cell.CellStyle = cellStylebt4;
  1882. sheet.AutoSizeColumn(indexsource);
  1883. // sheet.SetColumnWidth(indexsource, 12 * 150);
  1884. break;
  1885. case 4:
  1886. cell.SetCellValue("接\n通\n率\n");
  1887. cell.CellStyle = cellStylebt10;
  1888. sheet.AutoSizeColumn(indexsource);
  1889. // sheet.SetColumnWidth(indexsource, 12 * 200);
  1890. break;
  1891. }
  1892. }
  1893. indexsource += 1;
  1894. sheet.SetColumnWidth(indexsource, 12 * 35);
  1895. }
  1896. }
  1897. }
  1898. for (int i=0;i< MergerHotSource.Count; i++)
  1899. {
  1900. IRow irow4 = sheet.CreateRow(5+i );
  1901. for (int j = 0; j <= MergerHotSource[i].MergerHot.Count; j++)
  1902. {
  1903. if (j == 0)
  1904. {
  1905. ICell cell = irow4.CreateCell(0);
  1906. cell.SetCellValue(MergerHotSource[i].Data);
  1907. cell.CellStyle = cellStylebt11;
  1908. indexsource = 0;
  1909. }
  1910. else
  1911. {
  1912. if (i == MergerHotSource.Count-1)
  1913. {
  1914. if (j == 1)
  1915. {
  1916. for (int z = 0; z < 5; z++)
  1917. {
  1918. indexsource += 1;
  1919. ICell cell = irow4.CreateCell(indexsource);
  1920. switch (z)
  1921. {
  1922. case 0:
  1923. cell.SetCellValue(MergerHotSource[i]
  1924. .MergerHot[j - 1].Call);
  1925. cell.CellStyle = cellStylebt8;
  1926. break;
  1927. case 1:
  1928. cell.SetCellValue(MergerHotSource[i]
  1929. .MergerHot[j - 1].Connect);
  1930. cell.CellStyle = cellStylebt8;
  1931. break;
  1932. case 2:
  1933. cell.SetCellValue(MergerHotSource[i]
  1934. .MergerHot[j - 1].Notconnected);
  1935. cell.CellStyle = cellStylebt8;
  1936. break;
  1937. case 3:
  1938. cell.SetCellValue(MergerHotSource[i]
  1939. .MergerHot[j - 1].voluntarily);
  1940. cell.CellStyle = cellStylebt8;
  1941. break;
  1942. case 4:
  1943. cell.SetCellValue(MergerHotSource[i]
  1944. .MergerHot[j - 1].rate );
  1945. cell.CellStyle = cellStylebt8;
  1946. break;
  1947. }
  1948. }
  1949. indexsource += 1;
  1950. }
  1951. else
  1952. {
  1953. if (MergerHotSource[i].MergerHot[j - 1].Source == "12345")
  1954. {
  1955. for (int z = 0; z < 5; z++)
  1956. {
  1957. indexsource += 1;
  1958. ICell cell = irow4.CreateCell(indexsource);
  1959. switch (z)
  1960. {
  1961. case 0:
  1962. cell.SetCellValue(MergerHotSource[i]
  1963. .MergerHot[j - 1].Call);
  1964. cell.CellStyle = cellStylebt8;
  1965. break;
  1966. case 1:
  1967. cell.SetCellValue(MergerHotSource[i]
  1968. .MergerHot[j - 1].Connect);
  1969. cell.CellStyle = cellStylebt8;
  1970. break;
  1971. case 2:
  1972. cell.SetCellValue(MergerHotSource[i]
  1973. .MergerHot[j - 1].rate);
  1974. cell.CellStyle = cellStylebt8;
  1975. break;
  1976. case 3:
  1977. cell.SetCellValue(MergerHotSource[i]
  1978. .MergerHot[j - 1].Notconnected);
  1979. cell.CellStyle = cellStylebt8;
  1980. break;
  1981. case 4:
  1982. cell.SetCellValue(MergerHotSource[i]
  1983. .MergerHot[j - 1].voluntarily);
  1984. cell.CellStyle = cellStylebt8;
  1985. break;
  1986. }
  1987. }
  1988. indexsource += 1;
  1989. }
  1990. else if (MergerHotSource[i].MergerHot[j - 1].Source == "当日小计"
  1991. || MergerHotSource[i].MergerHot[j - 1].Source == "累计")
  1992. {
  1993. for (int z = 0; z < 5; z++)
  1994. {
  1995. indexsource += 1;
  1996. ICell cell = irow4.CreateCell(indexsource);
  1997. switch (z)
  1998. {
  1999. case 0:
  2000. cell.SetCellValue(MergerHotSource[i]
  2001. .MergerHot[j - 1].Call);
  2002. cell.CellStyle = cellStylebt8;
  2003. break;
  2004. case 1:
  2005. cell.SetCellValue(MergerHotSource[i]
  2006. .MergerHot[j - 1].Connect);
  2007. cell.CellStyle = cellStylebt8;
  2008. break;
  2009. case 2:
  2010. cell.SetCellValue(MergerHotSource[i]
  2011. .MergerHot[j - 1].Notconnected);
  2012. cell.CellStyle = cellStylebt8;
  2013. break;
  2014. case 3:
  2015. cell.SetCellValue(MergerHotSource[i]
  2016. .MergerHot[j - 1].voluntarily);
  2017. cell.CellStyle = cellStylebt8;
  2018. break;
  2019. case 4:
  2020. cell.SetCellValue(MergerHotSource[i]
  2021. .MergerHot[j - 1].rate);
  2022. cell.CellStyle = cellStylebt8;
  2023. break;
  2024. }
  2025. }
  2026. indexsource += 1;
  2027. }
  2028. else if (MergerHotSource[i].MergerHot[j - 1].Source == "归并热线小计"
  2029. )
  2030. {
  2031. for (int z = 0; z < 6; z++)
  2032. {
  2033. indexsource += 1;
  2034. ICell cell = irow4.CreateCell(indexsource);
  2035. switch (z)
  2036. {
  2037. case 0:
  2038. cell.SetCellValue(MergerHotSource[i]
  2039. .MergerHot[j - 1].Call);
  2040. cell.CellStyle = cellStylebt8;
  2041. break;
  2042. case 1:
  2043. cell.SetCellValue(MergerHotSource[i]
  2044. .MergerHot[j - 1].Connect);
  2045. cell.CellStyle = cellStylebt8;
  2046. break;
  2047. case 2:
  2048. cell.SetCellValue(MergerHotSource[i]
  2049. .MergerHot[j - 1].Notconnected);
  2050. cell.CellStyle = cellStylebt8;
  2051. break;
  2052. case 3:
  2053. cell.SetCellValue(MergerHotSource[i]
  2054. .MergerHot[j - 1].voluntarily);
  2055. cell.CellStyle = cellStylebt8;
  2056. break;
  2057. case 4:
  2058. cell.SetCellValue(MergerHotSource[i]
  2059. .MergerHot[j - 1].rate);
  2060. cell.CellStyle = cellStylebt8;
  2061. break;
  2062. case 5:
  2063. cell.SetCellValue(MergerHotSource[i]
  2064. .MergerHot[j - 1].callback );
  2065. cell.CellStyle = cellStylebt8;
  2066. break;
  2067. }
  2068. }
  2069. indexsource += 1;
  2070. }
  2071. else
  2072. {
  2073. for (int z = 0; z < 5; 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 = cellStylebt8;
  2083. break;
  2084. case 1:
  2085. cell.SetCellValue(MergerHotSource[i]
  2086. .MergerHot[j - 1].Connect);
  2087. cell.CellStyle = cellStylebt8;
  2088. break;
  2089. case 2:
  2090. cell.SetCellValue(MergerHotSource[i]
  2091. .MergerHot[j - 1].Notconnected);
  2092. cell.CellStyle = cellStylebt8;
  2093. break;
  2094. case 3:
  2095. cell.SetCellValue(MergerHotSource[i]
  2096. .MergerHot[j - 1].voluntarily);
  2097. cell.CellStyle = cellStylebt8;
  2098. break;
  2099. case 4:
  2100. cell.SetCellValue(MergerHotSource[i]
  2101. .MergerHot[j - 1].rate );
  2102. cell.CellStyle = cellStylebt8;
  2103. break;
  2104. }
  2105. }
  2106. indexsource += 1;
  2107. }
  2108. }
  2109. }
  2110. else
  2111. {
  2112. if (j == 1)
  2113. {
  2114. for (int z = 0; z < 5; z++)
  2115. {
  2116. indexsource += 1;
  2117. ICell cell = irow4.CreateCell(indexsource);
  2118. switch (z)
  2119. {
  2120. case 0:
  2121. cell.SetCellValue(MergerHotSource[i]
  2122. .MergerHot[j - 1].Call);
  2123. cell.CellStyle = cellStylebt15;
  2124. break;
  2125. case 1:
  2126. cell.SetCellValue(MergerHotSource[i]
  2127. .MergerHot[j - 1].Connect);
  2128. cell.CellStyle = cellStylebt14;
  2129. break;
  2130. case 2:
  2131. cell.SetCellValue(MergerHotSource[i]
  2132. .MergerHot[j - 1].Notconnected);
  2133. cell.CellStyle = cellStylebt11;
  2134. break;
  2135. case 3:
  2136. cell.SetCellValue(MergerHotSource[i]
  2137. .MergerHot[j - 1].voluntarily);
  2138. cell.CellStyle = cellStylebt11;
  2139. break;
  2140. case 4:
  2141. cell.SetCellValue(MergerHotSource[i]
  2142. .MergerHot[j - 1].rate );
  2143. cell.CellStyle = cellStylebt11;
  2144. break;
  2145. }
  2146. }
  2147. indexsource += 1;
  2148. }
  2149. else
  2150. {
  2151. if (MergerHotSource[i].MergerHot[j - 1].Source == "12345")
  2152. {
  2153. for (int z = 0; z < 5; z++)
  2154. {
  2155. indexsource += 1;
  2156. ICell cell = irow4.CreateCell(indexsource);
  2157. switch (z)
  2158. {
  2159. case 0:
  2160. cell.SetCellValue(MergerHotSource[i]
  2161. .MergerHot[j - 1].Call);
  2162. cell.CellStyle = cellStylebt15;
  2163. break;
  2164. case 1:
  2165. cell.SetCellValue(MergerHotSource[i]
  2166. .MergerHot[j - 1].Connect);
  2167. cell.CellStyle = cellStylebt14;
  2168. break;
  2169. case 2:
  2170. cell.SetCellValue(MergerHotSource[i]
  2171. .MergerHot[j - 1].rate);
  2172. cell.CellStyle = cellStylebt6;
  2173. break;
  2174. case 3:
  2175. cell.SetCellValue(MergerHotSource[i]
  2176. .MergerHot[j - 1].Notconnected);
  2177. cell.CellStyle = cellStylebt11;
  2178. break;
  2179. case 4:
  2180. cell.SetCellValue(MergerHotSource[i]
  2181. .MergerHot[j - 1].voluntarily);
  2182. cell.CellStyle = cellStylebt11;
  2183. break;
  2184. }
  2185. }
  2186. indexsource += 1;
  2187. }
  2188. else if (MergerHotSource[i].MergerHot[j - 1].Source == "当日小计"
  2189. || MergerHotSource[i].MergerHot[j - 1].Source == "累计")
  2190. {
  2191. for (int z = 0; z < 5; z++)
  2192. {
  2193. indexsource += 1;
  2194. ICell cell = irow4.CreateCell(indexsource);
  2195. switch (z)
  2196. {
  2197. case 0:
  2198. cell.SetCellValue(MergerHotSource[i]
  2199. .MergerHot[j - 1].Call);
  2200. cell.CellStyle = cellStylebt15;
  2201. break;
  2202. case 1:
  2203. cell.SetCellValue(MergerHotSource[i]
  2204. .MergerHot[j - 1].Connect);
  2205. cell.CellStyle = cellStylebt14;
  2206. break;
  2207. case 2:
  2208. cell.SetCellValue(MergerHotSource[i]
  2209. .MergerHot[j - 1].Notconnected);
  2210. cell.CellStyle = cellStylebt11;
  2211. break;
  2212. case 3:
  2213. cell.SetCellValue(MergerHotSource[i]
  2214. .MergerHot[j - 1].voluntarily);
  2215. cell.CellStyle = cellStylebt11;
  2216. break;
  2217. case 4:
  2218. cell.SetCellValue(MergerHotSource[i]
  2219. .MergerHot[j - 1].rate);
  2220. cell.CellStyle = cellStylebt12;
  2221. break;
  2222. }
  2223. }
  2224. indexsource += 1;
  2225. }
  2226. else if (MergerHotSource[i].MergerHot[j - 1].Source == "归并热线小计")
  2227. {
  2228. for (int z = 0; z < 6; z++)
  2229. {
  2230. indexsource += 1;
  2231. ICell cell = irow4.CreateCell(indexsource);
  2232. switch (z)
  2233. {
  2234. case 0:
  2235. cell.SetCellValue(MergerHotSource[i]
  2236. .MergerHot[j - 1].Call);
  2237. cell.CellStyle = cellStylebt15;
  2238. break;
  2239. case 1:
  2240. cell.SetCellValue(MergerHotSource[i]
  2241. .MergerHot[j - 1].Connect);
  2242. cell.CellStyle = cellStylebt14;
  2243. break;
  2244. case 2:
  2245. cell.SetCellValue(MergerHotSource[i]
  2246. .MergerHot[j - 1].Notconnected);
  2247. cell.CellStyle = cellStylebt11;
  2248. break;
  2249. case 3:
  2250. cell.SetCellValue(MergerHotSource[i]
  2251. .MergerHot[j - 1].voluntarily);
  2252. cell.CellStyle = cellStylebt11;
  2253. break;
  2254. case 4:
  2255. cell.SetCellValue(MergerHotSource[i]
  2256. .MergerHot[j - 1].rate);
  2257. cell.CellStyle = cellStylebt12;
  2258. break;
  2259. case 5:
  2260. cell.SetCellValue(MergerHotSource[i]
  2261. .MergerHot[j - 1].callback );
  2262. cell.CellStyle = cellStylebt11;
  2263. break;
  2264. }
  2265. }
  2266. indexsource += 1;
  2267. }
  2268. else
  2269. {
  2270. for (int z = 0; z < 5; z++)
  2271. {
  2272. indexsource += 1;
  2273. ICell cell = irow4.CreateCell(indexsource);
  2274. switch (z)
  2275. {
  2276. case 0:
  2277. cell.SetCellValue(MergerHotSource[i]
  2278. .MergerHot[j - 1].Call);
  2279. cell.CellStyle = cellStylebt15;
  2280. break;
  2281. case 1:
  2282. cell.SetCellValue(MergerHotSource[i]
  2283. .MergerHot[j - 1].Connect);
  2284. cell.CellStyle = cellStylebt14;
  2285. break;
  2286. case 2:
  2287. cell.SetCellValue(MergerHotSource[i]
  2288. .MergerHot[j - 1].Notconnected);
  2289. cell.CellStyle = cellStylebt11;
  2290. break;
  2291. case 3:
  2292. cell.SetCellValue(MergerHotSource[i]
  2293. .MergerHot[j - 1].voluntarily);
  2294. cell.CellStyle = cellStylebt11;
  2295. break;
  2296. case 4:
  2297. cell.SetCellValue(MergerHotSource[i]
  2298. .MergerHot[j - 1].rate );
  2299. cell.CellStyle = cellStylebt11;
  2300. break;
  2301. }
  2302. }
  2303. indexsource += 1;
  2304. }
  2305. }
  2306. }
  2307. }
  2308. }
  2309. }
  2310. //自适应列宽度
  2311. //for (int i = 0; i < 20; i++)
  2312. //{
  2313. // sheet.AutoSizeColumn(i);
  2314. // // sheet.SetColumnWidth(i, 20 * 256);
  2315. //}
  2316. using (MemoryStream ms = new MemoryStream())
  2317. {
  2318. workbook.Write(ms);
  2319. HttpContext curContext = HttpContext.Current;
  2320. // 设置编码和附件格式
  2321. curContext.Response.ContentType = "application/vnd.ms-excel";
  2322. curContext.Response.ContentEncoding = Encoding.UTF8;
  2323. curContext.Response.Charset = "";
  2324. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  2325. curContext.Response.AppendHeader("Content-Disposition",
  2326. "attachment;filename=" + HttpUtility.UrlEncode("归并数据统计" + ".xls", Encoding.UTF8));
  2327. curContext.Response.BinaryWrite(ms.GetBuffer());
  2328. workbook = null;
  2329. ms.Close();
  2330. ms.Dispose();
  2331. curContext.Response.End();
  2332. }
  2333. return "";
  2334. }
  2335. catch
  2336. {
  2337. return "导出失败!";
  2338. }
  2339. }
  2340. /// <summary>
  2341. /// 督办数据报表导出
  2342. /// </summary>
  2343. /// <param name="ds"></param>
  2344. /// <returns></returns>
  2345. public string CenterReception(DataSet dt)
  2346. {
  2347. try
  2348. {
  2349. int lenth = 0;
  2350. HSSFWorkbook workbook = new HSSFWorkbook();
  2351. ISheet sheet = workbook.CreateSheet("电话中心受话情况统计表");
  2352. ICellStyle cellStyle = workbook.CreateCellStyle();
  2353. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  2354. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  2355. cellStyle.SetFont(cellfont);
  2356. ICellStyle cellStylebt = workbook.CreateCellStyle();
  2357. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  2358. cellfontbt.Boldweight = (short)FontBoldWeight.Bold;
  2359. cellStylebt.SetFont(cellfontbt);
  2360. cellStylebt.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black .Index ;
  2361. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  2362. cellStylebt.Alignment = HorizontalAlignment.Center;
  2363. cellStylebt.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2364. cellStylebt.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2365. cellStylebt.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2366. cellStylebt.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2367. ICellStyle cellStylebt1 = workbook.CreateCellStyle();
  2368. NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
  2369. cellfontbt1.Boldweight = (short)FontBoldWeight.Bold;
  2370. cellfontbt1.FontHeightInPoints = 22;
  2371. cellStylebt1.SetFont(cellfontbt1);
  2372. cellStylebt1.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2373. cellStylebt1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2374. cellStylebt1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2375. cellStylebt1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2376. cellStylebt1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2377. cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
  2378. cellStylebt1.Alignment = HorizontalAlignment.Center;
  2379. ICellStyle cellStylebt2 = workbook.CreateCellStyle();
  2380. NPOI.SS.UserModel.IFont cellfontbt2 = workbook.CreateFont();
  2381. cellfontbt2.Boldweight = (short)FontBoldWeight.Bold;
  2382. cellStylebt2.WrapText = true;//设置换行这个要先设置
  2383. cellfontbt2.FontHeightInPoints = 14;
  2384. cellStylebt2.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2385. cellStylebt2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2386. cellStylebt2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2387. cellStylebt2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2388. cellStylebt2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2389. cellStylebt2.SetFont(cellfontbt2);
  2390. cellStylebt2.VerticalAlignment = VerticalAlignment.Center;
  2391. cellStylebt2.Alignment = HorizontalAlignment.Center;
  2392. HSSFPalette palette = workbook.GetCustomPalette(); //调色板实例
  2393. palette.SetColorAtIndex(8, 218, 232, 244);
  2394. NPOI.HSSF.Util.HSSFColor hssFColor = palette.FindColor(218, 232, 244);
  2395. cellStylebt2.FillForegroundColor = hssFColor.Indexed;
  2396. cellStylebt2.FillPattern = FillPattern.SolidForeground;
  2397. cellStylebt2.FillBackgroundColor = hssFColor.Indexed; ;
  2398. ICellStyle cellStylebt3 = workbook.CreateCellStyle();
  2399. NPOI.SS.UserModel.IFont cellfontbt3 = workbook.CreateFont();
  2400. cellfontbt3.Boldweight = (short)FontBoldWeight.Bold;
  2401. cellStylebt3.WrapText = true;//设置换行这个要先设置
  2402. cellfontbt3.FontHeightInPoints = 11;
  2403. cellStylebt3.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2404. cellStylebt3.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2405. cellStylebt3.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2406. cellStylebt3.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2407. cellStylebt3.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2408. cellStylebt3.SetFont(cellfontbt3);
  2409. cellStylebt3.VerticalAlignment = VerticalAlignment.Center;
  2410. cellStylebt3.Alignment = HorizontalAlignment.Center;
  2411. ICellStyle cellStylebt4 = workbook.CreateCellStyle();
  2412. NPOI.SS.UserModel.IFont cellfontbt4 = workbook.CreateFont();
  2413. cellfontbt4.Boldweight = (short)FontBoldWeight.Bold;
  2414. cellStylebt4.WrapText = true;//设置换行这个要先设置
  2415. cellfontbt4.FontHeightInPoints = 11;
  2416. cellStylebt4.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2417. cellStylebt4.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2418. cellStylebt4.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2419. cellStylebt4.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2420. cellStylebt4.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2421. cellStylebt4.SetFont(cellfontbt4);
  2422. cellStylebt4.VerticalAlignment = VerticalAlignment.Center;
  2423. cellStylebt4.Alignment = HorizontalAlignment.Center;
  2424. HSSFPalette palette1 = workbook.GetCustomPalette(); //调色板实例
  2425. palette1.SetColorAtIndex(9, 166, 197, 191);
  2426. NPOI.HSSF.Util.HSSFColor hssFColor1 = palette1.FindColor(166, 197, 191);
  2427. cellStylebt4.FillForegroundColor = hssFColor1.Indexed;
  2428. cellStylebt4.FillPattern = FillPattern.SolidForeground;
  2429. cellStylebt4.FillBackgroundColor = hssFColor1.Indexed; ;
  2430. ICellStyle cellStylebt5 = workbook.CreateCellStyle();
  2431. cellStylebt5.WrapText = true;//设置换行这个要先设置
  2432. cellStylebt5.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2433. cellStylebt5.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2434. cellStylebt5.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2435. cellStylebt5.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2436. cellStylebt5.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2437. cellStylebt5.SetFont(cellfontbt4);
  2438. cellStylebt5.VerticalAlignment = VerticalAlignment.Center;
  2439. cellStylebt5.Alignment = HorizontalAlignment.Center;
  2440. HSSFPalette palette2 = workbook.GetCustomPalette(); //调色板实例
  2441. palette2.SetColorAtIndex(10, 216, 243, 198);
  2442. NPOI.HSSF.Util.HSSFColor hssFColor2 = palette2.FindColor(216, 243, 198);
  2443. cellStylebt5.FillForegroundColor = hssFColor2.Indexed;
  2444. cellStylebt5.FillPattern = FillPattern.SolidForeground;
  2445. cellStylebt5.FillBackgroundColor = hssFColor2.Indexed; ;
  2446. ICellStyle cellStylebt6 = workbook.CreateCellStyle();
  2447. cellStylebt6.WrapText = true;//设置换行这个要先设置
  2448. cellStylebt6.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2449. cellStylebt6.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2450. cellStylebt6.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2451. cellStylebt6.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2452. cellStylebt6.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2453. cellStylebt6.SetFont(cellfontbt4);
  2454. cellStylebt6.VerticalAlignment = VerticalAlignment.Center;
  2455. cellStylebt6.Alignment = HorizontalAlignment.Center;
  2456. HSSFPalette palette3 = workbook.GetCustomPalette(); //调色板实例
  2457. palette3.SetColorAtIndex(11, 253, 220, 212);
  2458. NPOI.HSSF.Util.HSSFColor hssFColor3 = palette3.FindColor(253, 220, 212);
  2459. cellStylebt6.FillForegroundColor = hssFColor3.Indexed;
  2460. cellStylebt6.FillPattern = FillPattern.SolidForeground;
  2461. cellStylebt6.FillBackgroundColor = hssFColor3.Indexed; ; ;
  2462. ICellStyle cellStylebt7 = workbook.CreateCellStyle();
  2463. cellStylebt7.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2464. cellStylebt7.WrapText = true;//设置换行这个要先设置
  2465. cellStylebt7.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2466. cellStylebt7.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2467. cellStylebt7.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2468. cellStylebt7.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2469. cellStylebt7.SetFont(cellfontbt4);
  2470. cellStylebt7.VerticalAlignment = VerticalAlignment.Center;
  2471. cellStylebt7.Alignment = HorizontalAlignment.Center;
  2472. HSSFPalette palette4 = workbook.GetCustomPalette(); //调色板实例
  2473. palette4.SetColorAtIndex(12, 248, 231, 187);
  2474. NPOI.HSSF.Util.HSSFColor hssFColor4 = palette4.FindColor(248, 231, 187);
  2475. cellStylebt7.FillForegroundColor = hssFColor4.Indexed;
  2476. cellStylebt7.FillPattern = FillPattern.SolidForeground;
  2477. cellStylebt7.FillBackgroundColor = hssFColor4.Indexed; ; ;
  2478. IRow irow1 = sheet.CreateRow(0);
  2479. ICell cell1 = irow1.CreateCell(0);
  2480. cell1.SetCellValue("电话中心受话情况统计表");
  2481. cell1.CellStyle = cellStylebt1;
  2482. sheet.AddMergedRegion(new CellRangeAddress(0, 2, 0, 9));
  2483. IRow irow2 = sheet.CreateRow(3);
  2484. string[] cols = { "序号", "班组", "坐席人员", "通话量"
  2485. , "呼入接通量", "呼出接通量", "呼出未接通量", "来电总量"
  2486. , "未接通量" , "待回拨量"};
  2487. for (int i = 0; i < cols.Length
  2488. ; i++)
  2489. {
  2490. ICell cell = irow2.CreateCell(i);
  2491. cell.SetCellValue(cols[i]);
  2492. cell.CellStyle = cellStylebt2;
  2493. }
  2494. IRow irow3 = sheet.CreateRow(4);
  2495. for (int i=0;i< dt.Tables [0].Rows.Count;i ++)
  2496. {
  2497. if (i ==0)
  2498. {
  2499. for (int j =0;j <7;j++)
  2500. {
  2501. ICell cell = irow3.CreateCell(j);
  2502. switch (j )
  2503. {
  2504. case 0:
  2505. cell.SetCellValue(i +1);
  2506. cell.CellStyle = cellStylebt3;
  2507. break;
  2508. case 1:
  2509. cell.SetCellValue(dt.Tables[0].Rows[i ]["groupname"].ToString ());
  2510. cell.CellStyle = cellStylebt3;
  2511. break;
  2512. case 2:
  2513. cell.SetCellValue(dt.Tables[0].Rows[i]["username"].ToString());
  2514. cell.CellStyle = cellStylebt3;
  2515. break;
  2516. case 3:
  2517. cell.SetCellValue(dt.Tables[0].Rows[i]["telcount"].ToString());
  2518. cell.CellStyle = cellStylebt4;
  2519. break;
  2520. case 4:
  2521. cell.SetCellValue(dt.Tables[0].Rows[i]["hrcount"].ToString());
  2522. cell.CellStyle = cellStylebt5;
  2523. break;
  2524. case 5:
  2525. cell.SetCellValue(dt.Tables[0].Rows[i]["hccount"].ToString());
  2526. cell.CellStyle = cellStylebt5;
  2527. break;
  2528. case 6:
  2529. cell.SetCellValue(dt.Tables[0].Rows[i]["hcwjtcount"].ToString());
  2530. cell.CellStyle = cellStylebt3;
  2531. break;
  2532. }
  2533. }
  2534. }
  2535. else
  2536. {
  2537. IRow irow4 = sheet.CreateRow(4+i );
  2538. for (int j = 0; j < 7; j++)
  2539. {
  2540. ICell cell = irow4.CreateCell(j );
  2541. switch (j)
  2542. {
  2543. case 0:
  2544. cell.SetCellValue(i + 1);
  2545. cell.CellStyle = cellStylebt3;
  2546. break;
  2547. case 1:
  2548. cell.SetCellValue(dt.Tables[0].Rows[i]["groupname"].ToString());
  2549. cell.CellStyle = cellStylebt3;
  2550. break;
  2551. case 2:
  2552. cell.SetCellValue(dt.Tables[0].Rows[i]["username"].ToString());
  2553. cell.CellStyle = cellStylebt3;
  2554. break;
  2555. case 3:
  2556. cell.SetCellValue(dt.Tables[0].Rows[i]["telcount"].ToString());
  2557. cell.CellStyle = cellStylebt4;
  2558. break;
  2559. case 4:
  2560. cell.SetCellValue(dt.Tables[0].Rows[i]["hrcount"].ToString());
  2561. cell.CellStyle = cellStylebt5;
  2562. break;
  2563. case 5:
  2564. cell.SetCellValue(dt.Tables[0].Rows[i]["hccount"].ToString());
  2565. cell.CellStyle = cellStylebt5;
  2566. break;
  2567. case 6:
  2568. cell.SetCellValue(dt.Tables[0].Rows[i]["hcwjtcount"].ToString());
  2569. cell.CellStyle = cellStylebt3;
  2570. break;
  2571. }
  2572. }
  2573. }
  2574. }
  2575. ICell cell2 = irow3.CreateCell(7);
  2576. cell2.SetCellValue(dt.Tables[1].Rows[0]["telcount"].ToString());
  2577. cell2.CellStyle = cellStylebt6;
  2578. sheet.AddMergedRegion(new CellRangeAddress(4, dt.Tables[0].Rows.Count+3, 7, 7));
  2579. ICell cell3 = irow3.CreateCell(8);
  2580. cell3.SetCellValue(dt.Tables[2].Rows[0]["wjtcount"].ToString());
  2581. cell3.CellStyle = cellStylebt7;
  2582. sheet.AddMergedRegion(new CellRangeAddress(4, dt.Tables[0].Rows.Count+3, 8, 8));
  2583. ICell cell4 = irow3.CreateCell(9);
  2584. cell4.SetCellValue(dt.Tables[3].Rows[0]["dhbcount"].ToString());
  2585. cell4.CellStyle = cellStylebt3;
  2586. sheet.AddMergedRegion(new CellRangeAddress(4, dt.Tables[0].Rows.Count+3, 9, 9));
  2587. for (int i = 0; i < 10; i++)
  2588. {
  2589. sheet.AutoSizeColumn(i);
  2590. }
  2591. using (MemoryStream ms = new MemoryStream())
  2592. {
  2593. workbook.Write(ms);
  2594. HttpContext curContext = HttpContext.Current;
  2595. // 设置编码和附件格式
  2596. curContext.Response.ContentType = "application/vnd.ms-excel";
  2597. curContext.Response.ContentEncoding = Encoding.UTF8;
  2598. curContext.Response.Charset = "";
  2599. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  2600. curContext.Response.AppendHeader("Content-Disposition",
  2601. "attachment;filename=" + HttpUtility.UrlEncode("电话中心受话情况统计表" + ".xls", Encoding.UTF8));
  2602. curContext.Response.BinaryWrite(ms.GetBuffer());
  2603. workbook = null;
  2604. ms.Close();
  2605. ms.Dispose();
  2606. curContext.Response.End();
  2607. }
  2608. return "";
  2609. }
  2610. catch(Exception e)
  2611. {
  2612. return e.Message;
  2613. }
  2614. }
  2615. /// <summary>
  2616. /// 居委办件统计
  2617. /// </summary>
  2618. /// <param name="ds"></param>
  2619. /// <returns></returns>
  2620. public string BureauHandling(DataSet dt)
  2621. {
  2622. try
  2623. {
  2624. int lenth = 0;
  2625. HSSFWorkbook workbook = new HSSFWorkbook();
  2626. ISheet sheet = workbook.CreateSheet("局委办件统计");
  2627. ICellStyle cellStyle = workbook.CreateCellStyle();
  2628. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  2629. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  2630. cellStyle.SetFont(cellfont);
  2631. ICellStyle cellStylebt1 = workbook.CreateCellStyle();
  2632. NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
  2633. cellfontbt1.Boldweight = (short)FontBoldWeight.Bold;
  2634. cellfontbt1.FontHeightInPoints = 20;
  2635. cellStylebt1.SetFont(cellfontbt1);
  2636. cellStylebt1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2637. cellStylebt1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2638. cellStylebt1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2639. cellStylebt1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2640. cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
  2641. cellStylebt1.Alignment = HorizontalAlignment.Center;
  2642. ICellStyle cellStylebt2 = workbook.CreateCellStyle();
  2643. NPOI.SS.UserModel.IFont cellfontbt2 = workbook.CreateFont();
  2644. cellfontbt2.Boldweight = (short)FontBoldWeight.Bold;
  2645. cellStylebt2.WrapText = true;//设置换行这个要先设置
  2646. cellfontbt2.FontHeightInPoints = 16;
  2647. cellStylebt2.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2648. cellStylebt2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2649. cellStylebt2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2650. cellStylebt2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2651. cellStylebt2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2652. cellStylebt2.SetFont(cellfontbt2);
  2653. cellStylebt2.VerticalAlignment = VerticalAlignment.Center;
  2654. cellStylebt2.Alignment = HorizontalAlignment.Center;
  2655. ICellStyle cellStylebt3 = workbook.CreateCellStyle();
  2656. NPOI.SS.UserModel.IFont cellfontbt3 = workbook.CreateFont();
  2657. cellfontbt3.Boldweight = (short)FontBoldWeight.Bold;
  2658. cellStylebt3.WrapText = true;//设置换行这个要先设置
  2659. cellfontbt3.FontHeightInPoints = 14;
  2660. cellStylebt3.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2661. cellStylebt3.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2662. cellStylebt3.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2663. cellStylebt3.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2664. cellStylebt3.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2665. cellStylebt3.SetFont(cellfontbt3);
  2666. cellStylebt3.VerticalAlignment = VerticalAlignment.Center;
  2667. cellStylebt3.Alignment = HorizontalAlignment.Center;
  2668. IRow irow1 = sheet.CreateRow(0);
  2669. ICell cell1 = irow1.CreateCell(0);
  2670. cell1.SetCellValue("局委办件统计");
  2671. cell1.CellStyle = cellStylebt1;
  2672. sheet.AddMergedRegion(new CellRangeAddress(0, 2, 0, 14));
  2673. IRow irow = sheet.CreateRow(3);
  2674. for (int i = 0; i < 15; i++)
  2675. {
  2676. ICell cell4 = irow.CreateCell(i);
  2677. cell4.CellStyle = cellStylebt2;
  2678. }
  2679. ICell cell2 = irow.CreateCell(5);
  2680. cell2.SetCellValue("未办结");
  2681. cell2.CellStyle = cellStylebt2;
  2682. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 5, 6));
  2683. ICell cell3 = irow.CreateCell(7);
  2684. cell3.SetCellValue("已办结");
  2685. cell3.CellStyle = cellStylebt2;
  2686. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 7, 9));
  2687. IRow irow2 = sheet.CreateRow(4);
  2688. string[] cols = { "序号", "承办单位", "承办件", "办结件"
  2689. , "办结率", "正在办理", "超期未果", "正常回复"
  2690. , "超期回复" , "已办未果", "待审核", "局委退件", "延期件", "重置转发", "驳回"};
  2691. for (int i = 0; i < cols.Length
  2692. ; i++)
  2693. {
  2694. ICell cell = irow2.CreateCell(i);
  2695. cell.SetCellValue(cols[i]);
  2696. cell.CellStyle = cellStylebt2;
  2697. }
  2698. if (dt!=null&& dt.Tables [0].Rows .Count >0)
  2699. {
  2700. for (int i=0; i< dt.Tables[0].Rows.Count;i++)
  2701. {
  2702. IRow irow3 = sheet.CreateRow(5+i);
  2703. for (int j = 0; j < cols.Length
  2704. ; j++)
  2705. {
  2706. ICell cell = irow3.CreateCell(j);
  2707. switch (j )
  2708. {
  2709. case 0:
  2710. cell.SetCellValue(i +1);
  2711. cell.CellStyle = cellStylebt3;
  2712. break;
  2713. case 1:
  2714. cell.SetCellValue(dt.Tables[0].Rows[i]["deptname"].ToString());
  2715. cell.CellStyle = cellStylebt3;
  2716. break;
  2717. case 2:
  2718. cell.SetCellValue(dt.Tables[0].Rows[i]["cbcount"].ToString());
  2719. cell.CellStyle = cellStylebt3;
  2720. break;
  2721. case 3:
  2722. cell.SetCellValue(dt.Tables[0].Rows[i]["bjcount"].ToString());
  2723. cell.CellStyle = cellStylebt3;
  2724. break;
  2725. case 4:
  2726. cell.SetCellValue(dt.Tables[0].Rows[i]["bjrate"].ToString());
  2727. cell.CellStyle = cellStylebt3;
  2728. break;
  2729. case 5:
  2730. cell.SetCellValue(dt.Tables[0].Rows[i]["blcount"].ToString());
  2731. cell.CellStyle = cellStylebt3;
  2732. break;
  2733. case 6:
  2734. cell.SetCellValue(dt.Tables[0].Rows[i]["cqwgcount"].ToString());
  2735. cell.CellStyle = cellStylebt3;
  2736. break;
  2737. case 7:
  2738. cell.SetCellValue(dt.Tables[0].Rows[i]["zchf"].ToString());
  2739. cell.CellStyle = cellStylebt3;
  2740. break;
  2741. case 8:
  2742. cell.SetCellValue(dt.Tables[0].Rows[i]["cqhf"].ToString());
  2743. cell.CellStyle = cellStylebt3;
  2744. break;
  2745. case 9:
  2746. cell.SetCellValue(dt.Tables[0].Rows[i]["ybwg"].ToString());
  2747. cell.CellStyle = cellStylebt3;
  2748. break;
  2749. case 10:
  2750. cell.SetCellValue(dt.Tables[0].Rows[i]["dsh"].ToString());
  2751. cell.CellStyle = cellStylebt3;
  2752. break;
  2753. case 11:
  2754. cell.SetCellValue(dt.Tables[0].Rows[i]["jwtj"].ToString());
  2755. cell.CellStyle = cellStylebt3;
  2756. break;
  2757. case 12:
  2758. cell.SetCellValue(dt.Tables[0].Rows[i]["yqcount"].ToString());
  2759. cell.CellStyle = cellStylebt3;
  2760. break;
  2761. case 13:
  2762. cell.SetCellValue(dt.Tables[0].Rows[i]["czzf"].ToString());
  2763. cell.CellStyle = cellStylebt3;
  2764. break;
  2765. case 14:
  2766. cell.SetCellValue(dt.Tables[0].Rows[i]["bh"].ToString());
  2767. cell.CellStyle = cellStylebt3;
  2768. break;
  2769. }
  2770. }
  2771. }
  2772. }
  2773. for (int i = 0; i < 10; i++)
  2774. {
  2775. sheet.AutoSizeColumn(i);
  2776. }
  2777. using (MemoryStream ms = new MemoryStream())
  2778. {
  2779. workbook.Write(ms);
  2780. HttpContext curContext = HttpContext.Current;
  2781. // 设置编码和附件格式
  2782. curContext.Response.ContentType = "application/vnd.ms-excel";
  2783. curContext.Response.ContentEncoding = Encoding.UTF8;
  2784. curContext.Response.Charset = "";
  2785. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  2786. curContext.Response.AppendHeader("Content-Disposition",
  2787. "attachment;filename=" + HttpUtility.UrlEncode("局委办件统计" + ".xls", Encoding.UTF8));
  2788. curContext.Response.BinaryWrite(ms.GetBuffer());
  2789. workbook = null;
  2790. ms.Close();
  2791. ms.Dispose();
  2792. curContext.Response.End();
  2793. }
  2794. return "";
  2795. }
  2796. catch (Exception e)
  2797. {
  2798. return e.Message;
  2799. }
  2800. }
  2801. /// <summary>
  2802. /// 政民互动综合统计
  2803. /// </summary>
  2804. /// <param name="ds"></param>
  2805. /// <returns></returns>
  2806. public string Government(DataSet dt)
  2807. {
  2808. try
  2809. {
  2810. int lenth = 0;
  2811. HSSFWorkbook workbook = new HSSFWorkbook();
  2812. ISheet sheet = workbook.CreateSheet("政民互动综合统计");
  2813. ICellStyle cellStyle = workbook.CreateCellStyle();
  2814. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  2815. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  2816. cellStyle.SetFont(cellfont);
  2817. ICellStyle cellStylebt1 = workbook.CreateCellStyle();
  2818. NPOI.SS.UserModel.IFont cellfontbt1 = workbook.CreateFont();
  2819. cellfontbt1.Boldweight = (short)FontBoldWeight.Bold;
  2820. cellfontbt1.FontHeightInPoints = 20;
  2821. cellStylebt1.SetFont(cellfontbt1);
  2822. cellStylebt1.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2823. cellStylebt1.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2824. cellStylebt1.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2825. cellStylebt1.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2826. cellStylebt1.VerticalAlignment = VerticalAlignment.Center;
  2827. cellStylebt1.Alignment = HorizontalAlignment.Center;
  2828. ICellStyle cellStylebt2 = workbook.CreateCellStyle();
  2829. NPOI.SS.UserModel.IFont cellfontbt2 = workbook.CreateFont();
  2830. cellfontbt2.Boldweight = (short)FontBoldWeight.Bold;
  2831. cellStylebt2.WrapText = true;//设置换行这个要先设置
  2832. cellfontbt2.FontHeightInPoints = 16;
  2833. cellStylebt2.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2834. cellStylebt2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2835. cellStylebt2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2836. cellStylebt2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2837. cellStylebt2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2838. cellStylebt2.SetFont(cellfontbt2);
  2839. cellStylebt2.VerticalAlignment = VerticalAlignment.Center;
  2840. cellStylebt2.Alignment = HorizontalAlignment.Center;
  2841. ICellStyle cellStylebt3 = workbook.CreateCellStyle();
  2842. NPOI.SS.UserModel.IFont cellfontbt3 = workbook.CreateFont();
  2843. cellfontbt3.Boldweight = (short)FontBoldWeight.Bold;
  2844. cellStylebt3.WrapText = true;//设置换行这个要先设置
  2845. cellfontbt3.FontHeightInPoints = 14;
  2846. cellStylebt3.BottomBorderColor = NPOI.HSSF.Util.HSSFColor.Black.Index;
  2847. cellStylebt3.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  2848. cellStylebt3.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  2849. cellStylebt3.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  2850. cellStylebt3.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  2851. cellStylebt3.SetFont(cellfontbt3);
  2852. cellStylebt3.VerticalAlignment = VerticalAlignment.Center;
  2853. cellStylebt3.Alignment = HorizontalAlignment.Center;
  2854. IRow irow1 = sheet.CreateRow(0);
  2855. ICell cell1 = irow1.CreateCell(0);
  2856. cell1.SetCellValue("政民互动综合统计");
  2857. cell1.CellStyle = cellStylebt1;
  2858. IRow irow = sheet.CreateRow(3);
  2859. sheet.AddMergedRegion(new CellRangeAddress(0, 2, 0, 14));
  2860. for (int i = 0; i < 15; i++)
  2861. {
  2862. ICell cell4 = irow.CreateCell(i );
  2863. cell4.CellStyle = cellStylebt2;
  2864. }
  2865. ICell cell2 = irow.CreateCell(6);
  2866. cell2.SetCellValue("状态");
  2867. cell2.CellStyle = cellStylebt2;
  2868. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 6, 9));
  2869. ICell cell3 = irow.CreateCell(10);
  2870. cell3.SetCellValue("已办结");
  2871. cell3.CellStyle = cellStylebt2;
  2872. sheet.AddMergedRegion(new CellRangeAddress(3, 3, 10, 14));
  2873. IRow irow2 = sheet.CreateRow(4);
  2874. string[] cols = { "序号", "工单来源", "工单总量", "转办量"
  2875. , "退件量", "退件率", "已办结", "已办未果"
  2876. , "超期未果" , "办理率", "评议量", "满意量", "不满意量", "满意率", "重新转办量"};
  2877. for (int i = 0; i < cols.Length
  2878. ; i++)
  2879. {
  2880. ICell cell = irow2.CreateCell(i);
  2881. cell.SetCellValue(cols[i]);
  2882. cell.CellStyle = cellStylebt2;
  2883. }
  2884. if (dt != null && dt.Tables[0].Rows.Count > 0)
  2885. {
  2886. for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
  2887. {
  2888. IRow irow3 = sheet.CreateRow(5 + i);
  2889. for (int j = 0; j < cols.Length
  2890. ; j++)
  2891. {
  2892. ICell cell = irow3.CreateCell(j);
  2893. switch (j)
  2894. {
  2895. case 0:
  2896. cell.SetCellValue(i + 1);
  2897. cell.CellStyle = cellStylebt3;
  2898. break;
  2899. case 1:
  2900. cell.SetCellValue(dt.Tables[0].Rows[i]["name"].ToString());
  2901. cell.CellStyle = cellStylebt3;
  2902. break;
  2903. case 2:
  2904. cell.SetCellValue(dt.Tables[0].Rows[i]["totalcount"].ToString());
  2905. cell.CellStyle = cellStylebt3;
  2906. break;
  2907. case 3:
  2908. cell.SetCellValue(dt.Tables[0].Rows[i]["zb"].ToString());
  2909. cell.CellStyle = cellStylebt3;
  2910. break;
  2911. case 4:
  2912. cell.SetCellValue(dt.Tables[0].Rows[i]["td"].ToString());
  2913. cell.CellStyle = cellStylebt3;
  2914. break;
  2915. case 5:
  2916. cell.SetCellValue(dt.Tables[0].Rows[i]["tdrate"].ToString());
  2917. cell.CellStyle = cellStylebt3;
  2918. break;
  2919. case 6:
  2920. cell.SetCellValue(dt.Tables[0].Rows[i]["bj"].ToString());
  2921. cell.CellStyle = cellStylebt3;
  2922. break;
  2923. case 7:
  2924. cell.SetCellValue(dt.Tables[0].Rows[i]["ybwg"].ToString());
  2925. cell.CellStyle = cellStylebt3;
  2926. break;
  2927. case 8:
  2928. cell.SetCellValue(dt.Tables[0].Rows[i]["cqwg"].ToString());
  2929. cell.CellStyle = cellStylebt3;
  2930. break;
  2931. case 9:
  2932. cell.SetCellValue(dt.Tables[0].Rows[i]["blrate"].ToString());
  2933. cell.CellStyle = cellStylebt3;
  2934. break;
  2935. case 10:
  2936. cell.SetCellValue(dt.Tables[0].Rows[i]["py"].ToString());
  2937. cell.CellStyle = cellStylebt3;
  2938. break;
  2939. case 11:
  2940. cell.SetCellValue(dt.Tables[0].Rows[i]["my"].ToString());
  2941. cell.CellStyle = cellStylebt3;
  2942. break;
  2943. case 12:
  2944. cell.SetCellValue(dt.Tables[0].Rows[i]["bmy"].ToString());
  2945. cell.CellStyle = cellStylebt3;
  2946. break;
  2947. case 13:
  2948. cell.SetCellValue(dt.Tables[0].Rows[i]["myrate"].ToString());
  2949. cell.CellStyle = cellStylebt3;
  2950. break;
  2951. case 14:
  2952. cell.SetCellValue(dt.Tables[0].Rows[i]["cxzb"].ToString());
  2953. cell.CellStyle = cellStylebt3;
  2954. break;
  2955. }
  2956. }
  2957. }
  2958. }
  2959. for (int i = 0; i < 10; i++)
  2960. {
  2961. sheet.AutoSizeColumn(i);
  2962. }
  2963. using (MemoryStream ms = new MemoryStream())
  2964. {
  2965. workbook.Write(ms);
  2966. HttpContext curContext = HttpContext.Current;
  2967. // 设置编码和附件格式
  2968. curContext.Response.ContentType = "application/vnd.ms-excel";
  2969. curContext.Response.ContentEncoding = Encoding.UTF8;
  2970. curContext.Response.Charset = "";
  2971. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  2972. curContext.Response.AppendHeader("Content-Disposition",
  2973. "attachment;filename=" + HttpUtility.UrlEncode("政民互动综合统计" + ".xls", Encoding.UTF8));
  2974. curContext.Response.BinaryWrite(ms.GetBuffer());
  2975. workbook = null;
  2976. ms.Close();
  2977. ms.Dispose();
  2978. curContext.Response.End();
  2979. }
  2980. return "";
  2981. }
  2982. catch (Exception e)
  2983. {
  2984. return e.Message;
  2985. }
  2986. }
  2987. /// <summary>
  2988. /// 弹出下载框导出excel
  2989. /// </summary>
  2990. /// <param name="Name"></param>
  2991. /// <param name="dt"></param>
  2992. /// <returns></returns>
  2993. public string TSExportToExcel(DataTable dt, int tscount)
  2994. {
  2995. try
  2996. {
  2997. //if (dt.Rows.Count > 0)
  2998. //{
  2999. HSSFWorkbook workbook = new HSSFWorkbook();
  3000. ISheet sheet = workbook.CreateSheet("Sheet1");
  3001. ICellStyle HeadercellStyle = workbook.CreateCellStyle();
  3002. HeadercellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  3003. HeadercellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  3004. HeadercellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  3005. HeadercellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  3006. HeadercellStyle.Alignment = HorizontalAlignment.Center;
  3007. HeadercellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  3008. HeadercellStyle.FillPattern = FillPattern.SolidForeground;
  3009. HeadercellStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  3010. //字体
  3011. NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
  3012. headerfont.Boldweight = (short)FontBoldWeight.Bold;
  3013. headerfont.FontHeightInPoints = 12;
  3014. HeadercellStyle.SetFont(headerfont);
  3015. //用column name 作为列名
  3016. int icolIndex = 0;
  3017. IRow headerRow = sheet.CreateRow(0);
  3018. foreach (DataColumn dc in dt.Columns)
  3019. {
  3020. ICell cell = headerRow.CreateCell(icolIndex);
  3021. cell.SetCellValue(dc.ColumnName);
  3022. cell.CellStyle = HeadercellStyle;
  3023. icolIndex++;
  3024. }
  3025. ICellStyle cellStyle = workbook.CreateCellStyle();
  3026. //为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
  3027. cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
  3028. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  3029. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  3030. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  3031. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  3032. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  3033. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  3034. cellStyle.SetFont(cellfont);
  3035. //建立内容行
  3036. int iRowIndex = 0;
  3037. foreach (DataRow dr in dt.Rows)
  3038. {
  3039. int iCellIndex = 0;
  3040. IRow irow = sheet.CreateRow(iRowIndex + 1);
  3041. for (int i = 0; i < dt.Columns.Count; i++)
  3042. {
  3043. string strsj = string.Empty;
  3044. if (dr[i] != null)
  3045. {
  3046. strsj = dr[i].ToString();
  3047. }
  3048. ICell cell = irow.CreateCell(iCellIndex);
  3049. cell.SetCellValue(strsj);
  3050. cell.CellStyle = cellStyle;
  3051. iCellIndex++;
  3052. }
  3053. iRowIndex++;
  3054. }
  3055. sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 1));
  3056. sheet.AddMergedRegion(new CellRangeAddress(1, tscount, 0, 0));
  3057. for (int i = iRowIndex; i > tscount; i--)
  3058. {
  3059. sheet.AddMergedRegion(new CellRangeAddress(i, i, 0, 1));
  3060. }
  3061. //自适应列宽度
  3062. for (int i = 0; i < icolIndex; i++)
  3063. {
  3064. sheet.AutoSizeColumn(i);
  3065. }
  3066. using (MemoryStream ms = new MemoryStream())
  3067. {
  3068. workbook.Write(ms);
  3069. HttpContext curContext = HttpContext.Current;
  3070. // 设置编码和附件格式
  3071. curContext.Response.ContentType = "application/vnd.ms-excel";
  3072. curContext.Response.ContentEncoding = Encoding.UTF8;
  3073. curContext.Response.Charset = "";
  3074. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  3075. curContext.Response.AppendHeader("Content-Disposition",
  3076. "attachment;filename=" + HttpUtility.UrlEncode("投诉统计_导出文件_" + DateTime.Now.Ticks + ".xls", Encoding.UTF8));
  3077. curContext.Response.BinaryWrite(ms.GetBuffer());
  3078. workbook = null;
  3079. ms.Close();
  3080. ms.Dispose();
  3081. curContext.Response.End();
  3082. }
  3083. //}
  3084. return "";
  3085. }
  3086. catch
  3087. {
  3088. return "导出失败!";
  3089. }
  3090. }
  3091. /// <summary>
  3092. /// 生成excel到路径
  3093. /// </summary>
  3094. /// <param name="Name"></param>
  3095. /// <param name="dt"></param>
  3096. /// <returns></returns>
  3097. public string CreateExcelFile(string Name, DataTable dt, string Path,string[] cols = null)
  3098. {
  3099. try
  3100. {
  3101. if (dt.Rows.Count > 0)
  3102. {
  3103. HSSFWorkbook workbook = new HSSFWorkbook();
  3104. ISheet sheet = workbook.CreateSheet(Name);
  3105. ICellStyle HeadercellStyle = workbook.CreateCellStyle();
  3106. HeadercellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  3107. HeadercellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  3108. HeadercellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  3109. HeadercellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  3110. HeadercellStyle.Alignment = HorizontalAlignment.Center;
  3111. HeadercellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  3112. HeadercellStyle.FillPattern = FillPattern.SolidForeground;
  3113. HeadercellStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  3114. //字体
  3115. NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
  3116. headerfont.Boldweight = (short)FontBoldWeight.Bold;
  3117. headerfont.FontHeightInPoints = 12;
  3118. HeadercellStyle.SetFont(headerfont);
  3119. //用column name 作为列名
  3120. int icolIndex = 0;
  3121. IRow headerRow = sheet.CreateRow(0);
  3122. if (cols == null || (cols != null && cols.Length == 0))
  3123. {
  3124. foreach (DataColumn dc in dt.Columns)
  3125. {
  3126. ICell cell = headerRow.CreateCell(icolIndex);
  3127. cell.SetCellValue(dc.ColumnName);
  3128. cell.CellStyle = HeadercellStyle;
  3129. icolIndex++;
  3130. }
  3131. }
  3132. else
  3133. {
  3134. foreach (string dc in cols)
  3135. {
  3136. ICell cell = headerRow.CreateCell(icolIndex);
  3137. cell.SetCellValue(dc);
  3138. cell.CellStyle = HeadercellStyle;
  3139. icolIndex++;
  3140. }
  3141. }
  3142. ICellStyle cellStyle = workbook.CreateCellStyle();
  3143. //为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
  3144. cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
  3145. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  3146. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  3147. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  3148. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  3149. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  3150. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  3151. cellStyle.SetFont(cellfont);
  3152. //建立内容行
  3153. int iRowIndex = 0;
  3154. foreach (DataRow dr in dt.Rows)
  3155. {
  3156. int iCellIndex = 0;
  3157. IRow irow = sheet.CreateRow(iRowIndex + 1);
  3158. for (int i = 0; i < dt.Columns.Count; i++)
  3159. {
  3160. string strsj = string.Empty;
  3161. if (dr[i] != null)
  3162. {
  3163. strsj = dr[i].ToString();
  3164. }
  3165. ICell cell = irow.CreateCell(iCellIndex);
  3166. cell.SetCellValue(strsj);
  3167. cell.CellStyle = cellStyle;
  3168. iCellIndex++;
  3169. }
  3170. iRowIndex++;
  3171. }
  3172. //自适应列宽度
  3173. for (int i = 0; i < icolIndex; i++)
  3174. {
  3175. sheet.AutoSizeColumn(i);
  3176. }
  3177. Name = HttpUtility.UrlEncode(Name + "_导出文件_" + DateTime.Now.Ticks + ".xls");
  3178. Path = HttpContext.Current.Server.MapPath("..") + Path;
  3179. if (!Directory.Exists(Path)) Directory.CreateDirectory(Path);
  3180. FileStream fileHSSF = new FileStream(Path+ Name, FileMode.Create);
  3181. workbook.Write(fileHSSF);
  3182. fileHSSF.Close();
  3183. fileHSSF.Dispose();
  3184. workbook = null;
  3185. }
  3186. return "";
  3187. }
  3188. catch
  3189. {
  3190. return "生成失败!";
  3191. }
  3192. }
  3193. /// <summary>
  3194. /// 弹出下载框导出excel
  3195. /// </summary>
  3196. /// <param name="Name"></param>
  3197. /// <param name="dt"></param>
  3198. /// <returns></returns>
  3199. public string ExportToExcel64(string name, string base64url)
  3200. {
  3201. try
  3202. {
  3203. int delLength = base64url.IndexOf(',') + 1;
  3204. string str = base64url.Substring(delLength, base64url.Length - delLength);
  3205. byte[] bData = Convert.FromBase64String(str);
  3206. HttpContext curContext = HttpContext.Current;
  3207. // 设置编码和附件格式
  3208. curContext.Response.ContentType = "application/vnd.ms-excel";
  3209. curContext.Response.ContentEncoding = Encoding.UTF8;
  3210. curContext.Response.Charset = "";
  3211. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  3212. curContext.Response.AppendHeader("Content-Disposition",
  3213. "attachment;filename=" + HttpUtility.UrlEncode(name + "_导出文件_" + DateTime.Now.Ticks + ".xls", Encoding.UTF8));
  3214. curContext.Response.BinaryWrite(bData);
  3215. curContext.Response.End();
  3216. return "";
  3217. }
  3218. catch
  3219. {
  3220. return "导出失败!";
  3221. }
  3222. }
  3223. /// <summary>
  3224. /// 简报导出
  3225. /// </summary>
  3226. /// <param name="ds"></param>
  3227. /// <returns></returns>
  3228. public string SimpleExportToExcel(DataSet ds)
  3229. {
  3230. try
  3231. {
  3232. HSSFWorkbook workbook = new HSSFWorkbook();
  3233. ISheet sheet = workbook.CreateSheet("Sheet1");
  3234. ICellStyle cellStyle = workbook.CreateCellStyle();
  3235. //为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
  3236. //cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
  3237. //cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  3238. //cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  3239. //cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  3240. //cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  3241. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  3242. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  3243. cellStyle.SetFont(cellfont);
  3244. ICellStyle cellStylebt = workbook.CreateCellStyle();
  3245. NPOI.SS.UserModel.IFont cellfontbt = workbook.CreateFont();
  3246. cellfontbt.Boldweight = (short)FontBoldWeight.Bold;
  3247. cellStylebt.SetFont(cellfontbt);
  3248. cellStylebt.VerticalAlignment = VerticalAlignment.Center;
  3249. cellStylebt.Alignment = HorizontalAlignment.Center;
  3250. IRow irow1 = sheet.CreateRow(1);
  3251. ICell cell1 = irow1.CreateCell(0);
  3252. cell1.SetCellValue("时间:"+ ds.Tables[5].Rows[0]["sdate"].ToString()+ " 至 "+ ds.Tables[5].Rows[0]["edate"].ToString());
  3253. cell1.CellStyle = cellStylebt;
  3254. sheet.AddMergedRegion(new CellRangeAddress(1, 1, 0, 7));
  3255. //((HSSFSheet)sheet).SetEnclosedBorderOfRegion(new CellRangeAddress(1, 1, 0, 7), BorderStyle.Thin, NPOI.HSSF.Util.HSSFColor.Black.Index);
  3256. #region 话务受理情况
  3257. DataTable dt1 = ds.Tables[0];
  3258. IRow irow2 = sheet.CreateRow(2);
  3259. ICell cell2 = irow2.CreateCell(0);
  3260. cell2.SetCellValue("话务受理情况");
  3261. cell2.CellStyle = cellStylebt;
  3262. sheet.AddMergedRegion(new CellRangeAddress(2, 2, 0, 7));
  3263. IRow irow3 = sheet.CreateRow(3);
  3264. ICell cell31 = irow3.CreateCell(0);
  3265. cell31.SetCellValue("来电");
  3266. cell31.CellStyle = cellStyle;
  3267. ICell cell32 = irow3.CreateCell(1);
  3268. cell32.SetCellValue(Int32.Parse(dt1.Rows[0]["ldcount"].ToString()));
  3269. cell32.CellStyle = cellStyle;
  3270. ICell cell33 = irow3.CreateCell(2);
  3271. cell33.SetCellValue("接听");
  3272. cell33.CellStyle = cellStyle;
  3273. ICell cell34 = irow3.CreateCell(3);
  3274. cell34.SetCellValue(Int32.Parse(dt1.Rows[0]["jtcount"].ToString()));
  3275. cell34.CellStyle = cellStyle;
  3276. ICell cell35 = irow3.CreateCell(4);
  3277. cell35.SetCellValue("有效接听");
  3278. cell35.CellStyle = cellStyle;
  3279. ICell cell36 = irow3.CreateCell(5);
  3280. cell36.SetCellValue(Int32.Parse(dt1.Rows[0]["yxcount"].ToString()));
  3281. cell36.CellStyle = cellStyle;
  3282. #endregion
  3283. #region 工单受理情况
  3284. DataTable dt2 = ds.Tables[1];
  3285. IRow irow4 = sheet.CreateRow(4);
  3286. ICell cell4 = irow4.CreateCell(0);
  3287. cell4.SetCellValue("工单受理情况");
  3288. cell4.CellStyle = cellStylebt;
  3289. sheet.AddMergedRegion(new CellRangeAddress(4, 4, 0, 7));
  3290. IRow irow5 = sheet.CreateRow(5);
  3291. ICell cell51 = irow5.CreateCell(0);
  3292. cell51.SetCellValue("受理");
  3293. cell51.CellStyle = cellStyle;
  3294. ICell cell52 = irow5.CreateCell(1);
  3295. cell52.SetCellValue(Int32.Parse(dt2.Rows[0]["slcount"].ToString()));
  3296. cell52.CellStyle = cellStyle;
  3297. ICell cell53 = irow5.CreateCell(2);
  3298. cell53.SetCellValue("待提交");
  3299. cell53.CellStyle = cellStyle;
  3300. ICell cell54 = irow5.CreateCell(3);
  3301. cell54.SetCellValue(Int32.Parse(dt2.Rows[0]["dtjcount"].ToString()));
  3302. cell54.CellStyle = cellStyle;
  3303. ICell cell55 = irow5.CreateCell(4);
  3304. cell55.SetCellValue("待交办");
  3305. cell55.CellStyle = cellStyle;
  3306. ICell cell56 = irow5.CreateCell(5);
  3307. cell56.SetCellValue(Int32.Parse(dt2.Rows[0]["djbcount"].ToString()));
  3308. cell56.CellStyle = cellStyle;
  3309. ICell cell57 = irow5.CreateCell(6);
  3310. cell57.SetCellValue("待查收");
  3311. cell57.CellStyle = cellStyle;
  3312. ICell cell58 = irow5.CreateCell(7);
  3313. cell58.SetCellValue(Int32.Parse(dt2.Rows[0]["dcscount"].ToString()));
  3314. cell58.CellStyle = cellStyle;
  3315. IRow irow6 = sheet.CreateRow(6);
  3316. ICell cell61 = irow6.CreateCell(0);
  3317. cell61.SetCellValue("待审核退回");
  3318. cell61.CellStyle = cellStyle;
  3319. ICell cell62 = irow6.CreateCell(1);
  3320. cell62.SetCellValue(Int32.Parse(dt2.Rows[0]["dshthcount"].ToString()));
  3321. cell62.CellStyle = cellStyle;
  3322. ICell cell63 = irow6.CreateCell(2);
  3323. cell63.SetCellValue("待办理");
  3324. cell63.CellStyle = cellStyle;
  3325. ICell cell64 = irow6.CreateCell(3);
  3326. cell64.SetCellValue(Int32.Parse(dt2.Rows[0]["dblcount"].ToString()));
  3327. cell64.CellStyle = cellStyle;
  3328. ICell cell65 = irow6.CreateCell(4);
  3329. cell65.SetCellValue("待延时审核");
  3330. cell65.CellStyle = cellStyle;
  3331. ICell cell66 = irow6.CreateCell(5);
  3332. cell66.SetCellValue(Int32.Parse(dt2.Rows[0]["dshyscount"].ToString()));
  3333. cell66.CellStyle = cellStyle;
  3334. ICell cell67 = irow6.CreateCell(6);
  3335. cell67.SetCellValue("待回访");
  3336. cell67.CellStyle = cellStyle;
  3337. ICell cell68 = irow6.CreateCell(7);
  3338. cell68.SetCellValue(Int32.Parse(dt2.Rows[0]["dhfcount"].ToString()));
  3339. cell68.CellStyle = cellStyle;
  3340. IRow irow7 = sheet.CreateRow(7);
  3341. ICell cell71 = irow7.CreateCell(0);
  3342. cell71.SetCellValue("待结案");
  3343. cell71.CellStyle = cellStyle;
  3344. ICell cell72 = irow7.CreateCell(1);
  3345. cell72.SetCellValue(Int32.Parse(dt2.Rows[0]["dwjcount"].ToString()));
  3346. cell72.CellStyle = cellStyle;
  3347. ICell cell73 = irow7.CreateCell(2);
  3348. cell73.SetCellValue("待重办");
  3349. cell73.CellStyle = cellStyle;
  3350. ICell cell74 = irow7.CreateCell(3);
  3351. cell74.SetCellValue(Int32.Parse(dt2.Rows[0]["dcbcount"].ToString()));
  3352. cell74.CellStyle = cellStyle;
  3353. ICell cell75 = irow7.CreateCell(4);
  3354. cell75.SetCellValue("已结案");
  3355. cell75.CellStyle = cellStyle;
  3356. ICell cell76 = irow7.CreateCell(5);
  3357. cell76.SetCellValue(Int32.Parse(dt2.Rows[0]["ywjcount"].ToString()));
  3358. cell76.CellStyle = cellStyle;
  3359. ICell cell77 = irow7.CreateCell(6);
  3360. cell77.SetCellValue("在线办理");
  3361. cell77.CellStyle = cellStyle;
  3362. ICell cell78 = irow7.CreateCell(7);
  3363. cell78.SetCellValue(Int32.Parse(dt2.Rows[0]["zxbjcount"].ToString()));
  3364. cell78.CellStyle = cellStyle;
  3365. IRow irow8 = sheet.CreateRow(8);
  3366. ICell cell81 = irow8.CreateCell(0);
  3367. cell81.SetCellValue("中心转派");
  3368. cell81.CellStyle = cellStyle;
  3369. ICell cell82 = irow8.CreateCell(1);
  3370. cell82.SetCellValue(Int32.Parse(dt2.Rows[0]["zxzpcount"].ToString()));
  3371. cell82.CellStyle = cellStyle;
  3372. ICell cell83 = irow8.CreateCell(2);
  3373. cell83.SetCellValue("在线办理率");
  3374. cell83.CellStyle = cellStyle;
  3375. ICell cell84 = irow8.CreateCell(3);
  3376. cell84.SetCellValue(dt2.Rows[0]["zxbjrate"].ToString());
  3377. cell84.CellStyle = cellStyle;
  3378. #endregion
  3379. #region 政府热线受理情况
  3380. DataTable dt3 = ds.Tables[2];
  3381. IRow irow9 = sheet.CreateRow(9);
  3382. ICell cell9 = irow9.CreateCell(0);
  3383. cell9.SetCellValue("政府热线受理情况");
  3384. cell9.CellStyle = cellStylebt;
  3385. sheet.AddMergedRegion(new CellRangeAddress(9, 9, 0, 7));
  3386. IRow irow10 = sheet.CreateRow(10);
  3387. IRow irow11 = sheet.CreateRow(11);
  3388. int n = 0;
  3389. foreach (DataRow dr3 in dt3.Rows)
  3390. {
  3391. if (n < 4)
  3392. {
  3393. ICell cell101 = irow10.CreateCell(2 * (n + 1) - 2);
  3394. cell101.SetCellValue(dr3["source"].ToString());
  3395. cell101.CellStyle = cellStyle;
  3396. ICell cell102 = irow10.CreateCell(2 * (n + 1) - 1);
  3397. cell102.SetCellValue(Int32.Parse(dr3["count"].ToString()));
  3398. cell102.CellStyle = cellStyle;
  3399. }
  3400. else
  3401. {
  3402. ICell cell111 = irow11.CreateCell(2 * (n -3) - 2);
  3403. cell111.SetCellValue(dr3["source"].ToString());
  3404. cell111.CellStyle = cellStyle;
  3405. ICell cell112 = irow11.CreateCell(2 * (n - 3) - 1);
  3406. cell112.SetCellValue(Int32.Parse(dr3["count"].ToString()));
  3407. cell112.CellStyle = cellStyle;
  3408. }
  3409. n = n + 1;
  3410. }
  3411. #endregion
  3412. #region 工单受理类型情况
  3413. DataTable dt4 = ds.Tables[3];
  3414. IRow irow12 = sheet.CreateRow(12);
  3415. ICell cell12 = irow12.CreateCell(0);
  3416. cell12.SetCellValue("工单受理类型情况");
  3417. cell12.CellStyle = cellStylebt;
  3418. sheet.AddMergedRegion(new CellRangeAddress(12, 12, 0, 7));
  3419. IRow irow13 = sheet.CreateRow(13);
  3420. IRow irow14 = sheet.CreateRow(14);
  3421. int m = 0;
  3422. foreach (DataRow dr4 in dt4.Rows)
  3423. {
  3424. if (m < 4)
  3425. {
  3426. ICell cell131 = irow13.CreateCell(2 * (m + 1) - 2);
  3427. cell131.SetCellValue(dr4["type"].ToString());
  3428. cell131.CellStyle = cellStyle;
  3429. ICell cell132 = irow13.CreateCell(2 * (m + 1) - 1);
  3430. cell132.SetCellValue(Int32.Parse(dr4["count"].ToString()));
  3431. cell132.CellStyle = cellStyle;
  3432. }
  3433. else
  3434. {
  3435. ICell cell141 = irow14.CreateCell(2 * (m - 3) - 2);
  3436. cell141.SetCellValue(dr4["type"].ToString());
  3437. cell141.CellStyle = cellStyle;
  3438. ICell cell152 = irow14.CreateCell(2 * (m - 3) - 1);
  3439. cell152.SetCellValue(Int32.Parse(dr4["count"].ToString()));
  3440. cell152.CellStyle = cellStyle;
  3441. }
  3442. m = m + 1;
  3443. }
  3444. #endregion
  3445. #region 工单事发区域情况
  3446. DataTable dt5 = ds.Tables[4];
  3447. IRow irow15 = sheet.CreateRow(15);
  3448. ICell cell15 = irow15.CreateCell(0);
  3449. cell15.SetCellValue("工单事发区域情况");
  3450. cell15.CellStyle = cellStylebt;
  3451. sheet.AddMergedRegion(new CellRangeAddress(15, 15, 0, 7));
  3452. int rowcount = (dt5.Rows.Count / 4) + 1;
  3453. for (int i = 0; i < rowcount; i++)
  3454. {
  3455. IRow irow = sheet.CreateRow(16 + i);
  3456. for (int j = 0; j < 4; j++)
  3457. {
  3458. int num = i * 4 + j;
  3459. if (num != dt5.Rows.Count)
  3460. {
  3461. var dr = dt5.Rows[num];
  3462. ICell cellname = irow.CreateCell(2 * (j + 1) - 2);
  3463. cellname.SetCellValue(dr["areaname"].ToString());
  3464. cellname.CellStyle = cellStyle;
  3465. ICell cellcount = irow.CreateCell(2 * (j + 1) - 1);
  3466. cellcount.SetCellValue(Int32.Parse(dr["count"].ToString()));
  3467. cellcount.CellStyle = cellStyle;
  3468. }
  3469. else
  3470. {
  3471. break;
  3472. }
  3473. }
  3474. }
  3475. #endregion
  3476. //自适应列宽度
  3477. for (int i = 0; i < 8; i++)
  3478. {
  3479. sheet.AutoSizeColumn(i);
  3480. }
  3481. using (MemoryStream ms = new MemoryStream())
  3482. {
  3483. workbook.Write(ms);
  3484. HttpContext curContext = HttpContext.Current;
  3485. // 设置编码和附件格式
  3486. curContext.Response.ContentType = "application/vnd.ms-excel";
  3487. curContext.Response.ContentEncoding = Encoding.UTF8;
  3488. curContext.Response.Charset = "";
  3489. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  3490. curContext.Response.AppendHeader("Content-Disposition",
  3491. "attachment;filename=" + HttpUtility.UrlEncode("业务简报_导出文件_" + DateTime.Now.Ticks + ".xls", Encoding.UTF8));
  3492. curContext.Response.BinaryWrite(ms.GetBuffer());
  3493. workbook = null;
  3494. ms.Close();
  3495. ms.Dispose();
  3496. curContext.Response.End();
  3497. }
  3498. return "";
  3499. }
  3500. catch
  3501. {
  3502. return "导出失败!";
  3503. }
  3504. }
  3505. /// <summary>
  3506. /// 弹出下载框导出excel(数据第一行为标题)
  3507. /// </summary>
  3508. /// <param name="Name"></param>
  3509. /// <param name="dt"></param>
  3510. /// <returns></returns>
  3511. public string ExportToExcel2(string Name, DataTable dt, string[] cols = null)
  3512. {
  3513. try
  3514. {
  3515. //if (dt.Rows.Count > 0)
  3516. //{
  3517. HSSFWorkbook workbook = new HSSFWorkbook();
  3518. ISheet sheet = workbook.CreateSheet("Sheet1");
  3519. ICellStyle HeadercellStyle = workbook.CreateCellStyle();
  3520. HeadercellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  3521. HeadercellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  3522. HeadercellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  3523. HeadercellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  3524. HeadercellStyle.Alignment = HorizontalAlignment.Center;
  3525. HeadercellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  3526. HeadercellStyle.FillPattern = FillPattern.SolidForeground;
  3527. HeadercellStyle.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.SkyBlue.Index;
  3528. //字体
  3529. NPOI.SS.UserModel.IFont headerfont = workbook.CreateFont();
  3530. headerfont.Boldweight = (short)FontBoldWeight.Bold;
  3531. headerfont.FontHeightInPoints = 12;
  3532. HeadercellStyle.SetFont(headerfont);
  3533. //用column name 作为列名
  3534. int icolIndex = 0;
  3535. IRow headerRow = sheet.CreateRow(0);
  3536. if (cols == null || (cols != null && cols.Length == 0))
  3537. {
  3538. //foreach (DataColumn dc in dt.Columns)
  3539. //{
  3540. // ICell cell = headerRow.CreateCell(icolIndex);
  3541. // cell.SetCellValue(dc.ColumnName);
  3542. // cell.CellStyle = HeadercellStyle;
  3543. // icolIndex++;
  3544. //}
  3545. for (int i = 0; i < dt.Columns.Count; i++)
  3546. {
  3547. ICell cell = headerRow.CreateCell(icolIndex);
  3548. cell.SetCellValue(dt.Rows[0][i].ToString());
  3549. cell.CellStyle = HeadercellStyle;
  3550. icolIndex++;
  3551. }
  3552. }
  3553. else
  3554. {
  3555. foreach (string dc in cols)
  3556. {
  3557. ICell cell = headerRow.CreateCell(icolIndex);
  3558. cell.SetCellValue(dc);
  3559. cell.CellStyle = HeadercellStyle;
  3560. icolIndex++;
  3561. }
  3562. }
  3563. ICellStyle cellStyle = workbook.CreateCellStyle();
  3564. //为避免日期格式被Excel自动替换,所以设定 format 为 『@』 表示一率当成text來看
  3565. cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("@");
  3566. cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  3567. cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  3568. cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  3569. cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  3570. NPOI.SS.UserModel.IFont cellfont = workbook.CreateFont();
  3571. cellfont.Boldweight = (short)FontBoldWeight.Normal;
  3572. cellStyle.SetFont(cellfont);
  3573. //建立内容行
  3574. int iRowIndex = 0;
  3575. foreach (DataRow dr in dt.Rows)
  3576. {
  3577. if (iRowIndex > 0)
  3578. {
  3579. int iCellIndex = 0;
  3580. IRow irow = sheet.CreateRow(iRowIndex);
  3581. for (int i = 0; i < dt.Columns.Count; i++)
  3582. {
  3583. string strsj = string.Empty;
  3584. if (dr[i] != null)
  3585. {
  3586. strsj = dr[i].ToString();
  3587. }
  3588. ICell cell = irow.CreateCell(iCellIndex);
  3589. cell.SetCellValue(strsj);
  3590. cell.CellStyle = cellStyle;
  3591. iCellIndex++;
  3592. }
  3593. }
  3594. iRowIndex++;
  3595. }
  3596. //自适应列宽度
  3597. for (int i = 0; i < icolIndex; i++)
  3598. {
  3599. sheet.AutoSizeColumn(i);
  3600. }
  3601. using (MemoryStream ms = new MemoryStream())
  3602. {
  3603. workbook.Write(ms);
  3604. HttpContext curContext = HttpContext.Current;
  3605. // 设置编码和附件格式
  3606. curContext.Response.ContentType = "application/vnd.ms-excel";
  3607. curContext.Response.ContentEncoding = Encoding.UTF8;
  3608. curContext.Response.Charset = "";
  3609. curContext.Response.AppendHeader("Access-Control-Expose-Headers", "Content-Disposition");
  3610. curContext.Response.AppendHeader("Content-Disposition",
  3611. "attachment;filename=" + HttpUtility.UrlEncode(Name + ".xls", Encoding.UTF8));
  3612. curContext.Response.BinaryWrite(ms.GetBuffer());
  3613. workbook = null;
  3614. ms.Close();
  3615. ms.Dispose();
  3616. curContext.Response.End();
  3617. }
  3618. //}
  3619. return "";
  3620. }
  3621. catch
  3622. {
  3623. return "导出失败!";
  3624. }
  3625. }
  3626. /// <summary>
  3627. /// 导出word
  3628. /// </summary>
  3629. /// <returns></returns>
  3630. public byte[] ExportToWordDemo()
  3631. {
  3632. try
  3633. {
  3634. //创建document文档对象对象实例
  3635. NPOI.XWPF.UserModel.XWPFDocument document = new NPOI.XWPF.UserModel.XWPFDocument();
  3636. document.CreateParagraph();
  3637. NPOI.XWPF.UserModel.XWPFParagraph paragraph = document.CreateParagraph();//创建段落对象
  3638. paragraph.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.CENTER;//文字显示位置,段落排列(左对齐,居中,右对齐)
  3639. NPOI.XWPF.UserModel.XWPFRun xwpfRun = paragraph.CreateRun();//创建段落文本对象
  3640. xwpfRun.IsBold = true;//文字加粗
  3641. xwpfRun.SetText("安阳市12345政务服务热线交办单");//填充内容
  3642. xwpfRun.FontSize = 18;//设置文字大小
  3643. xwpfRun.SetFontFamily("宋体", NPOI.XWPF.UserModel.FontCharRange.None); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
  3644. document.CreateParagraph();
  3645. //创建文档中的表格对象实例
  3646. NPOI.XWPF.UserModel.XWPFTable table = document.CreateTable(9, 8);//显示的行列数rows:3行,cols:4列
  3647. table.Width = 5200;//总宽度
  3648. table.SetColumnWidth(0, 650); /* 设置列宽 */
  3649. table.SetColumnWidth(1, 650);
  3650. table.SetColumnWidth(2, 650);
  3651. table.SetColumnWidth(3, 650);
  3652. table.SetColumnWidth(4, 650);
  3653. table.SetColumnWidth(5, 650);
  3654. table.SetColumnWidth(6, 650);
  3655. table.SetColumnWidth(7, 650);
  3656. for (int i = 0; i < 9; i++)
  3657. {
  3658. for (int j = 0; j < 8; j++)
  3659. {
  3660. var cp = table.GetRow(i).GetCell(j).GetCTTc().AddNewTcPr();
  3661. cp.AddNewVAlign().val = ST_VerticalJc.center;
  3662. }
  3663. }
  3664. //第一行
  3665. table.GetRow(0).GetCTRow().AddNewTrPr().AddNewTrHeight().val= (ulong)300;
  3666. var cp0 = table.GetRow(0).GetCell(0).GetCTTc().AddNewTcPr();
  3667. cp0.AddNewVMerge().val = ST_Merge.restart;
  3668. cp0.AddNewVAlign().val = ST_VerticalJc.center;
  3669. cp0.tcW = new CT_TblWidth();cp0.tcW.w = "650";cp0.tcW.type = ST_TblWidth.dxa;
  3670. table.GetRow(0).GetCell(0).SetParagraph(GetParagraph(table, true, "事项编号"));
  3671. var cp1 = table.GetRow(0).GetCell(1).GetCTTc().AddNewTcPr();
  3672. cp1.AddNewVMerge().val = ST_Merge.restart;
  3673. cp1.AddNewVAlign().val = ST_VerticalJc.center;
  3674. table.GetRow(0).GetCell(1).SetParagraph(GetParagraph(table, false, "DH9941052721041200351"));
  3675. table.GetRow(0).GetCell(2).SetParagraph(GetParagraph(table, true, "工单来源"));
  3676. table.GetRow(0).GetCell(3).SetParagraph(GetParagraph(table, false, "市长电话"));
  3677. table.GetRow(0).GetCell(4).SetParagraph(GetParagraph(table, true, "办理时限"));
  3678. table.GetRow(0).GetCell(5).SetParagraph(GetParagraph(table, false, "2021-04-21"));
  3679. table.GetRow(0).GetCell(6).SetParagraph(GetParagraph(table, true, "联系电话"));
  3680. table.GetRow(0).GetCell(7).SetParagraph(GetParagraph(table, false, "017185328292"));
  3681. //第二行
  3682. table.GetRow(1).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)300;
  3683. var cp2 = table.GetRow(1).GetCell(0).GetCTTc().AddNewTcPr();
  3684. cp2.AddNewVMerge().val = ST_Merge.@continue;
  3685. var cp3 = table.GetRow(1).GetCell(1).GetCTTc().AddNewTcPr();
  3686. cp3.AddNewVMerge().val = ST_Merge.@continue;
  3687. table.GetRow(1).GetCell(2).SetParagraph(GetParagraph(table, true, "签收时间"));
  3688. table.GetRow(1).GetCell(3).SetParagraph(GetParagraph(table, false, "2021-04-12"));
  3689. table.GetRow(1).GetCell(4).SetParagraph(GetParagraph(table, true, "办理时间"));
  3690. table.GetRow(1).GetCell(5).SetParagraph(GetParagraph(table, false, "2021-04-12"));
  3691. table.GetRow(1).GetCell(6).SetParagraph(GetParagraph(table, true, "来电人"));
  3692. table.GetRow(1).GetCell(7).SetParagraph(GetParagraph(table, false, "徐青田"));
  3693. //第三行
  3694. table.GetRow(2).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)300;
  3695. table.GetRow(2).MergeCells(1, 7);//合并列
  3696. table.GetRow(2).GetCell(0).SetParagraph(GetParagraph(table, true, "事项区域"));
  3697. table.GetRow(2).GetCell(1).SetParagraph(GetParagraph(table, false, "河南省郑州市高新技术开发区大学科技园东区", false));
  3698. //第四行
  3699. table.GetRow(3).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)2000;
  3700. table.GetRow(3).MergeCells(1, 7);//合并列
  3701. table.GetRow(3).GetCell(0).SetParagraph(GetParagraph(table, true, "内容摘要"));
  3702. table.GetRow(3).GetCell(1).SetParagraph(GetParagraph(table, false, "来电人反映:内黄县城关镇宛庄村第四生产队第二、三小组土地至今无法确权(遗留问题),村委会和镇政府承诺给解决,至今未解决,请政府责成相关部门调查处理。", false));
  3703. //第五行
  3704. table.GetRow(4).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)300;
  3705. table.GetRow(4).MergeCells(1, 4);//合并列
  3706. table.GetRow(4).MergeCells(3, 4);//合并列
  3707. table.GetRow(4).GetCell(0).SetParagraph(GetParagraph(table, true, "承办单位"));
  3708. table.GetRow(4).GetCell(1).SetParagraph(GetParagraph(table, false, "内黄县政府"));
  3709. table.GetRow(4).GetCell(2).SetParagraph(GetParagraph(table, true, "协办单位"));
  3710. table.GetRow(4).GetCell(3).SetParagraph(GetParagraph(table, false, "内黄县政府"));
  3711. //第六行
  3712. table.GetRow(5).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)2000;
  3713. table.GetRow(5).MergeCells(1, 7);//合并列
  3714. table.GetRow(5).GetCell(0).SetParagraph(GetParagraph(table, true, "调度意见"));
  3715. table.GetRow(5).GetCell(1).SetParagraph(GetParagraph(table, false, "请按领导批示认真调查处理并答复来电人,在5个工作日内通过网络反馈市市长热线办公室。要求注明主办人、主管领导姓名和联系电话,同时提供有关处理依据。", false));
  3716. //第七行
  3717. table.GetRow(6).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)1500;
  3718. table.GetRow(6).MergeCells(1, 7);//合并列
  3719. table.GetRow(6).GetCell(0).SetParagraph(GetParagraph(table, true, "承办意见"));
  3720. table.GetRow(6).GetCell(1).SetParagraph(GetParagraph(table, false, "请按领导批示认真调查处理并答复来电人,在5个工作日内通过网络反馈市市长热线办公室。要求注明主办人、主管领导姓名和联系电话,同时提供有关处理依据。", false));
  3721. //第八行
  3722. table.GetRow(7).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)1500;
  3723. table.GetRow(7).MergeCells(1, 7);//合并列
  3724. table.GetRow(7).GetCell(0).SetParagraph(GetParagraph(table, true, "领导批示"));
  3725. table.GetRow(7).GetCell(1).SetParagraph(GetParagraph(table, false, "请按领导批示认真调查处理并答复来电人,在5个工作日内通过网络反馈市市长热线办公室。要求注明主办人、主管领导姓名和联系电话,同时提供有关处理依据。", false));
  3726. //第九行
  3727. table.GetRow(8).GetCTRow().AddNewTrPr().AddNewTrHeight().val = (ulong)2000;
  3728. table.GetRow(8).MergeCells(1, 7);//合并列
  3729. table.GetRow(8).GetCell(0).SetParagraph(GetParagraph(table, true, "处理结果"));
  3730. table.GetRow(8).GetCell(1).SetParagraph(GetParagraph(table, false, "2021-04-12 10:19:14 内黄县政府部门接到市长电话来源工单(编号:DH9941052721041200351)反映土地确权问题,已联系郑州第三方中标土地确权公司负责人待工作人员到我县后,就可以确权 [办理结果:已办理,承办人:刘志强,职务:城关镇人大主席,联系电话:15824608111,刘志强向当事人进行了反馈,当事人对结果表示未评价。]", false));
  3731. document.CreateParagraph();
  3732. NPOI.XWPF.UserModel.XWPFParagraph paragraph1 = document.CreateParagraph();//创建段落对象
  3733. paragraph1.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.CENTER;//文字显示位置,段落排列(左对齐,居中,右对齐)
  3734. NPOI.XWPF.UserModel.XWPFRun xwpfRun1 = paragraph1.CreateRun();//创建段落文本对象
  3735. xwpfRun1.IsBold = true;//文字加粗
  3736. xwpfRun1.SetText("联系电话:(0372) 12345审核人:8000 调度员:8065");//填充内容
  3737. xwpfRun1.FontSize = 9;//设置文字大小
  3738. xwpfRun1.SetFontFamily("宋体", NPOI.XWPF.UserModel.FontCharRange.None); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
  3739. NPOI.XWPF.UserModel.XWPFParagraph paragraph2 = document.CreateParagraph();//创建段落对象
  3740. paragraph2.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.RIGHT;//文字显示位置,段落排列(左对齐,居中,右对齐)
  3741. NPOI.XWPF.UserModel.XWPFRun xwpfRun2 = paragraph2.CreateRun();//创建段落文本对象
  3742. using (FileStream picData = new FileStream(HttpContext.Current.Server.MapPath("/Upload/Word/word.png"), FileMode.Open, FileAccess.Read))
  3743. {
  3744. //图片的文件流 图片类型 图片名称 设置的宽度以及高度
  3745. xwpfRun2.AddPicture(picData, (int)PictureType.PNG, "word.png", NPOI.Util.Units.ToEMU(100), NPOI.Util.Units.ToEMU(100));
  3746. }
  3747. using (MemoryStream ms = new MemoryStream())
  3748. {
  3749. document.Write(ms);
  3750. return ms.GetBuffer();
  3751. }
  3752. }
  3753. catch(Exception ex)
  3754. {
  3755. return null;
  3756. }
  3757. }
  3758. /// <summary>
  3759. ///
  3760. /// </summary>
  3761. /// <param name="document"></param>
  3762. /// <param name="isbold"></param>
  3763. /// <param name="content"></param>
  3764. /// <returns></returns>
  3765. private NPOI.XWPF.UserModel.XWPFParagraph GetParagraph(NPOI.XWPF.UserModel.XWPFTable table,bool isbold,string content, bool iscenter=true)
  3766. {
  3767. var para = new CT_P();
  3768. //设置单元格文本对齐
  3769. para.AddNewPPr().AddNewTextAlignment();
  3770. NPOI.XWPF.UserModel.XWPFParagraph paragraph = new NPOI.XWPF.UserModel.XWPFParagraph(para,table.Body);
  3771. paragraph.VerticalAlignment = NPOI.XWPF.UserModel.TextAlignment.CENTER;
  3772. if (iscenter)
  3773. {
  3774. paragraph.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.CENTER;
  3775. }
  3776. else
  3777. {
  3778. paragraph.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.LEFT;
  3779. }
  3780. NPOI.XWPF.UserModel.XWPFRun xwpfRun = paragraph.CreateRun();//创建段落文本对象
  3781. xwpfRun.IsBold = isbold;//文字加粗
  3782. xwpfRun.SetText(content);//填充内容
  3783. xwpfRun.FontSize = 9;//设置文字大小
  3784. xwpfRun.SetFontFamily("宋体", NPOI.XWPF.UserModel.FontCharRange.None); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
  3785. return paragraph;
  3786. }
  3787. /// <summary>
  3788. /// 插入图片
  3789. /// </summary>
  3790. /// <param name="table"></param>
  3791. /// <returns></returns>
  3792. private NPOI.XWPF.UserModel.XWPFParagraph GetParagraphImg(NPOI.XWPF.UserModel.XWPFTable table, bool isbold, string content, bool iscenter = true)
  3793. {
  3794. var para = new CT_P();
  3795. //设置单元格文本对齐
  3796. para.AddNewPPr().AddNewTextAlignment();
  3797. NPOI.XWPF.UserModel.XWPFParagraph paragraph = new NPOI.XWPF.UserModel.XWPFParagraph(para, table.Body);
  3798. paragraph.VerticalAlignment = NPOI.XWPF.UserModel.TextAlignment.CENTER;
  3799. if (iscenter)
  3800. {
  3801. paragraph.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.CENTER;
  3802. }
  3803. else
  3804. {
  3805. paragraph.Alignment = NPOI.XWPF.UserModel.ParagraphAlignment.LEFT;
  3806. }
  3807. NPOI.XWPF.UserModel.XWPFRun xwpfRun = paragraph.CreateRun();//创建段落文本对象
  3808. xwpfRun.IsBold = isbold;//文字加粗
  3809. xwpfRun.SetText(content);//填充内容
  3810. xwpfRun.FontSize = 9;//设置文字大小
  3811. xwpfRun.SetFontFamily("宋体", NPOI.XWPF.UserModel.FontCharRange.None); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
  3812. using (FileStream picData = new FileStream(HttpContext.Current.Server.MapPath("/Upload/Word/word.png"), FileMode.Open, FileAccess.Read))
  3813. {
  3814. //图片的文件流 图片类型 图片名称 设置的宽度以及高度
  3815. xwpfRun.AddPicture(picData, (int)PictureType.PNG, "word.png", NPOI.Util.Units.ToEMU(100), NPOI.Util.Units.ToEMU(100));
  3816. }
  3817. return paragraph;
  3818. }
  3819. }
  3820. }