4 个解决方案
#1
Imports NPOI.HSSF.UserModel
Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim workbook As HSSFWorkbook = New HSSFWorkbook()
Dim sheet1 As HSSFSheet = workbook.CreateSheet("sheet1")
Dim row As HSSFRow
Dim cell As HSSFCell
Dim rowIndex As Integer = 0
While rowIndex < 9
row = sheet1.CreateRow(rowIndex)
Dim colIndex As Integer = 0
While colIndex <= rowIndex
cell = row.CreateCell(colIndex)
cell.SetCellValue([String].Format("{0}*{1}={2}", rowIndex + 1, colIndex + 1, (rowIndex + 1) * (colIndex + 1)))
System.Math.Max(System.Threading.Interlocked.Increment(colIndex), colIndex - 1)
End While
System.Math.Max(System.Threading.Interlocked.Increment(rowIndex), rowIndex - 1)
End While
Dim file As New FileStream(Path.Combine(Application.StartupPath, "test.xls"), FileMode.Create)
workbook.Write(file)
file.Close()
End Sub
End Class
#2
网上好像真的多数都是c#版的,我这个特地改成了vb.net的,找的一个简单的C#的例子,c#版的在这儿,你有兴趣可以对照一下,里面还有生成后的截图。
http://www.cnblogs.com/atao/archive/2009/09/29/1576070.html
http://www.cnblogs.com/atao/archive/2009/09/29/1576070.html
#3
谢谢,学习。
#4
vb.net怎么引用npoi呢?不会,刚接触这个,请求大神赐教
#1
Imports NPOI.HSSF.UserModel
Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim workbook As HSSFWorkbook = New HSSFWorkbook()
Dim sheet1 As HSSFSheet = workbook.CreateSheet("sheet1")
Dim row As HSSFRow
Dim cell As HSSFCell
Dim rowIndex As Integer = 0
While rowIndex < 9
row = sheet1.CreateRow(rowIndex)
Dim colIndex As Integer = 0
While colIndex <= rowIndex
cell = row.CreateCell(colIndex)
cell.SetCellValue([String].Format("{0}*{1}={2}", rowIndex + 1, colIndex + 1, (rowIndex + 1) * (colIndex + 1)))
System.Math.Max(System.Threading.Interlocked.Increment(colIndex), colIndex - 1)
End While
System.Math.Max(System.Threading.Interlocked.Increment(rowIndex), rowIndex - 1)
End While
Dim file As New FileStream(Path.Combine(Application.StartupPath, "test.xls"), FileMode.Create)
workbook.Write(file)
file.Close()
End Sub
End Class
#2
网上好像真的多数都是c#版的,我这个特地改成了vb.net的,找的一个简单的C#的例子,c#版的在这儿,你有兴趣可以对照一下,里面还有生成后的截图。
http://www.cnblogs.com/atao/archive/2009/09/29/1576070.html
http://www.cnblogs.com/atao/archive/2009/09/29/1576070.html
#3
谢谢,学习。
#4
vb.net怎么引用npoi呢?不会,刚接触这个,请求大神赐教