tags:

views:

9

answers:

0

I have the following block of code which populates data from a database into an xlsx file:

                For Each xc As XElement In xelC
                    Dim sAttribute_Cell As XAttribute = xc.Attribute("s")
                    Try
                        xelV = xc.Element(xvName)
                    Catch ex As Exception
                        xelV = Nothing
                    End Try
                    If Not xelV Is Nothing Then
                        Select Case xelV.Value
                            Case "^^[OperationName]^^"
                                xelV.SetValue(objOpp.OperationName)
                            Case "^^[FBRN]^^"
                                xelV.SetValue(objOpp.FarmBusinessRegistrationNumber)
                            Case "^^[FileNumber]^^"
                                xelV.SetValue(objOpp.FileNumber)
                        End Select
                Next 

This code works as it should.

I need to change the header text in one of the columns in the xlsx file. Whenever I make the change and save the file and try to re-run this code, the code no longer works because none of the cases are hit.

It seems that once I save the xlsx base file, the values of each xelV.Value get lost - i.e. they are reset to a number instead of a custom text value. For example, where xelV.Value once equalled ^^[OperationName]^^, it has now been reset to "51". This happens to the xlsx file even if I simply open the original file, make absolutely no changes and then save the file.

What am I missing? Is there some option I'm forgetting to check when I save the xlsx file that makes me lose this data?