public void AddElement(string filePath, VerifiableLog log) { using (SpreadsheetDocument package = SpreadsheetDocument.Open(filePath, true)) { ConnectionsPart connectionsPart = package.WorkbookPart.ConnectionsPart; int connectionNum = connectionsPart.Connections.Descendants <X15.Connection>().Count(); X15.Connection x15connection = new X15.Connection() { Id = this.X15ConnectionId, AutoDelete = this.X15ConnectionAutoDelete }; x15connection.OleDbPrpoperties = new X15.OleDbPrpoperties() { Connection = this.ConnectionString }; x15connection.OleDbPrpoperties.DbCommand = new X15.DbCommand() { Text = this.DBCommandText }; ConnectionExtension connectionExtension = new ConnectionExtension() { Uri = this.ConnectionExtUri }; Connection connection = new Connection() { Id = this.ConnectionId, ConnectionFile = this.ConnectionOdcFile, Name = this.ConnectionName, Type = this.ConnectionType, RefreshedVersion = this.ConnectionRefreshedVersion, MinRefreshableVersion = this.ConnectionMinRefreshedVersion, Background = this.ConnectionBackground }; ConnectionExtensionList connectionExtensionList = new ConnectionExtensionList(); connectionExtension.AppendChild <X15.Connection>(x15connection); log.Pass("Added the X15.Connection."); connectionExtensionList.AppendChild <ConnectionExtension>(connectionExtension); log.Pass("Added the ConnectionExtension."); connection.AppendChild <ConnectionExtensionList>(connectionExtensionList); log.Pass("Added the ConnectionExtensionList."); package.WorkbookPart.ConnectionsPart.Connections.Append(connection); log.Pass("Added the Connection."); } }
public void AddElement(string filePath, VerifiableLog log) { using (SpreadsheetDocument package = SpreadsheetDocument.Open(filePath, true)) { ConnectionsPart connectionsPart = package.WorkbookPart.ConnectionsPart; int connectionNum = connectionsPart.Connections.Descendants<X15.Connection>().Count(); X15.Connection x15connection = new X15.Connection() { Id = this.X15ConnectionId, AutoDelete = this.X15ConnectionAutoDelete }; x15connection.OleDbPrpoperties = new X15.OleDbPrpoperties() { Connection = this.ConnectionString }; x15connection.OleDbPrpoperties.DbCommand = new X15.DbCommand() { Text = this.DBCommandText }; ConnectionExtension connectionExtension = new ConnectionExtension() { Uri = this.ConnectionExtUri }; Connection connection = new Connection() { Id = this.ConnectionId, ConnectionFile = this.ConnectionOdcFile, Name = this.ConnectionName, Type = this.ConnectionType, RefreshedVersion = this.ConnectionRefreshedVersion, MinRefreshableVersion = this.ConnectionMinRefreshedVersion, Background = this.ConnectionBackground }; ConnectionExtensionList connectionExtensionList = new ConnectionExtensionList(); connectionExtension.AppendChild<X15.Connection>(x15connection); log.Pass("Added the X15.Connection."); connectionExtensionList.AppendChild<ConnectionExtension>(connectionExtension); log.Pass("Added the ConnectionExtension."); connection.AppendChild<ConnectionExtensionList>(connectionExtensionList); log.Pass("Added the ConnectionExtensionList."); package.WorkbookPart.ConnectionsPart.Connections.Append(connection); log.Pass("Added the Connection."); } }
// Generates content of connectionsPart1. private void GenerateConnectionsPart1Content(ConnectionsPart connectionsPart1) { Connections connections1 = new Connections(); Connection connection1 = new Connection(){ Id = (UInt32Value)1U, ConnectionFile = "C:\\Users\\pberruti\\Documents\\My Data Sources\\xlextdat105 Timestamps\\DAT105 Timestamp - Foodmart 2000 account.odc", Name = "DAT105 Timestamp - Foodmart 2000 account", Type = (UInt32Value)100U, RefreshedVersion = 5, MinRefreshableVersion = 5, Background = true }; ConnectionExtensionList connectionExtensionList1 = new ConnectionExtensionList(); ConnectionExtension connectionExtension1 = new ConnectionExtension(){ Uri = "{DE250136-89BD-433C-8126-D09CA5730AF9}" }; connectionExtension1.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); X15.Connection connection2 = new X15.Connection(){ Id = "d500245d-c151-4de3-9436-83c6e82b7f22", AutoDelete = true }; X15.OleDbPrpoperties oleDbPrpoperties1 = new X15.OleDbPrpoperties(){ Connection = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Data Source=xlextdat105;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=PB07641564SHIP;Use Encryption for Data=False;Tag with column collation when possible=False;Initial Catalog=Foodmart 2000" }; X15.DbCommand dbCommand1 = new X15.DbCommand(){ Text = "SELECT *, suser_name() CurrentUser, current_timestamp RefreshTime FROM \"Foodmart 2000\".\"dbo\".\"account\"" }; oleDbPrpoperties1.Append(dbCommand1); connection2.Append(oleDbPrpoperties1); connectionExtension1.Append(connection2); connectionExtensionList1.Append(connectionExtension1); connection1.Append(connectionExtensionList1); Connection connection3 = new Connection(){ Id = (UInt32Value)2U, KeepAlive = true, Name = "ModelConnection_Query", Description = "Model", Type = (UInt32Value)5U, RefreshedVersion = 5, MinRefreshableVersion = 3, SaveData = true }; DatabaseProperties databaseProperties1 = new DatabaseProperties(){ Connection = "Data Model Connection", Command = "Query", CommandType = (UInt32Value)3U }; ConnectionExtensionList connectionExtensionList2 = new ConnectionExtensionList(); ConnectionExtension connectionExtension2 = new ConnectionExtension(){ Uri = "{DE250136-89BD-433C-8126-D09CA5730AF9}" }; connectionExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); X15.Connection connection4 = new X15.Connection(){ Id = "", Model = true }; connectionExtension2.Append(connection4); connectionExtensionList2.Append(connectionExtension2); connection3.Append(databaseProperties1); connection3.Append(connectionExtensionList2); Connection connection5 = new Connection(){ Id = (UInt32Value)3U, KeepAlive = true, Name = "ThisWorkbookDataModel", Description = "Model", Type = (UInt32Value)5U, RefreshedVersion = 5, MinRefreshableVersion = 5, Background = true }; DatabaseProperties databaseProperties2 = new DatabaseProperties(){ Connection = "Data Model Connection", Command = "Model", CommandType = (UInt32Value)1U }; OlapProperties olapProperties1 = new OlapProperties(){ SendLocale = true, RowDrillCount = (UInt32Value)1000U }; ConnectionExtensionList connectionExtensionList3 = new ConnectionExtensionList(); ConnectionExtension connectionExtension3 = new ConnectionExtension(){ Uri = "{DE250136-89BD-433C-8126-D09CA5730AF9}" }; connectionExtension3.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); X15.Connection connection6 = new X15.Connection(){ Id = "", Model = true }; connectionExtension3.Append(connection6); connectionExtensionList3.Append(connectionExtension3); connection5.Append(databaseProperties2); connection5.Append(olapProperties1); connection5.Append(connectionExtensionList3); connections1.Append(connection1); connections1.Append(connection3); connections1.Append(connection5); connectionsPart1.Connections = connections1; }