如何在不提示用户的情况下覆盖excel应用程序 [英] How to overwrite an excel application without prompting the users

查看:161
本文介绍了如何在不提示用户的情况下覆盖excel应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我如何覆盖Excel文件,而不用提示VB.Net中的用户。



我已经尝试过这个代码,但是它不工作..

  Dim xlsApp As New Excel.Application 
Dim xlsBook As Excel.Workbook
Dim xlsSheet作为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


Can anyone help me on how can I overwrite the excel file without prompting the users in VB.Net..

I have try this code but It doesn't work..

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

这篇关于如何在不提示用户的情况下覆盖excel应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆