Worksheet
Worksheet — Single sheet in an Aspose.Cells FOSS Workbook
Properties
Worksheet 表示一个单独的工作表,位于 Workbook.。它提供对该工作表的单元格集合、图表集合、图片集合、形状集合以及自动筛选的访问。工作表可通过索引或名称从 workbook.worksheets.
from aspose.cells_foss import Workbook
workbook = Workbook()
worksheet = workbook.worksheets[0]
worksheet.cells["A1"].value = "Hello"
worksheet.cells["A2"].formula = "=A1"
workbook.save("output.xlsx")Properties
| Properties | Properties | Properties |
|---|---|---|
name | str | 工作表标签名称。Assign 用于重命名工作表。. |
cells | Cells | 此工作表的单元格集合。支持 A1 样式和 (row, col) 索引方式。. |
charts | ChartCollection | 此工作表中嵌入的图表集合。. |
shapes | 集合 | 此工作表中形状(文本框、图片、矩形等)的集合。. |
auto_filter | AutoFilter | 此工作表的自动筛选对象。使用 auto_filter.range 来设置筛选范围。. |
Properties
| Properties | 返回类型 | Properties |
|---|---|---|
protect(password=None) | None | 对工作表进行密码保护,防止编辑。. |
unprotect(password=None) | None | 移除工作表的保护。. |
Properties
以下示例创建一个工作表,设置数值和公式,为标题单元格应用样式,并保存工作簿。.
from aspose.cells_foss import Workbook
workbook = Workbook()
ws = workbook.worksheets[0]
ws.name = "Sales"
# Set header and data values
ws.cells["A1"].value = "Month"
ws.cells["B1"].value = "Revenue"
ws.cells["A2"].value = "January"
ws.cells["B2"].value = 12500
ws.cells["A3"].value = "February"
ws.cells["B3"].value = 14800
# Add a SUM formula
ws.cells["B4"].formula = "=SUM(B2:B3)"
# Apply bold styling to the header row
style = ws.cells["A1"].get_style()
style.font.bold = True
ws.cells["A1"].apply_style(style)
style2 = ws.cells["B1"].get_style()
style2.font.bold = True
ws.cells["B1"].apply_style(style2)
workbook.save("sales_report.xlsx")