Handle the case where the formula starts with "=+". Detailed information: https://professor-excel.com/equal-plus-excel-formulas/
Workaround: replace the "=+" with "="
CellRange usedCellRange = workbook.Worksheets[0].UsedCellRange;
for (int rowIndex = usedCellRange.FromIndex.RowIndex; rowIndex <= usedCellRange.ToIndex.RowIndex; rowIndex++)
{
for (int columnIndex = usedCellRange.FromIndex.ColumnIndex; columnIndex <= usedCellRange.ToIndex.ColumnIndex; columnIndex++)
{
CellSelection cell = workbook.Worksheets[0].Cells[rowIndex, columnIndex];
FormulaCellValue formulaCellValue =cell.GetValue().Value as FormulaCellValue;
if (formulaCellValue == null)
{
continue;
}
CellValueFormat format = cell.GetFormat().Value;
string resultValueAsString = formulaCellValue.GetValueAsString(format);
Console.WriteLine(resultValueAsString);
if (resultValueAsString.StartsWith("=+"))
{
resultValueAsString = resultValueAsString.Remove(1, 1);
cell.SetValue(resultValueAsString);
}
}
}
radSpreadsheet.Workbook = workbook;