Search code examples
excelcellspreadsheetlight

SpreadsheetLight get an excel cell value beginning with aposthrope


When I read an excel cell value using SpreadsheetLight - I get the cell value without the leading apostrophe. When the cell value is 'Something I only get Something. I understand that the apostrophe has a special meaning for excel - but I really need that char! :)

How to detect when a cell has a leading apostrophe? I use the GetCellValueAsString(...) function to retrieve cell value.


Solution

  • The leading apostrophe went to the cell style data to the QuotePrefix property.

    if (sl.HasCellValue(rowIndex, i + 1))
    {
        var style = sl.GetCellStyle(rowIndex, i + 1);
        var text= sl.GetCellValueAsString(rowIndex, i + 1);
        Row[i] = (style.QuotePrefix.HasValue && style.QuotePrefix.Value) ? "'" + text : text;
    }