简体   繁体   English

在MS Excel 2013 powerpivot中更改连接字符串

[英]Change connection string in MS Excel 2013 powerpivot

I am working on same solution where i need to update connection strings of multiple files in Bulk.But , Its working for MS Excel 2010 and not for Excel 2013. 我正在研究相同的解决方案,我需要在Bulk.But中更新多个文件的连接字符串,它适用于MS Excel 2010而不适用于Excel 2013。

Exception Result : "Exception from HRESULT: 0x800A03EC" 异常结果:“HRESULT异常:0x800A03EC”

Code Snippet : 代码片段:

Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook ppWorkbook = (Microsoft.Office.Interop.Excel.Workbook)xlApp.Workbooks.Open(fileNameBox.Text);
Microsoft.Office.Interop.Excel.Connections connections = ppWorkbook.Connections;

string newConnectionString = "Connection String";

try
{
     foreach (Microsoft.Office.Interop.Excel.WorkbookConnection connection in connections)
     {
          connection.OLEDBConnection.Connection = newConnectionString;
     }
}
catch (Exception ex)
{ }

It occurs while assigning the connection string to OLEDBConnection. 将连接字符串分配给OLEDBConnection时会发生这种情况。 Need solution for MS Excel 2013 c#. 需要MS Excel 2013 c#的解决方案。

Every connection has the property "InModel". 每个连接都具有“InModel”属性。 When this property is set it's a powerpivot connection and can't be updated with excel api. 设置此属性时,它是powerpivot连接,无法使用excel api进行更新。 When you try this, you'll get the posted error message. 当您尝试此操作时,您将收到发布的错误消息。 You have to use the dlls from the powerpivot addin. 你必须使用powerpivot插件中的dll。

You could do assignment if adding OLEDB; 如果添加OLEDB;你可以做任务OLEDB; at the beginning of your connection string. 在连接字符串的开头。 Had the same issue . 同样的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM