Nessuna descrizione

NPOIHelper.cs 213KB

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