Error putting a value into a cell

I have this code:

var sheet = _book.Worksheets[0];

var row = sheet.Cells.Rows[_data.RowIndex + 1];

row.GetCellByIndex(0).PutValue(record.Column1);

row.GetCellByIndex(1).PutValue(record.Column2);

row.GetCellByIndex(2).PutValue(record.Column3);

The code crashes on the third line of code with the following error:

Object reference not set to an instance of an object.

Stack:

at Aspose.Cells.Cell.€Œ‚()
at Aspose.Cells.Cell.PutValue(String stringValue)
at

Version 8.1.2.0

Please advise.

Hi,


Could you provide us your sample code (runnable) with your template Excel file here, we will check it soon. Please use dynamic data source/ table or constant value that you may create in your code to insert into the cells of the rows, so we could run your code properly and evaluate your issue on our end.

Thank you

Unfortunately, it simply isn't feasible within our security protocols to attach or email any files or code. So I am hoping that you may have some questions about setup that might help me understand the possible reasons why this code would fail with that error. Have you run into it before? If so what were the problems?

Also, I am using .NET 4.5.1. Does that matter?

Hi,

bwhitejpmc:
Also, I am using .NET 4.5.1. Does that matter?

No, absolutely not, the issue does not depend on .NET framework version.

Well, I am afraid, we cannot evaluate your issue unless we have your sample code (runnable) at least. I think you may simply separate the issue and use some dummy data to be inserted into the cells of row to reproduce the issue on our end, you may create a simple console application (you may zip it prior attaching here or paste the code segments), so we could look into your issue more precisely and log the issue (if found) into our database to figure it out soon.

Thanks for your understanding!

I can understand your reluctance to try and troubleshoot without code, and perhaps that may make your policies incompatible with ours. Nevertheless, I did resolve the problem. What I was doing according to the code was updating cell values using GetCellByIndex...but when I switched to this:

element.Cells["A" + indexString].PutValue(record.Column1);

element.Cells["B" + indexString].PutValue(record.Column2);

element.Cells["C" + indexString].PutValue(record.Column3);

That worked. Don't know why but it did.

Thanks.

Hi,

Thanks for your posting and using Aspose.Cells.

Probably, you are getting exception because Implementations of Row/Cell/RowCollection is changed since v8.0.0. Please read about it how it could affect your code from the release notes of v8.0.0.

We are pleased to know that you were able to fix this issue. Let us know if you encounter any other issue, we will be glad to look into it and help you asap.