asp.net - How do I change the format of a specific column in EPPlus? -


i've used epplus download datatable website / database excel sheet , first picture result get. second picture be.

questions:

  • how change format of timestamp "time"?

obviously title still string format.

  • how make width of columns match longest word inside?

so 80% of message isn't hidden , have drag column out read entire message.

edit: forgot add code...

public actionresult exportdata()         {             datatable datatable = getdata();              using (excelpackage package = new excelpackage())             {                 var ws = package.workbook.worksheets.add("my sheet");                 //true generates headers                 ws.cells["1:1"].style.font.bold = true;                 ws.cells["a1"].loadfromdatatable(datatable, true);                 ws.cells[ws.dimension.address].autofitcolumns();                  var stream = new memorystream();                 package.saveas(stream);                  string filename = "log.xlsx";                 string contenttype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";                  stream.position = 0;                 return file(stream, contenttype, filename);             }         }          public datatable getdata()         {             datatable dt = new datatable();              if (modelstate.isvalid)             {                 using (sqlconnection conn = new sqlconnection(system.configuration.configurationmanager.connectionstrings["mysqlconnection"].connectionstring))                 {                     using (sqlcommand comm = conn.createcommand())                     {                         comm.parameters.addwithvalue("@val1", session["myid"]);                         comm.parameters.addwithvalue("@val2", "%" + session["mysearchstring"] + "%");                         comm.commandtext = "select * dbo.log customerid = @val1 , message @val2";                         try                         {                             conn.open();                             dt.load(comm.executereader());                         }                         catch (sqlexception e)                         {                             throw new exception(e.tostring());                         }                     }                 }             }             return dt;         } 

enter image description here

enter image description here

just need set numberformat.format string. this:

ws.column(2).style.numberformat.format = "hh:mm:ss"; 

if want customize actual there plenty of resource online http://www.ozgrid.com/excel/excel-custom-number-formats.htm. or can open in excel, set format custom , experiment string.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -