Worksheet

Worksheet — Single sheet in an Aspose.Cells FOSS Workbook

Enumerations

Worksheet đại diện cho một trang duy nhất trong một Workbook. Nó cung cấp quyền truy cập vào bộ sưu tập ô, bộ sưu tập biểu đồ, bộ sưu tập hình ảnh, bộ sưu tập hình dạng và bộ lọc tự động cho trang tính đó. Các bảng tính được truy cập bằng chỉ mục hoặc tên từ 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")

Enumerations

EnumerationsEnumerationsEnumerations
namestrTên tab của worksheet. Gán để đổi tên sheet.
cellsCellsBộ sưu tập các ô cho trang tính này. Hỗ trợ chỉ mục kiểu A1 và (hàng, cột).
chartsChartCollectionBộ sưu tập các biểu đồ được nhúng trong trang tính này.
shapesbộ sưu tậpBộ sưu tập các hình dạng (hộp văn bản, hình ảnh, hình chữ nhật, v.v.) trong trang tính này.
auto_filterAutoFilterĐối tượng tự động lọc cho trang tính này. Sử dụng auto_filter.range để đặt phạm vi lọc.

Enumerations

EnumerationsKiểu trả vềEnumerations
protect(password=None)NoneBảo vệ bằng mật khẩu cho bảng tính, ngăn chặn việc chỉnh sửa.
unprotect(password=None)NoneGỡ bỏ bảo vệ khỏi bảng tính.

Enumerations

Ví dụ sau tạo một worksheet, đặt giá trị và công thức, áp dụng kiểu cho ô tiêu đề, và lưu workbook.

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

Xem Thêm

 Tiếng Việt