I am Replacing Inteop with Aspose.Cells for reading .xlsx files in .Net. Interop Gives error code whenever any error occurs in formula evaluation while aspose giving me error text in case of errors.
I want aspose should also give me error code like interop
[“Diff_R_C(2,2): InterOP=‘-2146826246’ vs Aspsoer=‘#N/A’”]
What the context tells us
- The forum post only states the problem (Interop returns a numeric error code such as ‑2146826246, Aspose.Cells returns the error text “#N/A”).
- No answer or documentation excerpt is provided that shows Aspose.Cells can return a numeric error code.
What can be said based on Aspose.Cells behavior
- Aspose.Cells represents formula‑evaluation errors as the standard Excel error strings (e.g.,
#N/A,#DIV/0!,#VALUE!). - These strings are exposed through the
CellErrorValueclass (e.g.,CellErrorValue.NA,CellErrorValue.Div0). - There is no built‑in numeric error code equivalent to the COM‑Interop HRESULT values.
How to obtain a comparable “code” in Aspose.Cells
// after loading the workbook and calculating formulas
Cell cell = worksheet.Cells["B2"]; // cell that may contain an error
if (cell.Type == CellValueType.IsError) // error detected
{
string errText = cell.StringValue; // e.g. "#N/A"
// map the error text to your own numeric code
int errCode = errText switch
{
CellErrorValue.NA => -2146826246, // example mapping you choose
CellErrorValue.Div0 => -2146826259,
CellErrorValue.Value => -2146826260,
// add other mappings as needed
_ => 0
};
Console.WriteLine($"Error code: {errCode}");
}
- Step 1 – Check
cell.Type == CellValueType.IsError. - Step 2 – Read the error string via
cell.StringValue(or compare withCellErrorValueconstants). - Step 3 – Translate that string to any numeric code you need (e.g., the Interop HRESULTs) using a simple
switch/dictionary.
Bottom line
Aspose.Cells does not expose the same numeric error codes that Interop returns; it provides the error text. To get a numeric code you must map the error strings yourself.
The forum excerpt does not contain an official Aspose.Cells feature that returns numeric error codes, so the above is the recommended workaround.
Aspose.Cells may not have a built-in feature to return the exact numeric error codes used by Excel Interop (HRESULTs). The library provides specific enums and text representations for formula errors. I think you will need to create a mapping logic in your code by yourselves to convert the Aspose.Cells error type or text into the corresponding Interop error code.