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.

Wed Nov 13, 2019 2:29 pm

dear sir/madan
can you help for solving this error "Object reference not set to an instance of an object Error in calculating cell A16 in Worksheet 1' "
The error is on sheet.saveToPdf line, it stops and pop up the above error.

this is my code/

Spire.Xls.Workbook workbook = new Spire.Xls.Workbook();
workbook.LoadFromFile("C:/Users/User1/Desktop/t2.xls");
Spire.Xls.Worksheet sheet = workbook.Worksheets[11];
sheet.SaveToPdf(@"raporlama1", Spire.Xls.FileFormat.PDF);

I will be glad for helping

hafizullah.ozgur
 
Posts: 7
Joined: Wed Nov 13, 2019 1:28 pm

Thu Nov 14, 2019 3:15 am

Hi,

Thanks for your inquiry.
Please provide your input file for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Nov 14, 2019 6:39 am

I tried to write into veriler sheet by below code then, tried to read the written values. while reading the values from the sheet, the error pops up,

Range row1 = worksheet.Rows.Cells[5, 2];
Range row2 = worksheet.Rows.Cells[6, 2];
Range row3 = worksheet.Rows.Cells[7, 2];
Range row4 = worksheet.Rows.Cells[8, 2];
Range row5 = worksheet.Rows.Cells[5, 3];
Range row6 = worksheet.Rows.Cells[6, 3];
Range row7 = worksheet.Rows.Cells[7, 3];
Range row8 = worksheet.Rows.Cells[8, 3];
Range row9 = worksheet.Rows.Cells[14, 2];
Range row10 = worksheet.Rows.Cells[15, 2];
Range row11 = worksheet.Rows.Cells[16, 2];
Range row12 = worksheet.Rows.Cells[14, 3];
Range row13 = worksheet.Rows.Cells[15, 3];
Range row14 = worksheet.Rows.Cells[16, 3];
Range row15 = worksheet.Rows.Cells[21, 2];
Range row16 = worksheet.Rows.Cells[25, 2];
Range row17 = worksheet.Rows.Cells[28, 2];
Range row18 = worksheet.Rows.Cells[32, 2];
Range row19 = worksheet.Rows.Cells[33, 2];
Range row20 = worksheet.Rows.Cells[34, 2];

row1.Value = txt1.Text;
row2.Value = txt2.Text;
row3.Value = txt3.Text;
row4.Value = txt4.Text;
row5.Value = txt5.Text;
row6.Value = txt6.Text;
row7.Value = txt7.Text;
row8.Value = txt8.Text;
row9.Value = txt9.Text;
row10.Value = txt10.Text;
row11.Value = txt11.Text;
row12.Value = txt12.Text;
row13.Value = txt13.Text;
row14.Value = txt14.Text;
row15.Value = txt15.Text;
row16.Value = txt16.Text;
row17.Value = txt17.Text;
row18.Value = txt18.Text;
row19.Value = txt19.Text;
row20.Value = txt20.Text;

excel.Application.ActiveWorkbook.Save();
excel.Application.Quit();
excel.Quit();
Marshal.FinalReleaseComObject(workbook);
Marshal.FinalReleaseComObject(worksheet);
Marshal.FinalReleaseComObject(excel);
Attachments
t2.rar
(26.51 KiB) Downloaded 216 times

hafizullah.ozgur
 
Posts: 7
Joined: Wed Nov 13, 2019 1:28 pm

Thu Nov 14, 2019 9:38 am

Hi,

Thanks for your information.
1. About the error "Object reference not set to an instance of an object Error in calculating cell A16 in Worksheet 1", I have tested your file with the latest Spire.XLS Pack(Hotfix) Version:9.11.2, but didn't encounter any issue. Please try to use the latest one. Besides, the parameter [FileFormat] is useless, please directly use SaveToPdf("result.pdf").

2. About the error "System.Runtime.InteropServices.InvalidComObjectException: 'COM object that has been separated from its underlying RCW cannot be used.'", based on your information, it seems the issue is not caused by Spire.XLS since there is no Spire code in the code snippet you provided. If I misunderstood, please provide an executable project to help us reproduce your issue directly.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.XLS