Skip to main content

Posts

Showing posts with the label EPPlus

How to convert a column number (eg. 127) into an excel column (eg. AA)

private string GetExcelColumnName ( int columnNumber ) { int dividend = columnNumber ; string columnName = String . Empty ; int modulo ; while ( dividend > 0 ) { modulo = ( dividend - 1 ) % 26 ; columnName = Convert . ToChar ( 65 + modulo ). ToString () + columnName ; dividend = ( int )(( dividend - modulo ) / 26 ); } return columnName ; } Ref:  http://stackoverflow.com/questions/181596/how-to-convert-a-column-number-eg-127-into-an-excel-column-eg-aa

How to download .xslx File from server using EPPlus and MVC - stream Response

All you need to do is reset the stream position.  stream.Position = 0; You  shouldn't write directly to the Response , it's not the MVC way. It doesn't follow the correct MVC pipeline and it tightly couples your controller action code to the Response object. When you add a file name as the 3rd parameter in  File() , MVC automatically adds the correct  Content-Disposition  header... so you shouldn't need to add it manually. The short of it is, this is what you want: public ActionResult Index () { using ( ExcelPackage package = new ExcelPackage ()) { // I populate the worksheet here. I'm 90% sure this is fine // because the stream file size changes based on what I pass to it. var stream = new MemoryStream (); package . SaveAs ( stream ); string fileName = "myfilename.xlsx" ; string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet...