ExcelFile ========= .. cpp:class:: pandas::ExcelFile pandas C++ class. Example ------- .. code-block:: cpp #include using namespace pandas; // Use ExcelFile ExcelFile obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``ExcelFile(const ExcelFile&) = delete`` - pd_excel.h:831 - * - ``ExcelFile(ExcelFile&& other) noexcept`` - pd_excel.h:835 - Type Checking ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool is_open() const`` - bool - pd_excel.h:842 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``void close()`` - void - pd_excel.h:845 - :ref:`View ` * - ``std::string engine() const`` - std::string - pd_excel.h:841 - :ref:`View ` * - ``std::string find_worksheet_path(const std::string& sheet_name)`` - std::string - pd_excel.h:901 - * - ``void load_file()`` - void - pd_excel.h:896 - * - ``void load_shared_strings()`` - void - pd_excel.h:899 - * - ``void load_sheet_data(const std::string& sheet_name)`` - void - pd_excel.h:900 - * - ``void load_sheet_names()`` - void - pd_excel.h:898 - * - ``void parse_zip()`` - void - pd_excel.h:897 - * - ``std::string path() const`` - std::string - pd_excel.h:840 - :ref:`View ` * - ``std::vector sheet_names() const`` - std::vector - pd_excel.h:839 - :ref:`View ` * - ``static std::string unescape_xml(const std::string& str)`` - static std::string - pd_excel.h:902 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-excelfile-is_open-0: .. dropdown:: is_open (pd_test_2_all.cpp:4092) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4082 :emphasize-lines: 11 } if (writer.datetime_format() != "YYYY-MM-DD HH:MM:SS.fff") { std::cout << " [FAIL] : datetime_format property incorrect" << std::endl; throw std::runtime_error("datetime_format property incorrect"); } if (writer.if_sheet_exists() != "replace") { std::cout << " [FAIL] : if_sheet_exists property incorrect" << std::endl; throw std::runtime_error("if_sheet_exists property incorrect"); } if (!writer.is_open()) { std::cout << " [FAIL] : is_open should be true" << std::endl; throw std::runtime_error("is_open should be true"); } writer.close(); if (writer.is_open()) { std::cout << " [FAIL] : is_open should be false after close" << std::endl; throw std::runtime_error("is_open should be false after close"); } .. _example-excelfile-close-1: .. dropdown:: close (pd_test_2_all.cpp:3486) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 3476 :emphasize-lines: 11 // Check ZIP signature (PK..) file.seekg(0, std::ios::beg); char sig[4]; file.read(sig, 4); if (sig[0] != 'P' || sig[1] != 'K' || sig[2] != 0x03 || sig[3] != 0x04) { std::cout << " [FAIL] : in pd_test_excel_basic() : Invalid ZIP signature" << std::endl; throw std::runtime_error("pd_test_excel_basic failed: invalid ZIP signature"); } file.close(); std::cout << " -> tests passed" << std::endl; } // Test Excel export with custom sheet name void pd_test_excel_sheet_name() { std::cout << "========= Excel export with sheet name ============="; std::map> data = { {"X", {1.1, 2.2, 3.3}}, {"Y", {4.4, 5.5, 6.6}} .. _example-excelfile-engine-2: .. dropdown:: engine (pd_test_2_all.cpp:4075) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4065 :emphasize-lines: 11 void pd_test_excel_writer_properties() { std::cout << "========= ExcelWriter properties ==================="; pandas::ExcelWriter writer("temp/test_writer_props.xlsx", "xlsxwriter", "YYYY/MM/DD", "YYYY-MM-DD HH:MM:SS.fff", "w", std::nullopt, "replace"); if (writer.path() != "temp/test_writer_props.xlsx") { std::cout << " [FAIL] : path property incorrect" << std::endl; throw std::runtime_error("path property incorrect"); } if (writer.engine() != "xlsxwriter") { std::cout << " [FAIL] : engine property incorrect: " << writer.engine() << std::endl; throw std::runtime_error("engine property incorrect"); } if (writer.date_format() != "YYYY/MM/DD") { std::cout << " [FAIL] : date_format property incorrect" << std::endl; throw std::runtime_error("date_format property incorrect"); } if (writer.datetime_format() != "YYYY-MM-DD HH:MM:SS.fff") { std::cout << " [FAIL] : datetime_format property incorrect" << std::endl; throw std::runtime_error("datetime_format property incorrect"); .. _example-excelfile-path-3: .. dropdown:: path (pd_test_2_all.cpp:4071) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4061 :emphasize-lines: 11 std::cout << " -> tests passed" << std::endl; } void pd_test_excel_writer_properties() { std::cout << "========= ExcelWriter properties ==================="; pandas::ExcelWriter writer("temp/test_writer_props.xlsx", "xlsxwriter", "YYYY/MM/DD", "YYYY-MM-DD HH:MM:SS.fff", "w", std::nullopt, "replace"); if (writer.path() != "temp/test_writer_props.xlsx") { std::cout << " [FAIL] : path property incorrect" << std::endl; throw std::runtime_error("path property incorrect"); } if (writer.engine() != "xlsxwriter") { std::cout << " [FAIL] : engine property incorrect: " << writer.engine() << std::endl; throw std::runtime_error("engine property incorrect"); } if (writer.date_format() != "YYYY/MM/DD") { std::cout << " [FAIL] : date_format property incorrect" << std::endl; throw std::runtime_error("date_format property incorrect"); .. _example-excelfile-sheet_names-4: .. dropdown:: sheet_names (pd_test_2_all.cpp:4049) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4039 :emphasize-lines: 11 pandas::ExcelWriter writer("temp/test_writer_names.xlsx"); std::map> data = {{"A", {1}}}; pandas::DataFrame df(data); df.to_excel(writer, "First"); df.to_excel(writer, "Second"); df.to_excel(writer, "Third"); auto names = writer.sheet_names(); if (names.size() != 3) { std::cout << " [FAIL] : sheet_names: expected 3, got " << names.size() << std::endl; throw std::runtime_error("sheet_names: wrong count"); } if (names[0] != "First" || names[1] != "Second" || names[2] != "Third") { std::cout << " [FAIL] : sheet_names: wrong order or names" << std::endl; throw std::runtime_error("sheet_names: wrong order"); } writer.close();