Sin descripción

NPOIHelper.cs 193KB

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