I am using closedXML to take a datatable and place this into an Excel file.
The code I am working with works, with 99% of the files I put through the application, but I get an error with a file every now and then. (no this is not a debugging issue)
The problem must originate from the data, however I am at a loss on how to resolve this.
The code I'm using is
Public Sub WriteToExcel(dt As DataTable, filePath As String)
Dim workbook = New XLWorkbook()
Dim worksheet = workbook.Worksheets.Add(dt, "Call Validate Export")
Try
workbook.SaveAs(filePath)
Process.Start(filePath)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
When saving the file I get the error
'', hexadecimal value 0x1A, is an invalid character.
between the '' there is a little arrow pointing to the right.
When reading the file in to the datatable it reads in fine, looking at the file I see no hex characters.
The file being read in is a ^ delimited csv file.
So, my question is how to I check and repair\replace the bad characters in the output that will allow me to save 100% of the time.