Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to read cells with % symbol #1688

Open
NiranjanGodboleMaersk opened this issue Mar 11, 2024 · 0 comments
Open

Unable to read cells with % symbol #1688

NiranjanGodboleMaersk opened this issue Mar 11, 2024 · 0 comments

Comments

@NiranjanGodboleMaersk
Copy link

I am working on Net core with Open XML. In my excel there is value 100%. I am trying to read as below

GetCellValue method

public static string GetCellValue(SpreadsheetDocument doc, Cell cell)
{
    if (cell.CellValue != null)
    {
        string value = cell.CellValue.InnerText;
        if (cell.DataType != null && cell.DataType.Value == CellValues.SharedString)
        {
            return doc.WorkbookPart.SharedStringTablePart.SharedStringTable.ChildElements.ElementAt(int.Parse(value)).InnerText;
        }
        else
        {
            return value;
        }
    }
    return string.Empty;
}

GetCell method

public static Cell GetCell(Worksheet worksheet, string columnName, uint rowIndex)
 {
     Row row = worksheet.GetFirstChild<SheetData>().Elements<Row>().FirstOrDefault(r => r.RowIndex == rowIndex);

     if (row != null)
     {
         return row.Elements<Cell>().FirstOrDefault(c => string.Compare(c.CellReference.Value, columnName + rowIndex, true) == 0);
     }
     return null;
 }

I am reading as below.

var data = OpenXmlReader.GetCellValue(spreadsheetDocument, OpenXmlReader.GetCell(workSheet, "E", 11));

The data is coming as 1 whereas actual value in my excel is 100%. I am not sure why this is not properly reading. Can someone please help me? Any help would be appreciated. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant