2016-03-24 13 views

cevap

0

Sen Excel birlikte çalışma için sıkıcı Microsoft Office bağımlılıkları önleyebilirsiniz NPOI kütüphane, aynı zamanda bu şekilde kullanabilirsiniz "Ben kolay yolu Excel'de yazmak ve onu kurtarmak istiyoruz".

Kısa ev yapımı örnek:

Imports NPOI 
Imports NPOI.HSSF.UserModel 
Imports NPOI.HSSF.Util 
Imports NPOI.SS.UserModel 
Imports NPOI.SS.UserModel.Charts 
Imports NPOI.SS.Util 
Imports NPOI.XSSF.UserModel 

Dim WorkBookFile As String = "C:\MyWorkBook.xlsx" 

' Create the excel workbook instance. 
Dim workbook As IWorkbook = Nothing 

' Load the workbook. 
Using file As New FileStream(WorkBookFile, FileMode.Open, FileAccess.Read) 
    workbook = New XSSFWorkbook(file) 
End Using 

' Get the first sheet. 
Dim sheet As ISheet = workbook.GetSheetAt(0) 

' Get the first row. 
Dim row As IRow = sheet.GetRow(0) 

' Create a cell. 
Dim cell As ICell = row.CreateCell(1) 

' Get the cell value. 
If String.IsNullOrEmpty(cell.StringCellValue) Then ' If value is emty then... 

Set cell value. 
    cell.SetCellValue("This is a test") 

End If 

' Save changes. 
Using sw As FileStream = File.Create(WorkBookFile) 
    workbook.Write(sw) 
End Using 

resmi için Documentation başlarken örneklere bakın.

2

POCO ile işlemeye ihtiyacınız varsa, aracımı Npoi.Mapper kullanabilirsiniz. Ayrıca NPOI dayanmaktadır. Aşağıdaki gibi C# kodu, ancak kolayca VB.NET dönüştürebilirsiniz:

var mapper = new Mapper("Book1.xlsx"); 
mapper.Put(products, "sheet1", true/*overwrite existing rows*/); 
mapper.Put(orders, "sheet2", false/*append rows*/); 
mapper.Save("Book1.xlsx"); 
İlgili konular