既存の SQL データ接続を変更する

Aspose.Cells for Python via .NET を使用した既存の SQL データ接続の変更

以下のサンプルは、Aspose.Cells for Python via .NET を使用してワークブックの SQL データ接続を変更する例です。このコードで使用されているソース Excel ファイルと、生成された出力 Excel ファイルは以下のリンクからダウンロードできます。

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