.. _document-api:

Document Interface
==================

The Document interface represents the main document object that
manages Excel workbooks.

Classes
-------

.. cpp:class:: oo::iDocument

   Main document interface for creating and managing Excel workbooks.

   .. cpp:function:: oo::iWorkbook* get_workbook()

      Get the workbook associated with this document.

      :returns: Pointer to the workbook interface

   .. cpp:function:: bool save(const char* filename = nullptr) const

      Save the document to a file.

      :param filename: Path to save the document. If null, saves to current file.
      :returns: true if successful, false otherwise

   .. cpp:function:: bool save_to_csv(const char* filename = nullptr) const

      Save the current active worksheet to a csv file.

      :param filename: The path and file name where the file will be saved. If NULL, the worksheet name will be used as the csv file name and the csv file will be saved in the current working directory.
      :returns: true if successful, false otherwise

   .. cpp:function:: void release()

      Release the document and free associated resources.

      .. warning::
         This should be called when the document is no longer needed to prevent memory leaks.

Global Functions
----------------

.. cpp:function:: const char* lib_version()

   Get the library version string.

   :returns: Constant string containing library version information

.. cpp:function:: void set_product_key(const char* user, const char* key)

   Set the license key.

   :param user: User name
   :param key: License key

.. cpp:function:: oo::iDocument* create_document()

   Create a new empty document.

   :returns: Pointer to newly created document

.. cpp:function:: oo::iDocument* load_document(const char* filename)

   Load an existing document from file.

   :param filename: Path to the Excel file to load
   :returns: Pointer to loaded document, or nullptr if failed

.. cpp:function:: oo::iCSVPolicy* create_csv_policy()

   Create a new default csv policy.

   :returns: Pointer to newly created csv policy

.. cpp:function:: oo::iDocument* load_csv(const char* filename, const oo::iCSVPolicy* policy)

   Load an existing document from csv file.

   :param filename: Path to the csv file to load
   :param policy: A CSV policy for configuring the parsing rules applied to CSV files.
   :returns: Pointer to loaded document, or nullptr if failed

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

.. code-block:: cpp

   #include "oosxl.hxx"

   // Create a new document
   oo::iDocument* doc = create_document();

   if (doc) {
       // Get workbook and work with sheets
       oo::iWorkbook* workbook = doc->get_workbook();

       // Perform operations...

       // Save document
       doc->save("example.xlsx");

       // Clean up
       doc->release();
   }
