excel - How to get format type of cell using c# in spreadsheetlight -


i using spreadsheetlight library read excelsheet(.xslx) values using c#.

i can read cell value using following code

 (int col = stats.startcolumnindex; col <= stats.endcolumnindex; col++)      {                        var value= sheet.getcellvalueasstring(stats.startrowindex, col);  //where sheet current sheet in excel file          } 

i getting cell value. how can data type of cell. have checked in documentation dint filnd solution.

note: .xls type of excel files using excellibrary.dll library can datatype of cells using below code

for (int = 0; <= cells.lastcolindex; i++)      {          var type = cells[0, i].format.formattype;      } 

but no similar method there in spreadsheetlight.

thanks in advance.

here answer developer vincent tang after asked him wasn't sure how use datatype:


yes use slcell.datatype. it's enumeration, data, you'll working number, sharedstring , string.

text data sharedstring, , possibly string if text directly embedded in worksheet. there's getsharedstrings() or that.

for numeric data, number.

for dates, it's little tricky. data type number (ignore date enumeration because microsoft excel isn't using it). dates, have check formatcode, in slstyle slcell. use getstyles() list. slcell.styleindex gives index list.

for example, if slcell has cell value "15" , data type sharedstring, index 15 in list of shared strings. if it's "blah" string data type, that's it.

if it's 56789 number type, that's it.

unless formatcode "mm-yyyy" (or other date format code), 56789 number of days since 1 jan 1900.


he recommended using getcelllist() in order obtain list of slcell objects in sheet. however, reason function not available in version of sl, used getcells() instead. returns dictionary of slcell objects, keys of type slcellpoint.

so example datatype (which cellvalues object) of cell a1 this:

using (sldocument sldoc = new sldocument("worksheet1.xlsx", "sheet1")) {      slcp = slcellpoint;     slcp.columnindex = slconvert.tocolumnindex("a"); ///obviously 1 useful function know     slcp.rowindex = 1;      cellvalues slcv = sldoc.getcells(slcp).datatype;  } 

by way, had problem opening chm file. try this:

  • right click on chm file , select properties
  • click on unblock button @ bottom of general tab

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -