Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: Closing a ClosedXML generated Workbook.

$
0
0
Good morning,

I have the following code:
Private Sub Btn_export_Click() Handles Btn_export.Click
        Dim book As XLWorkbook = New XLWorkbook(XLEventTracking.Disabled)
        Dim table As System.Data.DataTable

        table = DGV_preview.DataSource
        book.AddWorksheet(table, "Result")
        book.SaveAs("visitation.xlsx")
        ' HERE BE SOME E-MAIL SENDING
        book.Worksheets(0).Dispose()
        book.Dispose()
        table.Dispose()
        File.Delete("visitation.xlsx")
    End Sub
Basically I want to create an Excel file, transfer a DataTable into it, Save the file, e-mail it and then delete the file.
Everything works perfectly until I want to delete the file. How on earth do I close the file so I can delete it? I can't seem to find the way to do it. :(

Thank you VERY much for this amazing work you've done, by the way.

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>