.. _workbook-api:

Workbook Interface
==================

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

Classes
-------

.. cpp:class:: oo::iWorkbook

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

   Date and Reference Settings
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~

   .. cpp:function:: 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

   .. cpp:function:: void set_date1904(bool set = true)

      Set the date system used by the workbook.

      :param set: true for 1904 date system, false for 1900 date system

   .. cpp:function:: 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

   .. cpp:function:: void set_a1_ref_mode(bool a1_mode = true)

      Set the reference mode for the workbook.

      :param a1_mode: true for A1 reference mode, false for R1C1 mode

   Calculation Settings
   ~~~~~~~~~~~~~~~~~~~~

   .. cpp:function:: CalcTypeEnum get_calc_mode() const

      Get the calculation mode for the workbook.

      :returns: Current calculation mode

   .. cpp:function:: void set_calc_mode(CalcTypeEnum type)

      Set the calculation mode for the workbook.

      :param type: Calculation mode to set

   Worksheet Management
   ~~~~~~~~~~~~~~~~~~~~

   .. cpp:function:: iWorksheet* add_worksheet(const char* name = nullptr)

      Add a new worksheet to the workbook.

      :param 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

   .. cpp:function:: iWorksheet* insert_worksheet(int index, const char* name = nullptr)

      Insert a worksheet at the specified position.

      :param index: Position to insert the worksheet (0-based)
      :param name: Optional name for the new worksheet
      :returns: Pointer to the new worksheet, or nullptr if failed

   .. cpp:function:: void shift_sheet(int srcIdx, int dstIdx)

      Move a worksheet from one position to another.

      :param srcIdx: Source index (0-based)
      :param dstIdx: Destination index (0-based)

   .. cpp:function:: void delete_sheet(int index)

      Delete a worksheet from the workbook.

      :param index: Index of worksheet to delete (0-based)

   Worksheet Information
   ~~~~~~~~~~~~~~~~~~~~~

   .. cpp:function:: int sheet_count() const

      Get the number of worksheets in the workbook.

      :returns: Number of worksheets

   .. cpp:function:: iWorksheet* get_sheet(int index) const

      Get a worksheet by index.

      :param index: Worksheet index (0-based)
      :returns: Pointer to worksheet, or nullptr if index is invalid

   .. cpp:function:: SheetTypeEnum sheet_type(int index) const

      Get the type of a worksheet.

      :param index: Worksheet index (0-based)
      :returns: Type of the worksheet

   .. cpp:function:: SheetStateEnum get_sheet_state(int index) const

      Get the visibility state of a worksheet.

      :param index: Worksheet index (0-based)
      :returns: Visibility state of the worksheet

   .. cpp:function:: void set_sheet_state(int index, SheetStateEnum state = SHEETSTATE_HIDDEN)

      Set the visibility state of a worksheet.

      :param index: Worksheet index (0-based)
      :param state: New visibility state

   Worksheet Naming
   ~~~~~~~~~~~~~~~~

   .. cpp:function:: const char* sheet_name(int index) const

      Get the name of a worksheet.

      :param index: Worksheet index (0-based)
      :returns: Name of the worksheet

   .. cpp:function:: void rename_sheet(int index, const char* newname)

      Rename a worksheet.

      :param index: Worksheet index (0-based)
      :param newname: New name for the worksheet

   Active Sheet Management
   ~~~~~~~~~~~~~~~~~~~~~~~

   .. cpp:function:: int get_active_sheet() const

      Get the index of the active worksheet.

      :returns: Index of active worksheet (0-based)

   .. cpp:function:: bool set_active_sheet(int tab)

      Set the active worksheet.

      :param tab: Worksheet index to activate (0-based)
      :returns: true if successful, false if index is invalid

   Defined Names
   ~~~~~~~~~~~~~

   .. cpp:function:: bool set_defined_name(const char* name, const char* expr, const char* local_name = nullptr)

      Set a defined name in the workbook.

      :param name: Name to define
      :param expr: Formula expression for the defined name
      :param local_name: Local sheet name (optional)
      :returns: true if successful

   .. cpp:function:: int defined_name_num()

      Get number of defined names in the workbook.

      :returns: Number of defined names.

   .. cpp:function:: const char* get_defined_name(int index, bool* is_local = 0) const

      Get the defined name.

      :param index: Index of defined names.
      :param is_local: Is it a locally defined name.
      :returns: Defined name.

   .. cpp:function:: const char* get_local_name(int index) const

      Retrieve the worksheet name to which the defined name belongs.

      :param index: Index of defined names.
      :returns: Worksheet name.

   .. cpp:function:: const char* get_defined_name_expr(int index) const

      Get the expression for a defined name.

      :param index: Index of defined names.
      :returns: Expression string.

   .. cpp:function:: void delete_defined_name(int index)

      Delete a defined name.

      :param index: Index of defined names.

   Style Management
   ~~~~~~~~~~~~~~~~

   .. cpp:function:: iStyle* get_named_style(const char* name)

      Get a named style from the workbook.

      :param name: Name of the style to retrieve
      :returns: Pointer to the style, or nullptr if not found

   .. cpp:function:: iStyle* add_custom_style(const char* name, iStyle* style)

      Add a custom named style to the workbook.

      :param name: Name for the new style
      :param style: Style object to add
      :returns: Pointer to the added style

   .. cpp:function:: bool modify_named_style(const char* name, iStyle* style)

      Modify an existing named style.

      :param name: Name of the style to modify
      :param style: New style properties
      :returns: true if successful, false if style not found

   Style object Creation
   ~~~~~~~~~~~~~~~~~~~~~

   .. cpp:function:: iStyle* make_normal_style()

      Create a new normal style.

      :returns: Pointer to new style object

   .. cpp:function:: iRichtext* make_richtext()

      Create a new rich text object.

      :returns: Pointer to new rich text object

Usage Example
-------------

.. code-block:: cpp

   #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);
