'', hexadecimal value 0x1A, is an invalid character
<p>I am using closedXML to take a datatable and place this into an Excel file. </p>

<p>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)</p>

<p>The problem must originate from the data, however I am at a loss on how to resolve this. </p>

<p>The code I'm using is </p>

<pre><code>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
</code></pre>

<p>When saving the file I get the error </p>

<blockquote>
  <p>'', hexadecimal value 0x1A, is an invalid character.</p>
</blockquote>

<p>between the '' there is a little arrow pointing to the right.  </p>

<p>When reading the file in to the datatable it reads in fine, looking at the file I see no hex characters. </p>

<p>The file being read in is a ^ delimited csv file. </p>

<p>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. </p>