防止文件现在可用弹出式Excel

编程入门 行业动态 更新时间:2024-10-25 12:17:34
本文介绍了防止文件现在可用弹出式Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这里有一个问题,我已经工作了几个小时了.

I have a problem here that I've been working on for hours.

我正在导入一个Excel文件,并使用以下代码来做到这一点:

I'm importing an Excel file, and I use this code to do it:

Dim objExcel As Excel.Application Dim objWorkBook As Excel.Workbook Dim totalWorkSheets As Excel.Worksheet Dim ExcelSheetName As String = "" objExcel = CreateObject("Excel.Application") objWorkBook = objExcel.Workbooks.Open(excelfile, Notify:=False) objExcel.DisplayAlerts = False Dim exConS As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & excelfile & ";Extended Properties=Excel 8.0;" For Each totalWorkSheets In objWorkBook.Worksheets ExcelSheetName += totalWorkSheets.Name Dim exCon As New OleDbConnection(exConS) Dim dsExcel As New DataSet() exCon.Open() Dim sExcel As String = "SELECT * FROM [" & totalWorkSheets.Name & "$]" Dim daExcel As New OleDbDataAdapter(sExcel, exCon) daExcel.Fill(dsExcel) exCon.Close() Next totalWorkSheets objWorkBook.Close() objExcel.Quit() Dim ggProcess As New Process ggProcess = Process.Start("EXCEL.EXE") ggProcess.Kill()

问题是当我运行代码时,以下对话框一直出现:

The problem is that the following dialog box keeps appearing when I run the code:

如何防止此弹出对话框出现?

How can I prevent this pop-up dialog box from appearing?

推荐答案

根据超级用户的建议,可以简单地进行更改

As poweruser has suggested can simply change

objWorkBook = objExcel.Workbooks.Open(excelfile, Notify:=False)

objWorkBook = objExcel.Workbooks.Open(excelfile, Notify:=False, Readonly:=True)

好吧,因为那没有用,所以我对代码进行了更详细的研究,认为您的问题是因为您正在打开excel文件,然后为其创建外部连接.不必打开该文件即可为它创建OLEDB连接.

Ok since that didn't work I've taken a more detailed look at the code and think your issue is because you are opening the excel file, then creating an external connection to it. The file does not have to be open in order create an OLEDB connection to it.

看来您不预先知道选项卡的名称,所以您需要打开文件来获取选项卡的名称吗?

It appears that you don't know the tab names in advance so you need to open the file to get the tab names?

如果是这样,我将创建一种打开文件的方法,以获取选项卡名称并返回选项卡名称的数组,然后您可以在上面的代码中对其进行迭代,然后关闭文件.

If so I would create a method to open the file get the tab names and return an array of the tab names which you can then iterate through in your code above, then close the file.

更多推荐

防止文件现在可用弹出式Excel

本文发布于:2023-08-06 04:46:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310158.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹出式   文件   Excel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!