excel - Unable to change cell background colour, EPPlus in C# -


i'm trying verify cell in row not null. if null, want change background colour of cell red. after reading how that, have come following code:

public int verifyimportfile(fileupload fup)     {         int status = 0;         //check if there file being uploaded         if (fup.hasfile)         {             //load uploaded file memorystream             using (memorystream stream = new memorystream(fup.filebytes))             //lets server know use excel package             using (excelpackage xlpackage = new excelpackage(stream))             {                 //gets first worksheet in workbook                 excelworksheet worksheet = xlpackage.workbook.worksheets[1];                 //gets row count                 var rowcnt = worksheet.dimension.end.row;                 //gets column count                 var colcnt = worksheet.dimension.end.column;                 //beginning loop data gathering                 (int = 2; < rowcnt; i++) //starts on 2 because excel starts @ 1, , line 1 headers                 {                     //if there no value in column 3, proceed                     if (worksheet.cells[i, 3].value == null)                     {                         worksheet.cells[i, 3].style.fill.patterntype = excelfillstyle.solid;                         worksheet.cells[i,3].style.fill.backgroundcolor.setcolor(color.red);                         status = 1;                     }                                         }                 xlpackage.save();             }                        }         return status;     } 

what know testing if null value found, enters if statement checks nulls. seems running code change background colour. after loops through entire excel sheet, variable status change 1 , displayed in popup. understanding of how this, running background colour stays white.

your code correct far setting background color assuming being hit have confirmed.

but how saving out file? once load memorystream connection original byte array severed. need saveas() or getasbytearray() call this:

xlpackage.saveas(new fileinfo(@"c:\temp\myfile.xls")); 

calling save() writes memorystream.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -