LoginSignup
6
7

More than 5 years have passed since last update.

NPOI VB.NET メモ

Last updated at Posted at 2018-05-31

宣言

Imports System.IO
Imports NPOI.SS.UserModel
Imports NPOI.XSSF.UserModel
'ブックの設定
Dim xWorkbook As IWorkbook = New XSSFWorkbook(path)

'シートの設定
Dim xSheet As ISheet = xWorkbook.CreateSheet
'列名設定
Dim xRow As IRow
'セル設定
Dim xCell As ICell

'セル番号を指定(0,x) 行
xRow = xSheet.CreateRow(0)

'セル番号を指定(x,0) 列
xCell = xRow.CreateCell(0)
xCell.SetCellValue("表示したいデータ") '表示する値指定
xCell = xRow.CreateCell(1)
xCell.SetCellValue("表示したいデータ") '表示する値指定
xCell = xRow.CreateCell(2)
xCell.SetCellValue("表示したいデータ") '表示する値指定


'UBoundで配列の最大インデックスを終了値に指定。
'UBound 配列内の指定された次元における最も大きいインデックスを返します。
For i As Integer = 0 To UBound(array)Step 1
'フラグでデータ管理 なければ終了
 If array.Flg = "" Then Exit For 

'セル番号を指定(0,x) 行
  xRow = xSheet.CreateRow(i)

'セル番号を指定(x,0) 列
    xCell = xrow.CreateCell(0) 
    xCell.SetCellValue(i1_Table(i - 1).arrayname0)
    xCell = xrow.CreateCell(1) 
    xCell.SetCellValue(i1_Table(i - 1).arrayname1)
    xCell = xrow.CreateCell(2)
    xCell.SetCellValue(i1_Table(i - 1).arrayname2)
    xCell = xrow.CreateCell(3)
    xCell.SetCellValue(i1_Table(i - 1).arrayname3)
Next
End If

'ここでSetCellValueで設定したデータを表示することが出来る。
Dim wFileStream As FileStream 
'FileModeに関しては調べてください。
wFileStream = New FileStream("path", FileMode,OpenOrCFCreate.FileAccess.Write)
'最終表示
xWorkbook.Write(wFileStream)

'宣言と逆にして開放する。
     xCell = Nothing
     xrow = Nothing
     xSheet = Nothing
     xWorkbook = Nothing


6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7