当前位置 : 主页 > 编程语言 > c语言 >

vb.net – 如何在不提示用户的情况下覆盖excel应用程序

来源:互联网 收集:自由互联 发布时间:2021-06-24
任何人都可以帮助我如何在不提示VB.Net中的用户的情况下覆盖excel文件. 我试过这段代码,但它不起作用.. Dim xlsApp As New Excel.ApplicationDim xlsBook As Excel.WorkbookDim xlsSheet As Excel.WorksheetDim dir
任何人都可以帮助我如何在不提示VB.Net中的用户的情况下覆盖excel文件.

我试过这段代码,但它不起作用..

Dim xlsApp As New Excel.Application
Dim xlsBook As Excel.Workbook
Dim xlsSheet As Excel.Worksheet
Dim dir As String = Application.StartupPath & "\Template\SampleTemplate.xls"
xlsBook = GetObject(dir)
xlsSheet = xlsBook.Sheets("Per BPA Error Report")


xlsSheet.Range("C2:T2").Merge()

xlsApp.DisplayAlerts = False
xlsSheet.SaveAs(Application.StartupPath & "\Template\SampleTemplate.xls")
xlsBook = Nothing
xlsSheet = Nothing
xlsApp.Quit()
Public Sub WriteExcelFile(ByVal ExcelFilePath As String) 
    Dim excel As Application = New Application
    Dim w As Workbook = excel.Workbooks.Open(ExcelFilePath)
    Dim sheet As Worksheet = w.Sheets(1)
    sheet.Cells(x + 1, 1) = 10
    x = x + 1
    excel.DisplayAlerts = False
    w.Save()
    w.Close()
End Sub
网友评论