Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Jan 11, 2024 2:56 am

Error:
Unable to cast object of type 'sprἾ' to type 'sprἿ'.
at sprợ.᝗()
at sprᾸ.ᜎ()
at sprᶣ.ᜁ()
at sprᶣ.ᜁ(sprᵷ A_0)
at sprᶣ.ᜀ(Stream A_0, spr⃒ A_1)
at Spire.Xls.Workbook.SaveToFile(String fileName, ExcelVersion version)

The error message is shown above.
Please help check the reason of this error.

Shea_0901
 
Posts: 2
Joined: Thu Jan 11, 2024 2:49 am

Thu Jan 11, 2024 6:11 am

Hello,

Thank you for your inquiry.
Currently, our latest version of Spire.XLS is Spire.XLS Pack Version: 14.1. Could you please confirm if you have tested using this version? If not, I recommend upgrading to this version before conducting further tests.
If the issue persists after testing with the latest version, we would appreciate it if you could provide the following information to assist us in investigating the problem more effectively.You could attach them here or send them to us via email (support@e-iceblue.com). Thanks in advance.
1) Your input Excel file.
2) Your complete test code.
3) Your test environment, such as OS info (E.g. Windows 7, 64-bit) and region setting (E.g. China, Chinese).
4) Your application type, such as Console app (. Net Framework 4.5).

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1652
Joined: Wed Apr 07, 2021 2:50 am

Thu Jan 11, 2024 6:28 am

Sorry, I forgot to say the context. I created a chart in a sheet and added the Error bar, the type is custom.
Then I made a copy of the sheet and then used savetofile and this issue came up.
When the type of error bar is other types, this issue will not appear.

Shea_0901
 
Posts: 2
Joined: Thu Jan 11, 2024 2:49 am

Thu Jan 11, 2024 7:24 am

Hello,

Thank you for your feedback.
Based on your description, I have used the following code to create a chart and add a custom Error bar. I then made a copy of the sheet without encountering the issue you mentioned.
Code: Select all
// Create a new workbook object
Workbook workbook = new Workbook();

// Create an empty sheet in the workbook
workbook.CreateEmptySheets(1);

// Get the reference to the first sheet in the workbook
Worksheet sheet = workbook.Worksheets[0];

// Set the name of the sheet to "Primeval"
sheet.Name = "Primeval";

// Set the value of cell A1 to "Month"
sheet.Range["A1"].Value = "Month";
sheet.Range["A2"].Value = "Jan.";
sheet.Range["A3"].Value = "Feb.";
sheet.Range["A4"].Value = "Mar.";
sheet.Range["A5"].Value = "Apr.";
sheet.Range["A6"].Value = "May.";
sheet.Range["A7"].Value = "Jun.";

// Set the value of cell B1 to "Planned"
sheet.Range["B1"].Value = "Planned";
sheet.Range["B2"].NumberValue = 3.3;
sheet.Range["B3"].NumberValue = 2.5;
sheet.Range["B4"].NumberValue = 2.0;
sheet.Range["B5"].NumberValue = 3.7;
sheet.Range["B6"].NumberValue = 4.5;
sheet.Range["B7"].NumberValue = 4.0;

// Add a line chart to the sheet
Chart chart = sheet.Charts.Add(ExcelChartType.Line);

// Set the data range for the chart to column B (values only)
chart.DataRange = sheet.Range["B1:B7"];

// Disable automatic series data detection from the range
chart.SeriesDataFromRange = false;

// Specify the location of the chart within the sheet
chart.TopRow = 8;
chart.BottomRow = 25;
chart.LeftColumn = 2;
chart.RightColumn = 9;

// Set the title of the chart to "Error Bar Custom"
chart.ChartTitle = "Error Bar Custom";

// Customize the appearance of the chart title
chart.ChartTitleArea.IsBold = true;
chart.ChartTitleArea.Size = 12;

// Get the reference to the first series in the chart
Spire.Xls.Charts.ChartSerie cs1 = chart.Series[0];

// Set the category labels for the series from range A2:A7
cs1.CategoryLabels = sheet.Range["A2:A7"];

// Enable error bars for the series and specify their type
var eb = cs1.ErrorBar(true, ErrorBarIncludeType.Both);
eb.Type = ErrorBarType.Custom;

// Specify the range for the positive error bars
eb.PlusRange = sheet.Range["B5"];

// Specify the range for the negative error bars
eb.MinusRange = sheet.Range["B2"];

// Add a new worksheet named "MySheet" to the workbook
Worksheet sheet1 = workbook.Worksheets.Add("MySheet");

// Copy the contents of the "Primeval" sheet to the new sheet
sheet1.CopyFrom(sheet);

// Save the workbook to a file named "AddCustomErrorBars.xlsx" in Excel 2010 format
string output = "AddCustomErrorBars.xlsx";
workbook.SaveToFile(output, ExcelVersion.Version2010);

To further investigate the issue with your document, we kindly request you to provide us with the complete testing code and the sample Excel file (if available). This will greatly assist us in identifying the cause of the problem and finding an appropriate solution. You could attach them here or send them to us via email (support@e-iceblue.com). Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1652
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS