c# - How to make cell formatting faster for large worksheets in EPPlus -
i have c# data processing application uses epplus write final results excel sheet. background color of rows changed based on data on row signifies. time never issue dealt files below <100mb before. however, requirements have changed , files larger, have noticed that.. coloring makes application 60% slower. removing coloring makes application faster. snippet below example of code use color data make visually distinguishing. i'm no expert @ epplus there way, can optimized make application faster? or there better ways me make rows visually distinct people end looking @ data? appreciated!
if (data[4] == "3") { // color type 3 messages here var fill1 = cell1.style.fill; fill1.patterntype = excelfillstyle.solid; fill1.backgroundcolor.setcolor(color.lightgray); } if (data[4] == "4") { var fill1 = cell1.style.fill; fill1.patterntype = excelfillstyle.solid; fill1.backgroundcolor.setcolor(color.blanchedalmond); } edit:
this code use copy template , write excel data new worksheet. p excel package convert byte array before writing excel file.
byte[] bin = p.getasbytearray(); file.copy("c:\\users\\mpas\\desktop\\template.xlsx", "c:\\users\\mpas\\desktop\\result.xlsx"); using (filestream fs = file.openwrite("c:\\users\\mpas\\desktop\\result.xlsx")) { fs.write(bin, 0, bin.length); }
here code open existing file.
fileinfo addresslist = new fileinfo("c:\test\test.xlsx"); // open , read xlsx file. try { using (excelpackage package = new excelpackage(addresslist)) { // work book in file excelworkbook workbook = package.workbook; if (workbook != null) { if (workbook.worksheets.count > 0) { // first worksheet //excelworksheet worksheet = workbook.worksheets.first(); var worksheet = package.workbook.worksheets[1];
Comments
Post a Comment