【发布时间】:2014-05-22 16:58:29
【问题描述】:
我有一个 excel 2013 powerpivot 文档...连接到我托管的 wcfdataservice...数据连接工作正常,所有数据都被带回并成功填充到我的 powerpivot 图表/表格中。
数据托管在如下所示的数据馈送 URL 中。:
http://mydomain/Reporting/WcfDataService1.svc/
我有几十个客户,每个客户都需要接收相同的文档...但是 DataFeedURL 被编辑为指向他们托管的数据服务...每个客户都有不同的 URL...例如
http://Client1/Reporting/WcfDataService1.svc/
http://Client2/Reporting/WcfDataService1.svc/
长话短说...我希望客户使用我的 C# Windows 窗体应用程序,该应用程序将引用模板 PowePivot 报告...并且当用户完成设置有关其公司的各种信息时。 .. 我需要以编程方式保存 PowerPivot 报告的一个版本,其中包含到我生成的新 URL 的更新连接。
我正在尝试这样做:
string workbookPath = String.Format("{0}\\{1}", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "PowerPivotSource.xlsx");
string workbookPath2 = String.Format("{0}\\{1}", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "PowerPivotTestOut.xlsx");
foreach (Excel.WorkbookConnection connection in excelWorkbook.Connections)
{
if (connection.Type == Excel.XlConnectionType.xlConnectionTypeDATAFEED)
{
Excel.DataFeedConnection dataFeedCur = connection.DataFeedConnection;
dataFeedCur.Connection = dataFeedCur.Connection.Replace("mydomain", "Client1");
break;
}
}
excelWorkbook.Close(true);
我可以读取 dataFeedCur.Connection 的内容,但尝试按此处所示进行编辑
dataFeedCur.Connection = dataFeedCur.Connection.Replace("localhost", "Client1");
抛出以下异常:
Exception Message: "Exception from HRESULT: 0x800A03EC"
Exception Stack Trace: "" at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)\r\n at Microsoft.Office.Interop.Excel.DataFeedConnection.set_Connection(Object value)\r\n
有一些迹象表明 WorkBookConnection.DataFeedConnection 对象是只读的...但我听说其他论坛中的人谈论能够编辑此连接字符串,但没有看到任何示例...任何人都知道这是怎么回事DataFeedConnection.Connection 对象可以编辑吗?
【问题讨论】:
-
你有没有得到这个工作?
标签: c# excel powerpivot