Mevcut SQL Veri Bağlantısını değiştir

Aspose.Cells for Python via .NET kullanarak mevcut SQL Veri Bağlantısını değiştir

Aşağıdaki örnek, Aspose.Cells for Python via .NET kullanarak çalışma kitabının SQL Veri Bağlantısını nasıl değiştireceğinizi gösterir. Bu kodda kullanılan kaynak Excel dosyasını ve kod tarafından oluşturulan çıktı Excel dosyasını aşağıdaki bağlantılardan indirebilirsiniz.

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")