Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue with creating Excel file using XML

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
Environment: Visual Studio 2015 / .net 4.5.1

I am trying to create an excel file from my vb.net application.
I am populating the file with database records.

I was able to populate column A, but could not populate the rest of the columns.
I got the code from docs.microsof.com and the code is failing here when it is time to populate the second column. I was populating it with same value as column A, so the problem is not record-related.
I removed the error handling (try...catch) and got an error on the highlighted line: Check to determine if the object is null before calling the method and Use the "new" keyword to create an object instance

' If there is not a cell with the specified column name, insert one.
If (row.Elements(Of Cell).Where(Function(c) c.CellReference.Value = columnName + rowIndex.ToString()).Count() > 0) Then

Return row.Elements(Of Cell).Where(Function(c) c.CellReference.Value = cellReference).First()
Else
' Cells must be in sequential order according to CellReference. Determine where to insert the new cell.
Dim refCell As Cell = Nothing
For Each cell As Cell In row.Elements(Of Cell)()

If (String.Compare(cell.CellReference.Value, cellReference, True) > 0) Then
refCell = cell
Exit For
End If
Next

Any help in resolving this issue is greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top