Modifica la connessione dati SQL esistente

Modificare la connessione dati SQL esistente usando Aspose.Cells per Python via .NET

Il seguente esempio illustra l’uso di Aspose.Cells per Python via .NET per modificare la Connessione Dati SQL del workbook. Puoi scaricare il file Excel sorgente usato in questo codice e il file Excel di output generato dal codice dai seguenti link.

from aspose import pycore
from aspose.cells import Workbook
from aspose.cells.externalconnections import DBConnection, OLEDBCommandType
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create workbook object
workbook = Workbook(dataDir + "DataConnection.xlsx")
# Access first Data Connection
conn = workbook.data_connections[0]
# Change the Data Connection Name and Odc file
conn.name = "MyConnectionName"
conn.odc_file = "C:\\Users\\MyDefaulConnection.odc"
# Change the Command Type, Command and Connection String
dbConn = pycore.as_of(conn, DBConnection) if pycore.is_assignable(conn, DBConnection) else None
dbConn.command_type = OLEDBCommandType.SQL_STATEMENT
dbConn.command = "Select * from AdminTable"
dbConn.connection_info = "Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False"
# Save the workbook
workbook.save(dataDir + "output_out.xlsx")