2016-01-11 50 views
0

我是VB.NET中的新成員。我想從VB.NET導出Excel,並且我正在使用EPPlus作爲我的項目。「cells」中的參數 - 方法

這段代碼中ws.cells()的四個參數是什麼?

代碼:

Imports OfficeOpenXml 
Imports OfficeOpenXml.Style 
Imports System.IO 
Public Class excelExport 
Private Access As New DBControl 
Public Sub myReport() 
    Dim saveDialog As New SaveFileDialog 
    saveDialog.Filter = "Excel File (*.xlsx)|*.xlsx" 
    saveDialog.FilterIndex = 1 

    If saveDialog.ShowDialog() = DialogResult.OK Then 
     Try 

      Dim file As FileInfo = New FileInfo(saveDialog.FileName) 

      ' Ensures we create a new workbook 
      If (file.Exists) Then 
       file.Delete() 
      End If 

      Dim pck As ExcelPackage = New ExcelPackage(file) 

      ' Add a new worksheet to the empty workbook 
      Dim ws As ExcelWorksheet = pck.Workbook.Worksheets.Add("Sheet1") 
      ' Load data from DataTable to the worksheet 
      ws.Cells("A1").Value = "new" 
      ws.Cells.AutoFitColumns() 

      ' Add some styling 
      Dim rng As ExcelRange = ws.Cells(1, 1, 1, 10) '<---------- This code 

      rng.Style.Font.Bold = True 
      rng.Style.Fill.PatternType = ExcelFillStyle.Solid 
      rng.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.FromArgb(79, 129, 189)) 
      rng.Style.Font.Color.SetColor(System.Drawing.Color.White) 

      ' Save the new workbook 
      pck.Save() 


      MessageBox.Show(String.Format("Excel file {0} generated successfully.", file.Name)) 

     Catch ex As Exception 

      MessageBox.Show("Failed to export to Excel. Original error: " + ex.Message) 
     End Try 
    End If 
End Sub 
End Class 

回答

1

你的第一個問題主要是要求的意見,這是不是這個網站是。對於它的價值,我發現EPPlus可用於創建Excel文件。

回答你的第二個問題是,在Cells方法有四個參數:

  1. 第一行的數量將被納入範圍。
  2. 要包含在範圍中的第一列的編號。
  3. 範圍中包含的最後一行的編號。
  4. 範圍中最後一列的編號。