セルの文字位置、文字色、セルの色、セルの枠線、などの属性を設定する方法を記載します。

セル内の文字の表示位置を設定する

Dim sheet As ExcelWorksheet = excel.Workbook.Worksheets("MySheet1")

Dim cell As ExcelRange = sheet.Cells("A1")
cell.Value = "Hello World"

cell.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center        '水平方向
cell.Style.VerticalAlignment = ExcelVerticalAlignment.Center            '垂直方向

 

セルの枠線を設定する

Dim sheet As ExcelWorksheet = excel.Workbook.Worksheets("MySheet1")

Dim cell As ExcelRange = sheet.Cells("A1")
cell.Value = "Hello World"

cell.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin         '上線
cell.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin      '下線
cell.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin        '左線
cell.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin       '右線

cell.Style.Border.Bottom.Color.SetColor(System.Drawing.Color.Red)               '下線色

 

枠に色を付ける

Dim sheet As ExcelWorksheet = excel.Workbook.Worksheets("MySheet1")

Dim cell As ExcelRange = sheet.Cells("A1")
cell.Value = "Hello World"

cell.Style.Fill.PatternType = ExcelFillStyle.Solid
cell.Style.Fill.BackgroundColor.SetColor(Color.Yellow)

 

文字属性の設定

Dim sheet As ExcelWorksheet = excel.Workbook.Worksheets("MySheet1")

Dim cell As ExcelRange = sheet.Cells("A1")
cell.Value = "Hello World"

cell.Style.Font.SetFromFont(New Font("MS P明朝", 9, FontStyle.Regular))
cell.Style.Font.Bold = True
cell.Style.Font.Color.SetColor(Color.WhiteSmoke)    'フォントカラー
cell.Style.Font.Size = 14                           'フォントサイズ

 

表示書式の設定

Dim sheet As ExcelWorksheet = excel.Workbook.Worksheets("MySheet1")

Dim cell As ExcelRange = sheet.Cells("A1")
cell.Value = 1234.56

cell.Style.Numberformat.Format = "#,##0"