暫無描述

NPOIHelper.cs 183KB

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