Modify existing SQL Data Connection using Aspose.Cells for Node.js via C++
Contents
[
Hide
]
Aspose.Cells supports modifying existing SQL Data Connection. The article will explain how to use Aspose.Cells to modify different properties of SQL Data Connection.
You can add or see Data Connections inside Microsoft Excel by following Data > Connections menu command.
Similarly, Aspose.Cells provides the means to access and modify the Data Connections using Workbook.dataConnections collection.
You can add or see Data Connections inside Microsoft Excel by following Data > Connections menu command.
Similarly, Aspose.Cells provides the means to access and modify the Data Connections using Workbook.dataConnections collection.
Modify existing SQL Data Connection using Aspose.Cells
The following sample illustrates the use of Aspose.Cells for Node.js via C++ to modify SQL Data Connection of the workbook. You can download the source Excel file used in this code and the output Excel file generated by the code from the following links.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Create workbook object
const workbook = new AsposeCells.Workbook(path.join(dataDir, "DataConnection.xlsx"));
// Access first Data Connection
const conn = workbook.getDataConnections().get(0);
// Change the Data Connection Name and Odc file
conn.setName("MyConnectionName");
conn.setOdcFile("C:\\Users\\MyDefaulConnection.odc");
// Change the Command Type, Command and Connection String
const dbConn = conn;
dbConn.setCommandType(AsposeCells.OLEDBCommandType.SqlStatement);
dbConn.setCommand("Select * from AdminTable");
dbConn.setConnectionString("Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False");
// Save the workbook
workbook.save(path.join(dataDir, "output_out.xlsx"));