Apparently Shapes.UpdateSelectedValue() throws a null exception in certain circumstances.
How do I mitigate this? Any solutions?
repo code:
private void test()
{
using (FileStream ms = new FileStream(@"C:\\tmp\test.xlsx", FileMode.Open))
{
cells.Workbook wb = new cells.Workbook(ms);
int activeIndex = wb.Worksheets.ActiveSheetIndex;
cells.CalculationOptions opts = new cells.CalculationOptions();
opts.Recursive = true;
opts.IgnoreError = false;
wb.CalculateFormula(opts);
cells.Worksheet sheet = wb.Worksheets[activeIndex];
sheet.CalculateFormula(opts, true);
sheet.Shapes.UpdateSelectedValue(); // <-- throws null exception error
// you can find which shape is the culprit by iterating shapes and calling UpdateSelectedValue() on each one
foreach (var shape in sheet.Shapes)
{
try
{
if (shape.Name == "Picture 14") // <-- this shape throws error
{
shape.UpdateSelectedValue();
}
}
catch (Exception)
{
Console.Write(ex);
}
}
}
}
Spreadsheet file is attached.
test.xlsx
{“Object reference not set to an instance of an object.”}
Data: {System.Collections.ListDictionaryInternal}
HResult: -2147467261
HelpLink: null
InnerException: null
Message: “Object reference not set to an instance of an object.”
Source: “Aspose.Cells”
StackTrace: " at Aspose.Cells.Charts.Chart.\u000e(Int32 \u0002)\r\n at Aspose.Cells.Drawing.ShapeCollection.\u0003 (Int32 \u0002)\r\n at Aspose.Cells.Drawing.ShapeCollection.\u0002 (Int32 \u0002)\r\n at Aspose.Cells.Drawing.ShapeCollection.\u0006(Int32 \u0002)\r\n at Aspose.Cells.Drawing.Picture.\u0002(Byte[] \u0002)\r\n at Aspose.Cells.Drawing.Shape.UpdateSelectedValue()\r\n at IE.Cloud.Common.Open