Aspose.Cells'i kullanarak mevcut SQL Veri Bağlantısını değiştirin

Aspose.Cells’i kullanarak mevcut SQL Veri Bağlantısını değiştirin

Aşağıdaki örnek, çalışma kitabının SQL Veri Bağlantısını değiştirmek için Aspose.Cells’in kullanımını göstermektedir. Bu kodda kullanılan kaynak Excel dosyasını ve kodun oluşturduğu çıktı Excel dosyasını aşağıdaki bağlantılardan indirebilirsiniz.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ModifyExistingSQLDataConnection.class);
// Create a workbook object from source file
Workbook workbook = new Workbook(dataDir + "DataConnection.xlsx");
// Access first Data Connection
ExternalConnection conn = workbook.getDataConnections().get(0);
// Change the Data Connection Name and Odc file
conn.setName("MyConnectionName");
conn.setOdcFile(dataDir + "MyDefaulConnection.odc");
// Change the Command Type, Command and Connection String
DBConnection dbConn = (DBConnection) conn;
dbConn.setCommandType(OLEDBCommandType.SQL_STATEMENT);
dbConn.setCommand("Select * from AdminTable");
dbConn.setConnectionInfo(
"Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False");
// Save the workbook
workbook.save(dataDir + "outxput.xlsx");