标签:imp stream for user cells set star bsp usermod
‘導入命名空間
Imports System.IO
Imports NPOI.HSSF.UserModel
Imports NPOI.HPSF
Imports NPOI.POIFS.FileSystem
Private Sub A1() ‘自定格式
Dim workbook As HSSFWorkbook = New HSSFWorkbook() ‘建立一個 Excel 實例
Dim fs = New FileStream("book1.xls", FileMode.Create) ‘準備建立一個Excel檔
Dim sheet As HSSFSheet = workbook.CreateSheet("Sheet1") ‘新增試算表 Sheet名稱
Dim cell As HSSFCell ‘單元格
Dim cs As HSSFCellStyle = workbook.CreateCellStyle ‘單元格樣式
Dim format As HSSFDataFormat = workbook.CreateDataFormat
cell = sheet.CreateRow(0).CreateCell(0) ‘單元格位置
cs.DataFormat = format.GetFormat("yyyy年m月d日")
cell.CellStyle = cs ‘設置單元格樣式
cell.SetCellValue(New DateTime(2018, 10, 15)) ‘設置單元格內容
cell = sheet.CreateRow(1).CreateCell(0) ‘單元格位置
cs.DataFormat = format.GetFormat("0.000")
cell.CellStyle = cs ‘設置單元格樣式
cell.SetCellValue(123.45678) ‘設置單元格內容
workbook.Write(fs) ‘把該workbook寫到檔案裡
fs.Close()
sheet = Nothing ‘释放EXCEL对象
workbook = Nothing ‘释放EXCEL对象
System.Diagnostics.Process.Start("book1.xls") ‘打開excel檔案
End Sub
标签:imp stream for user cells set star bsp usermod
原文地址:https://www.cnblogs.com/leme-chen/p/9790025.html