Mevcut SQL Veri Bağlantısını Değiştirme Aspose.Cells ile
Contents
[
Hide
]
Aspose.Cells, mevcut SQL Veri Bağlantısını değiştirme işlemini destekler. Bu makale, Aspose.Cells’ı kullanarak SQL Veri Bağlantısının farklı özelliklerini değiştirmeyi açıklamaktadır.
Microsoft Excel içinde Veri > Bağlantılar menü komutunu kullanarak Veri Bağlantılarını ekleyebilir veya görüntüleyebilirsiniz.
Benzer şekilde, Aspose.Cells, Workbook.getDataConnections() koleksiyonunu kullanarak Veri Bağlantılarına erişme ve bunları değiştirme imkanı sağlar.
Mevcut SQL Veri Bağlantısını Değiştirme Aspose.Cells ile
Aşağıdaki örnek, Aspose.Cells’ı kullanarak Excel dosyasının SQL Veri Bağlantısını değiştirmeyi göstermektedir. Kod içinde kullanılan kaynak Excel dosyasını ve kod tarafından oluşturulan çıktı Excel dosyasını aşağıdaki linklerden indirebilirsiniz.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |