I have an excel 2013 powerpivot document... that connects to a wcfdataservice that i host... data connectivity works fine, all data is brought back and populated into my powerpivot charts/tables succesfully.
The data is hosted at Data Feed URL that looks like this.:
http://mydomain/Reporting/WcfDataService1.svc/
I have dozens of clients, that will each need to receive this same document... but with the DataFeedURL edited to point to their hosted data service... each one will have a different URL... such as
http://Client1/Reporting/WcfDataService1.svc/
http://Client2/Reporting/WcfDataService1.svc/
Long story short... I wish for clients to use a C# Windows Form application of mine, that will have a reference to the template PowePivot Report... and when the user gets done setting up various information regarding their company... i need to programatically save a version of the PowerPivot report that contains an updated Connection to their new URL that I generate.
I am attempting to do this as follows:
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);
I can read the contents of dataFeedCur.Connection, but attempting to edit it as shown here
dataFeedCur.Connection = dataFeedCur.Connection.Replace("localhost", "Client1");
throws the following exception:
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
There is some indication the WorkBookConnection.DataFeedConnection objet is Read Only... but I've heard people in other forums talk about being able to edit this connection string, but have seen no examples... any one know how this DataFeedConnection.Connection object can be edited?