# Workbook Interface

The Workbook interface represents the main workbook object that manages worksheets, styles, and workbook-level settings.

## Classes

class oo::iWorkbook

  Main workbook interface for managing worksheets, shared strings, styles, and workbook properties.

  ### Date and Reference Settings

  bool is_date1904() const

    Check if the workbook uses the 1904 date system.

    Returns:

      true if using 1904 date system, false for 1900 date system

  void set_date1904(bool set = true)

    Set the date system used by the workbook.

    Parameters:

      set – true for 1904 date system, false for 1900 date system

  bool is_a1_ref_mode() const

    Check if the workbook uses A1 reference mode.

    Returns:

      true if using A1 reference mode, false for R1C1 mode

  void set_a1_ref_mode(bool a1_mode = true)

    Set the reference mode for the workbook.

    Parameters:

      a1_mode – true for A1 reference mode, false for R1C1 mode

  ### Calculation Settings

  CalcTypeEnum get_calc_mode() const

    Get the calculation mode for the workbook.

    Returns:

      Current calculation mode

  void set_calc_mode(CalcTypeEnum type)

    Set the calculation mode for the workbook.

    Parameters:

      type – Calculation mode to set

  ### Worksheet Management

  iWorksheet *add_worksheet(const char *name = nullptr)

    Add a new worksheet to the workbook.

    Parameters:

      name – Optional name for the new worksheet (Automatically generate worksheet name when name is empty)

    Returns:

      Pointer to the new worksheet, or nullptr if failed

  iWorksheet *insert_worksheet(int index, const char *name = nullptr)

    Insert a worksheet at the specified position.

    Parameters:

      - index – Position to insert the worksheet (0-based)

      - name – Optional name for the new worksheet

    Returns:

      Pointer to the new worksheet, or nullptr if failed

  void shift_sheet(int srcIdx, int dstIdx)

    Move a worksheet from one position to another.

    Parameters:

      - srcIdx – Source index (0-based)

      - dstIdx – Destination index (0-based)

  void delete_sheet(int index)

    Delete a worksheet from the workbook.

    Parameters:

      index – Index of worksheet to delete (0-based)

  ### Worksheet Information

  int sheet_count() const

    Get the number of worksheets in the workbook.

    Returns:

      Number of worksheets

  iWorksheet *get_sheet(int index) const

    Get a worksheet by index.

    Parameters:

      index – Worksheet index (0-based)

    Returns:

      Pointer to worksheet, or nullptr if index is invalid

  SheetTypeEnum sheet_type(int index) const

    Get the type of a worksheet.

    Parameters:

      index – Worksheet index (0-based)

    Returns:

      Type of the worksheet

  SheetStateEnum get_sheet_state(int index) const

    Get the visibility state of a worksheet.

    Parameters:

      index – Worksheet index (0-based)

    Returns:

      Visibility state of the worksheet

  void set_sheet_state(int index, SheetStateEnum state = SHEETSTATE_HIDDEN)

    Set the visibility state of a worksheet.

    Parameters:

      - index – Worksheet index (0-based)

      - state – New visibility state

  ### Worksheet Naming

  const char *sheet_name(int index) const

    Get the name of a worksheet.

    Parameters:

      index – Worksheet index (0-based)

    Returns:

      Name of the worksheet

  void rename_sheet(int index, const char *newname)

    Rename a worksheet.

    Parameters:

      - index – Worksheet index (0-based)

      - newname – New name for the worksheet

  ### Active Sheet Management

  int get_active_sheet() const

    Get the index of the active worksheet.

    Returns:

      Index of active worksheet (0-based)

  bool set_active_sheet(int tab)

    Set the active worksheet.

    Parameters:

      tab – Worksheet index to activate (0-based)

    Returns:

      true if successful, false if index is invalid

  ### Defined Names

  bool set_defined_name(const char *name, const char *expr, const char *local_name = nullptr)

    Set a defined name in the workbook.

    Parameters:

      - name – Name to define

      - expr – Formula expression for the defined name

      - local_name – Local sheet name (optional)

    Returns:

      true if successful

  int defined_name_num()

    Get number of defined names in the workbook.

    Returns:

      Number of defined names.

  const char *get_defined_name(int index, bool *is_local = 0) const

    Get the defined name.

    Parameters:

      - index – Index of defined names.

      - is_local – Is it a locally defined name.

    Returns:

      Defined name.

  const char *get_local_name(int index) const

    Retrieve the worksheet name to which the defined name belongs.

    Parameters:

      index – Index of defined names.

    Returns:

      Worksheet name.

  const char *get_defined_name_expr(int index) const

    Get the expression for a defined name.

    Parameters:

      index – Index of defined names.

    Returns:

      Expression string.

  void delete_defined_name(int index)

    Delete a defined name.

    Parameters:

      index – Index of defined names.

  ### Style Management

  iStyle *get_named_style(const char *name)

    Get a named style from the workbook.

    Parameters:

      name – Name of the style to retrieve

    Returns:

      Pointer to the style, or nullptr if not found

  iStyle *add_custom_style(const char *name, iStyle *style)

    Add a custom named style to the workbook.

    Parameters:

      - name – Name for the new style

      - style – Style object to add

    Returns:

      Pointer to the added style

  bool modify_named_style(const char *name, iStyle *style)

    Modify an existing named style.

    Parameters:

      - name – Name of the style to modify

      - style – New style properties

    Returns:

      true if successful, false if style not found

  ### Style object Creation

  iStyle *make_normal_style()

    Create a new normal style.

    Returns:

      Pointer to new style object

  iRichtext *make_richtext()

    Create a new rich text object.

    Returns:

      Pointer to new rich text object

## Usage Example

    #include "oosxl.hxx"

    using namespace oo;

    // Create document and get workbook
    Document* doc = create_document();
    Workbook* wb = doc->get_workbook();

    // Set workbook properties
    wb->set_date1904(false);  // Use 1900 date system
    wb->set_a1_ref_mode(true); // Use A1 reference mode

    // Add worksheets
    Worksheet* sheet1 = wb->add_worksheet("Data");
    Worksheet* sheet2 = wb->add_worksheet("Summary");

    // Set active sheet
    wb->set_active_sheet(0);

    // Create and use styles
    Style* header_style = wb->make_normal_style();
    header_style->set_bold(true);
    header_style->set_font_size(14);

Styled using the Piccolo Theme