使用 Aspose.Cells 利用 OpenXml 的 Sheet.SheetId 属性
Contents
[
Hide
]
可能的使用场景
Sheet.SheetId 属性位于 DocumentFormat.OpenXml.Spreadsheet 命名空间内,是 OpenXml 的一部分。如以下截图所示,你可以在 workbook.xml 中看到此属性及其值。Aspose.Cells for Python via .NET 提供与之对应的 Worksheet.tab_id 属性。
利用 Aspose.Cells for Python Excel 库使用 OpenXml 的 Sheet.SheetId 属性
以下示例代码加载了示例Excel文件,读取其表格或标签ID,然后将其分配为新的标签ID并保存为输出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 | |
# Load source Excel file | |
wb = Workbook("sampleSheetId.xlsx") | |
# Access first worksheet | |
ws = wb.worksheets[0] | |
# Print its Sheet or Tab Id on console | |
print("Sheet or Tab Id: " + str(ws.tab_id)) | |
# Change Sheet or Tab Id | |
ws.tab_id = 358 | |
# Save the workbook | |
wb.save("outputSheetId.xlsx") |
控制台输出
Sheet or Tab Id: 1297