Try For i As Integer = 0 To products.Length - 1 Dim product As String = products(i) sheet = DirectCast(wbook1.Worksheets.Item(i + 1), Excel.Worksheet) Dim tb As DataTable = dbtool.getProductInfo(_vendor, product, 0) sheet.Cells(2, 2) = dbtool.getVendorNameByvendorID(_vendor) sheet.Cells(4, 2) = product ..... Next 'save as new file wbook1.SaveAs(Excel_oOutputXls, missing, missing, missing, missing, missing, _ Excel.XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing) 'close without change template file wbook1.Close(False, missing, missing) excelApp.Quit() GC.Collect()
Next Catch ex As Exception wbook1.Close(False, missing, missing) GC.Collect() disply("Err:" & ex.Message, Color.Red) appendToErrDescription("Err:" & ex.Message) End Try
忘记开始的声明了:Dim excelApp As New Excel.ApplicationClass() excelApp.Visible = true Dim wbook1 As Excel.Workbook = Nothing Dim sheet As Excel.Worksheet = Nothing--------------------------------------------------------
sheet = DirectCast(wbook1.Worksheets.Item(i + 1), Excel.Worksheet) Dim tb As DataTable = dbtool.getProductInfo(_vendor, product, 0)
sheet.Cells(2, 2) = dbtool.getVendorNameByvendorID(_vendor)
sheet.Cells(4, 2) = product
.....
Next
'save as new file
wbook1.SaveAs(Excel_oOutputXls, missing, missing, missing, missing, missing, _
Excel.XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing) 'close without change template file
wbook1.Close(False, missing, missing)
excelApp.Quit()
GC.Collect()
Next
Catch ex As Exception wbook1.Close(False, missing, missing)
GC.Collect()
disply("Err:" & ex.Message, Color.Red)
appendToErrDescription("Err:" & ex.Message)
End Try
excelApp.Visible = true
Dim wbook1 As Excel.Workbook = Nothing
Dim sheet As Excel.Worksheet = Nothing--------------------------------------------------------
http://www.itwriting.com/htmleditor/index.php
打开excel编辑,保存后
file.Move复制到其他路径
你给的代码是不是在EXCEL的编辑器的代码吧?我现在保存这些操作是在WINFORM中界面的代码进行操作的!
Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,
Excel.XlSaveAsAccessMode.xlNoChange,Missing.Value,Missing.Value,Missing.Value,
Missing.Value,Missing.Value); xBook.AlertBeforeOverwriting=false;
请问这位仁兄 xBook 这个变量如何声明的!