如何在不提示用户的情况下覆盖 Excel 应用程序
任何人都可以帮助我如何在不提示 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()
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您只想覆盖当前存在的文件,那么先删除它然后保存新文件可能会更容易。因此只需使用 System.IO.File.Delete 即可。
If you just want to overwrite the file that's currently there, might just be easier to delete it first and then save the new file. So just use
System.IO.File.Delete
.为什么需要使用
另存为
?查看代码,您正在尝试写入同一个文件。请改用
保存
。Why do you need to use
SaveAs
?Looking at the code, you are trying to write to the same file. Use
Save
instead.