2015-08-24 5 views

ответ

0

Имеет примеры на этом сайте http://www.dotnetperls.com/excel-vbnet. В вашем проекте вам нужны ссылки Microsoft.Office.Interop of Office.

Создать из шаблона (подробнее https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.workbooks.add.aspx)

Imports Microsoft.Office.Interop.Excel 

Module Module1 
    Sub Main() 
    ' Create new Application. 
    Dim excel As Application = New Application 

    Dim w As Workbook = excel.Workbooks.Add("c:\templateFileName") 

    ' Close. 
    w.Close() 
    End Sub 
End Module 

Чтение из файла:

Imports Microsoft.Office.Interop.Excel 

Module Module1 
    Sub Main() 
    ' Create new Application. 
    Dim excel As Application = New Application 

    ' Open Excel spreadsheet. 
    Dim w As Workbook = excel.Workbooks.Open("C:\file.xls") 

    ' Loop over all sheets. 
    For i As Integer = 1 To w.Sheets.Count 

     ' Get sheet. 
     Dim sheet As Worksheet = w.Sheets(i) 

     ' Get range. 
     Dim r As Range = sheet.UsedRange 

     ' Load all cells into 2d array. 
     Dim array(,) As Object = r.Value(XlRangeValueDataType.xlRangeValueDefault) 

     ' Scan the cells. 
     If array IsNot Nothing Then 
     Console.WriteLine("Length: {0}", array.Length) 

     ' Get bounds of the array. 
     Dim bound0 As Integer = array.GetUpperBound(0) 
     Dim bound1 As Integer = array.GetUpperBound(1) 

     Console.WriteLine("Dimension 0: {0}", bound0) 
     Console.WriteLine("Dimension 1: {0}", bound1) 

     ' Loop over all elements. 
     For j As Integer = 1 To bound0 
      For x As Integer = 1 To bound1 
      Dim s1 As String = array(j, x) 
      Console.Write(s1) 
      Console.Write(" "c) 
      Next 
      Console.WriteLine() 
     Next 
     End If 
    Next 

    ' Close. 
    w.Close() 
    End Sub 
End Module 
+0

Спасибо за ответы, этот код получает данные из Excel лист и помещает их в массив и выводит содержимое массива. Как этот код создаст листок конкретного шаблона? –

+0

Теперь ответ спасибо большое –

Смежные вопросы