创建工作簿和工作表范围命名范围
Contents
[
Hide
]
Microsoft Excel 允许用户定义具有两种不同范围(工作簿(也称为全局范围)和工作表)的命名范围。
- 具有工作簿范围的命名范围可以通过简单地使用其名称从工作簿内的任何工作表中访问。
- 具有工作表范围的命名范围是通过在其创建的特定工作表的引用中访问的。
Aspose.Cells for Python via .NET 提供了与 Microsoft 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 a new Workbook object | |
workbook = Workbook() | |
# Get first worksheet of the workbook | |
sheet = workbook.worksheets[0] | |
# Get worksheet's cells collection | |
cells = sheet.cells | |
# Create a range of Cells from Cell A1 to C10 | |
workbookScope = cells.create_range("A1", "C10") | |
# Assign the nsame to workbook scope named range | |
workbookScope.name = "workbookScope" | |
# Save the workbook | |
workbook.save(dataDir + "WorkbookScope.out.xlsx") |
如何添加具有工作表作用域的命名区域
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 a new Workbook object | |
workbook = Workbook() | |
# Get first worksheet of the workbook | |
sheet = workbook.worksheets[0] | |
# Get worksheet's cells collection | |
cells = sheet.cells | |
# Create a range of Cells | |
localRange = cells.create_range("A1", "C10") | |
# Assign name to range with sheet raference | |
localRange.name = "Sheet1!local" | |
# Save the workbook | |
workbook.save(dataDir + "ouput.out.xls") |