Worksheet

Worksheet predstavlja pojedinačni list unutar a Workbook. Omogućava pristup kolekciji ćelija, kolekciji grafikona, kolekciji slika, kolekciji oblika i automatskom filteru za taj list. Radni listovi se pristupaju po indeksu ili imenu iz 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")
NameTypeAccessDescription
name``Read/WriteGets or sets the name of the worksheet.
cells``ReadGets the Cells collection for this worksheet.
visible``Read/WriteGets or sets the visibility state of the worksheet.
tab_color``Read/WriteGets or sets the tab color of the worksheet.
auto_filter``ReadGets the AutoFilter object for this worksheet.
conditional_formats``ReadGets the collection of conditional formats for this worksheet.
data_validations``ReadGets the collection of data validations for this worksheet.
hyperlinks``ReadGets the collection of hyperlinks for this worksheet.
charts``ReadGets the collection of charts for this worksheet.
shapes``ReadGets the collection of drawing shapes for this worksheet.
tables``ReadGets the collection of structured tables (ListObjects) for this worksheet.
sparkline_groups``ReadGets the collection of sparkline groups for this worksheet.
pictures``ReadGets the collection of pictures for this worksheet.
protection``ReadGets the protection settings for this worksheet.
page_setup``ReadGets the page setup settings for this worksheet.
page_margins``ReadGets the page margins for this worksheet.
properties``ReadGets the worksheet properties.
horizontal_page_breaks``ReadGets manual horizontal page break collection.
vertical_page_breaks``ReadGets manual vertical page break collection.
merged_cells``ReadGets merged cell ranges in A1 notation.
print_area``Read/WriteGets or sets print area in A1 notation.
SignatureDescription
__init__(name)Initializes a new instance of the Worksheet class.
rename(new_name)Renames the worksheet.
set_visibility(value)Set worksheet visibility.
get_visibility()Return current worksheet visibility (True, False, or ‘veryHidden’).
set_tab_color(color)Set the worksheet tab color.
get_tab_color()Return the worksheet tab color (8-char AARRGGBB hex) or None.
clear_tab_color()Clear the worksheet tab color.
set_page_orientation(orientation)Set page orientation.
get_page_orientation()Return the page orientation (‘portrait’, ’landscape’, or None).
set_paper_size(paper_size)Set the paper size (integer code, e.g.
get_paper_size()Return the paper size integer code.
set_page_margins(left, right, top, bottom, header, footer)Set page margins (in inches).
get_page_margins()Return a copy of the page margins dict.
set_fit_to_pages(width, height)Set fit-to-pages: width and height are page counts (0 = auto).
set_print_scale(scale)Set print scale percentage (10–400).
set_print_area(print_area)Sets the worksheet print area.
clear_print_area()Clears the worksheet print area.
SetPrintArea(print_area)
ClearPrintArea()
is_protected()Checks if the worksheet is protected.
protect(password, format_cells, format_columns, format_rows, insert_columns, insert_rows, delete_columns, delete_rows, sort, auto_filter, insert_hyperlinks, pivot_tables, select_locked_cells, select_unlocked_cells, objects, scenarios)Protects the worksheet with optional password and protection options.
unprotect(password)Unprotects the worksheet.
set_view(zoom, show_grid_lines, show_row_col_headers)Sets view options for the worksheet.
copy(name)Creates a copy of the worksheet.
delete()Deletes the worksheet from the workbook.
move(index)Moves the worksheet to the specified position in the workbook.
select()Selects the worksheet.
activate()Activates the worksheet (makes it the active worksheet).
calculate_formula()Calculates formulas in the worksheet.
get_range(start_cell, end_cell)Gets a range of cells.

Sledeći primer kreira radni list, postavlja vrednosti i formulu, primenjuje stil na ćeliju zaglavlja i čuva radnu svesku.

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

Vidi i

 Српски