Bez popisu

NPOIHelper.cs 194KB

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