説明なし

NPOIHelper.cs 185KB

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