工作表的查询表读取和写入
Contents
[
Hide
]
Aspose.Cells for Python via .NET提供Worksheet.QueryTables集合,该集合通过索引返回QueryTable对象。它具有以下两个属性
- QueryTable.AdjustColumnWidth
- QueryTable.PreserveFormatting
这两个都是布尔值。你可以在Microsoft Excel中通过数据 > 连接 > 属性查看它们。
工作表的查询表读取和写入
以下示例代码读取第一个工作表的第一个查询表,并打印出两个查询表属性。然后将QueryTable.PreserveFormatting设置为true。
您可以从以下链接下载用于此代码的源Excel文件和代码生成的输出Excel文件。
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
from aspose.cells import Workbook | |
# 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 from source excel file | |
workbook = Workbook(dataDir + "Sample.xlsx") | |
# Access first worksheet | |
worksheet = workbook.worksheets[0] | |
# Access first Query Table | |
qt = worksheet.query_tables[0] | |
# Print Query Table Data | |
print("Adjust Column Width: " + str(qt.adjust_column_width)) | |
print("Preserve Formatting: " + str(qt.preserve_formatting)) | |
# Now set Preserve Formatting to true | |
qt.preserve_formatting = True | |
# Save the workbook | |
workbook.save(dataDir + "Output_out.xlsx") |
控制台输出
这是上述示例代码的控制台输出
Adjust Column Width: True
Preserve Formatting: False
检索查询表结果范围
Aspose.Cells for Python via .NET提供读取查询表结果范围地址的选项。以下代码演示了如何读取查询表的结果范围地址。示例文件可在此处下载。
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
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Create workbook from source excel file | |
wb = Workbook("Query TXT.xlsx") | |
# Display the address(range) of result range of query table | |
print(wb.worksheets[0].query_tables[0].result_range.address) |