How to open Excel-workbooks without the message The workbook contains links to other data sources. programmatically?

让人想犯罪 __ 提交于 2019-12-04 05:50:27

问题


I want to open 1 or more Excel-workbooks programmatically. And when I open the workbook, you get a question: The workbook contains links to other data sources. And I don't want press "Don't update"

How can you leave this messagebox? So the functionality will not interrupted anymore. Updating is not needed.


回答1:


try placing in the workbook Open event handler:

Application.AskToUpdateLinks = False



回答2:


I don't think you can get around the dialogs with the excel interop libraries (the warnings are there for a reason). The way I've always done this in the past is to treat the Excel file like it's a database, and use the following:

OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + excelFileName + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\"");

Then you can use the following to get information about the sheets:

DataTable lookupSheets = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

Then use the debugger to understand what is behind the lookupSheets variable and start writing queries like you would with any other database.

Note: You cannot use the richer elements of the interop libraries like formatting



来源:https://stackoverflow.com/questions/27606970/how-to-open-excel-workbooks-without-the-message-the-workbook-contains-links-to-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!