Excelファイル(xlsx形式)を作成する事が出来る ClosedXML の説明をします。
ClosedXMLというライブラリは、このOpenXML SDKをラップして、簡単に操作できるライブラリです。
ClosedXMLは、 NuGet を使ってパッケージをインストール出来ます。Nugetで「ClosedXML」で検索してインストールして下さい。
簡単な出力サンプル
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim FilePath As String = "C:\work\HelloWorld.xlsx" Using book As XLWorkbook = New XLWorkbook() Dim wksheet As IXLWorksheet = book.Worksheets.Add("MySheet") wksheet.Cell("B2").Value = "Hello World!!" book.SaveAs(FilePath) End Using End Sub
属性追加したサンプル
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim FilePath As String = "C:\work\HelloWorld.xlsx" Using book As XLWorkbook = New XLWorkbook() Dim wksheet As IXLWorksheet = book.Worksheets.Add("MySheet") Dim cell As IXLCell = wksheet.Cell("B2") With cell .Value = "Hello World!" .Style.Font.FontSize = 24 .Style.Font.FontColor = XLColor.Red .Style.Border.OutsideBorder = XLBorderStyleValues.DashDotDot End With Dim cell2 As IXLCell = wksheet.Cell(5, 3) With cell2 .Value = "Hello World!" .Style.Font.FontSize = 24 .Style.Font.FontColor = XLColor.Red .Style.Border.OutsideBorder = XLBorderStyleValues.DashDotDot End With book.SaveAs(FilePath) End Using End Sub