Hello @jim brown
I would suggest using spreadsheetlight available from NuGet and DocumentFormat.OpenXml. Both are free libraries.
Why?
Because these libraries don't use Excel automation but OpenXML for Excel which is many times faster than Excel automation.
Some helpers
After creating and instance of SLDocument you can (where doc is a SLDocument)
- AutoFit columns e.g. doc.AutoFitColumn("A")
- Create and apply styles via doc.CreateStyle which in turn allows you to do things like text alignment, bold, italics etc.
Public Sub SimpleExportRaw( pFileName As String, pSheetName As String, pDataTable As DataTable, pColumnHeaders As Boolean) Using doc As New SLDocument() doc.SelectWorksheet(pSheetName) doc.ImportDataTable(1, SLConvert.ToColumnIndex("A"), pDataTable, pColumnHeaders) doc.SaveAs(pFileName) End Using End Sub
Extras
Public Function SheetNames(ByVal pFileName As String) As List(Of String)
Using doc = New SLDocument(pFileName)
Return doc.GetSheetNames(False)
End Using
End Function
Public Function AddNewSheet(ByVal pFileName As String, ByVal pSheetName As String) As Boolean
Using doc = New SLDocument(pFileName)
If Not (doc.GetSheetNames(False).Any(Function(sheetName) sheetName.ToLower() = pSheetName.ToLower())) Then
doc.AddWorksheet(pSheetName)
doc.Save()
Return True
Else
Return False
End If
End Using
End Function