### Install xlnt using vcpkg Source: https://github.com/tfussell/xlnt/blob/master/docs/introduction/Installation.md Installs the xlnt library using the vcpkg package manager. Supports both default x86 installation and explicit x64-Windows installation. ```bash .\vcpkg install xlnt .\vcpkg install xlnt:x64-windows ``` -------------------------------- ### Compile xlnt from Source on Ubuntu Source: https://github.com/tfussell/xlnt/blob/master/docs/introduction/Installation.md Steps to compile xlnt from source on Ubuntu 16.04 LTS, including system updates, dependency installation, compiler setup, and the build process using CMake and Make. Requires GCC 6.2.0 or later. ```bash sudo apt-get update sudo apt-get upgrade sudo apt-get install cmake sudo apt-get install zlibc sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt update sudo apt-get upgrade sudo apt-get install gcc-6 g++-6 export CC=/usr/bin/gcc-6 export CXX=/usr/bin/g++-6 git clone https://github.com/tfussell/xlnt.git xlnt --recurse-submodules cd xlnt cmake . make -j 2 sudo make install sudo ldconfig ``` -------------------------------- ### Compile xlnt Static Library with Xcode Project Source: https://github.com/tfussell/xlnt/blob/master/docs/introduction/Installation.md Compiles xlnt as a static library and generates an Xcode project using CMake. Includes instructions for building the project and running tests. Suitable for macOS environments. ```bash mkdir build cd build cmake -D STATIC=ON -G Xcode .. cmake --build . cd bin && ./xlnt.test ``` -------------------------------- ### Read XLSX File to Console (C++) Source: https://github.com/tfussell/xlnt/blob/master/docs/introduction/Examples.md This C++ code snippet demonstrates how to load an XLSX file using the xlnt library and print the string value of each cell to the standard output. It iterates through rows and cells, providing a basic example for getting started with xlnt. ```c++ #include #include int main() { xlnt::workbook wb; wb.load("/home/timothymccallum/test.xlsx"); auto ws = wb.active_sheet(); std::clog << "Processing spread sheet" << std::endl; for (auto row : ws.rows(false)) { for (auto cell : row) { std::clog << cell.to_string() << std::endl; } } std::clog << "Processing complete" << std::endl; return 0; } ``` -------------------------------- ### Compile xlnt from Source using CMake Source: https://github.com/tfussell/xlnt/blob/master/docs/introduction/Installation.md Basic steps to compile xlnt from source using CMake, suitable for various build systems like Make, Ninja, and Xcode. Generates a shared library by default. Assumes you are in the root xlnt directory. ```bash mkdir build cd build cmake .. make -j8 ``` -------------------------------- ### Compile xlnt for Windows x64 with Visual Studio Source: https://github.com/tfussell/xlnt/blob/master/docs/introduction/Installation.md Configures CMake to build xlnt for Windows x64 using the Visual Studio 14 2015 Win64 generator. This command should be run from the build directory. ```bash cmake -G "Visual Studio 14 2015 Win64" .. ``` -------------------------------- ### Install pybind11 Headers and Configuration Files Source: https://github.com/tfussell/xlnt/blob/master/third-party/pybind11/CMakeLists.txt This section handles the installation of pybind11 files when PYBIND11_INSTALL is enabled. It installs the header files to the specified include directory. It also configures and installs the CMake package configuration files (pybind11Config.cmake and pybind11ConfigVersion.cmake) and helper scripts (FindPythonLibsNew.cmake, pybind11Tools.cmake) to a designated CMake configuration directory. ```cmake if (PYBIND11_INSTALL) install(FILES ${PYBIND11_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pybind11) # GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share". set(PYBIND11_CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}" CACHE STRING "install path for pybind11Config.cmake") configure_package_config_file(tools/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) # Remove CMAKE_SIZEOF_VOID_P from ConfigVersion.cmake since the library does # not depend on architecture specific settings or libraries. set(_PYBIND11_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) unset(CMAKE_SIZEOF_VOID_P) write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake VERSION ${${PROJECT_NAME}_VERSION} COMPATIBILITY AnyNewerVersion) set(CMAKE_SIZEOF_VOID_P ${_PYBIND11_CMAKE_SIZEOF_VOID_P}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake tools/FindPythonLibsNew.cmake tools/pybind11Tools.cmake DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) endif() ``` -------------------------------- ### Install License File (CMake) Source: https://github.com/tfussell/xlnt/blob/master/source/CMakeLists.txt Installs the LICENSE.md file to the man3 directory, making license information accessible. This is a standard practice for open-source projects. ```cmake install(FILES ${XLNT_ROOT_DIR}/docs/xlnt.3 DESTINATION ${XLNT_MAN_DEST_DIR}/man3) ``` -------------------------------- ### Install Include Directory (CMake) Source: https://github.com/tfussell/xlnt/blob/master/source/CMakeLists.txt Installs the public header files for the xlnt library. It copies the contents of the `xlnt` include directory to the specified installation destination, excluding macOS specific files like `.DS_Store`. ```cmake install(DIRECTORY ${XLNT_INCLUDE_DIR}/xlnt DESTINATION ${XLNT_INC_DEST_DIR} PATTERN ".DS_Store" EXCLUDE) ``` -------------------------------- ### CMake Build Configuration and Options Source: https://github.com/tfussell/xlnt/blob/master/third-party/pybind11/CMakeLists.txt Configures the minimum CMake version, project name, and sets options for installation and testing. It also manages the module path and includes external CMake scripts. ```cmake cmake_minimum_required(VERSION 2.8.12) if (POLICY CMP0048) # cmake warns if loaded from a min-3.0-required parent dir, so silence the warning: cmake_policy(SET CMP0048 NEW) endif() project(pybind11) # Check if pybind11 is being used directly or via add_subdirectory set(PYBIND11_MASTER_PROJECT OFF) if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(PYBIND11_MASTER_PROJECT ON) endif() option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT}) option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT}) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/tools") include(pybind11Tools) # Cache variables so pybind11_add_module can be used in parent projects set(PYBIND11_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/include" CACHE INTERNAL "") set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} CACHE INTERNAL "") set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} CACHE INTERNAL "") set(PYTHON_MODULE_PREFIX ${PYTHON_MODULE_PREFIX} CACHE INTERNAL "") set(PYTHON_MODULE_EXTENSION ${PYTHON_MODULE_EXTENSION} CACHE INTERNAL "") # NB: when adding a header don't forget to also add it to setup.py set(PYBIND11_HEADERS include/pybind11/attr.h include/pybind11/buffer_info.h include/pybind11/cast.h include/pybind11/chrono.h include/pybind11/class_support.h include/pybind11/common.h include/pybind11/complex.h include/pybind11/descr.h include/pybind11/options.h include/pybind11/eigen.h include/pybind11/embed.h include/pybind11/eval.h include/pybind11/functional.h include/pybind11/numpy.h include/pybind11/operators.h include/pybind11/pybind11.h include/pybind11/pytypes.h include/pybind11/stl.h include/pybind11/stl_bind.h include/pybind11/typeid.h ) string(REPLACE "include/" "${CMAKE_CURRENT_SOURCE_DIR}/include/" PYBIND11_HEADERS "${PYBIND11_HEADERS}") if (PYBIND11_TEST) add_subdirectory(tests) endif() include(GNUInstallDirs) include(CMakePackageConfigHelpers) ``` -------------------------------- ### Install Library and Export Targets (CMake) Source: https://github.com/tfussell/xlnt/blob/master/source/CMakeLists.txt Installs the built xlnt library to the specified destination directories and exports its targets for use by other CMake projects. This makes the library available for linking and usage. ```cmake install(TARGETS xlnt EXPORT XlntTargets LIBRARY DESTINATION ${XLNT_LIB_DEST_DIR} ARCHIVE DESTINATION ${XLNT_LIB_DEST_DIR} RUNTIME DESTINATION ${XLNT_BIN_DEST_DIR}) install(EXPORT XlntTargets FILE XlntTargets.cmake NAMESPACE xlnt:: DESTINATION ${XLNT_CMAKE_CFG_DEST_DIR}) ``` -------------------------------- ### CMake: Set Default Installation Paths Source: https://github.com/tfussell/xlnt/blob/master/source/CMakeLists.txt This snippet configures default installation directories for headers, libraries, binaries, man pages, and CMake configuration files. It uses CMake's built-in variables and respects the project name. ```cmake include(GNUInstallDirs) set(XLNT_INC_DEST_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Default location to install include files") set(XLNT_LIB_DEST_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Default location to install library files") set(XLNT_BIN_DEST_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Default location to install runtime files") set(XLNT_MAN_DEST_DIR ${CMAKE_INSTALL_MANDIR} CACHE PATH "Default location to install runtime files") set(XLNT_CMAKE_CFG_DEST_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} CACHE PATH "Default location to install CMake config files") ``` -------------------------------- ### CMake: Set Default Install Prefix Source: https://github.com/tfussell/xlnt/blob/master/source/CMakeLists.txt This code block sets a default installation prefix for the project if one is not explicitly provided. It differentiates between Windows (MSVC) and other platforms, installing to the build directory on Windows and /usr/local otherwise. ```cmake if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) # Set a default CMAKE_INSTALL_PREFIX if one wasn't specified if(MSVC) # No good place to install on Windows so just install to cmake build directory in /installed set(DEFAULT_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/installed") else() # Install to /usr/local on other platforms set(DEFAULT_INSTALL_PREFIX "/usr/local") endif() # Apply the variable and save to cache set(CMAKE_INSTALL_PREFIX ${DEFAULT_INSTALL_PREFIX} CACHE PATH "default install path" FORCE) endif() ``` -------------------------------- ### CMake Project Setup for xlnt Source: https://github.com/tfussell/xlnt/blob/master/source/CMakeLists.txt This snippet defines the CMake version, project name, and version. It sets the C++ standard to be used and enforces its requirement. It also defines project metadata such as vendor, contact, URL, and description. ```cmake cmake_minimum_required(VERSION 3.1) project(xlnt VERSION 1.5.0) set(CMAKE_CXX_STANDARD ${XLNT_CXX_LANG}) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CXX_EXTENSIONS OFF) # Project metadata set(PROJECT_VENDOR "Thomas Fussell") set(PROJECT_CONTACT "thomas.fussell@gmail.com") set(PROJECT_URL "https://github.com/tfussell/xlnt") set(PROJECT_DESCRIPTION "cross-platform user-friendly xlsx library for C++11") ``` -------------------------------- ### Install pybind11 Targets (CMake >= 3.0) Source: https://github.com/tfussell/xlnt/blob/master/third-party/pybind11/CMakeLists.txt This code block, executed for CMake version 3.0 and above when PYBIND11_INSTALL is enabled, installs the defined interface library targets ('pybind11', 'module', 'embed'). It exports these targets under the namespace 'PROJECT_NAME::' to the specified CMake configuration directory, allowing other projects to easily find and link against pybind11. ```cmake if (PYBIND11_INSTALL) if(NOT (CMAKE_VERSION VERSION_LESS 3.0)) install(TARGETS pybind11 module embed EXPORT "${PROJECT_NAME}Targets") install(EXPORT "${PROJECT_NAME}Targets" NAMESPACE "${PROJECT_NAME}::" DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) endif() endif() ``` -------------------------------- ### Set Up pkg-config Variables (CMake) Source: https://github.com/tfussell/xlnt/blob/master/source/CMakeLists.txt Configures variables for pkg-config, a helper tool used to retrieve information about installed libraries. This section defines paths and flags necessary for pkg-config to correctly identify and use the xlnt library on non-MSVC systems. ```cmake if(NOT MSVC) # Set pkg-config variables set(PKG_CONFIG_LIBDIR ${XLNT_LIB_DEST_DIR}) set(PKG_CONFIG_INCLUDEDIR ${XLNT_INC_DEST_DIR}) set(PKG_CONFIG_LIBS "-L\${libdir} -lxlnt") set(PKG_CONFIG_CFLAGS "-I\${includedir}") # Replace variables in pkg-config template configure_file("${XLNT_ROOT_DIR}/cmake/pkg-config.pc.cmake" "${CMAKE_CURRENT_BINARY_DIR}/xlnt.pc") # pkg-config install install(FILES "${CMAKE_CURRENT_BINARY_DIR}/xlnt.pc" DESTINATION ${XLNT_LIB_DEST_DIR}/pkgconfig) endif() ``` -------------------------------- ### Store XLSX Data in 2D Vector (C++) Source: https://github.com/tfussell/xlnt/blob/master/docs/introduction/Examples.md This C++ code snippet shows how to load an XLSX file using xlnt and store its entire content into a 2D std::vector. This allows for high-performance data processing and lookups. The example includes iterating through the loaded vector to print its contents. ```c++ #include #include #include int main() { xlnt::workbook wb; wb.load("/home/timothymccallum/test.xlsx"); auto ws = wb.active_sheet(); std::clog << "Processing spread sheet" << std::endl; std::clog << "Creating a single vector which stores the whole spread sheet" << std::endl; std::vector< std::vector > theWholeSpreadSheet; for (auto row : ws.rows(false)) { std::clog << "Creating a fresh vector for just this row in the spread sheet" << std::endl; std::vector aSingleRow; for (auto cell : row) { std::clog << "Adding this cell to the row" << std::endl; aSingleRow.push_back(cell.to_string()); } std::clog << "Adding this entire row to the vector which stores the whole spread sheet" << std::endl; theWholeSpreadSheet.push_back(aSingleRow); } std::clog << "Processing complete" << std::endl; std::clog << "Reading the vector and printing output to the screen" << std::endl; for (int rowInt = 0; rowInt < theWholeSpreadSheet.size(); rowInt++) { for (int colInt = 0; colInt < theWholeSpreadSheet.at(rowInt).size(); colInt++) { std::cout << theWholeSpreadSheet.at(rowInt).at(colInt) << std::endl; } } return 0; } ``` -------------------------------- ### Write Bulk Data to Spreadsheet in C++ Source: https://context7.com/tfussell/xlnt/llms.txt Provides a C++ example using the xlnt library to programmatically generate large spreadsheets. It demonstrates preparing data in a 2D vector and efficiently writing it to an xlnt worksheet, with a note on handling 1-based Excel indexing versus 0-based vector indexing. ```cpp #include #include #include int main() { // Prepare data in 2D vector std::vector> data; for (int row = 0; row < 100; row++) { std::vector row_data; for (int col = 0; col < 100; col++) { row_data.push_back(std::to_string(col + 1)); } data.push_back(row_data); } // Create workbook and write data xlnt::workbook wb; xlnt::worksheet ws = wb.active_sheet(); ws.title("data"); // Write vector data to worksheet // Note: Excel cells are 1-indexed, vectors are 0-indexed for (size_t row_idx = 0; row_idx < data.size(); row_idx++) { for (size_t col_idx = 0; col_idx < data[row_idx].size(); col_idx++) { // cell_reference(column, row) - both 1-indexed ws.cell(xlnt::cell_reference(col_idx + 1, row_idx + 1)) .value(data[row_idx][col_idx]); } } wb.save("output.xlsx"); return 0; } ``` -------------------------------- ### Write 2D Vector Data to XLSX Spreadsheet (C++) Source: https://github.com/tfussell/xlnt/blob/master/docs/introduction/Examples.md This C++ code snippet demonstrates how to create a new XLSX spreadsheet and populate it with data from a 2D std::vector. It utilizes the xlnt library for spreadsheet manipulation. The code handles the conversion from 0-based vector indexing to 1-based Excel cell referencing. It takes no explicit input but generates an 'output.xlsx' file. ```c++ #include #include #include #include int main() { //Creating a 2 dimensional vector which we will write values to std::vector< std::vector > wholeWorksheet; //Looping through each row (100 rows as per the second argument in the for loop) for (int outer = 0; outer < 100; outer++) { //Creating a fresh vector for a fresh row std::vector singleRow; //Looping through each of the columns (100 as per the second argument in the for loop) in this particular row for(int inner = 0; inner < 100; inner++) { //Adding a single value in each cell of the row std::string val = std::to_string(inner + 1); singleRow.push_back(val); } //Adding the single row to the 2 dimensional vector wholeWorksheet.push_back(singleRow); std::clog << "Writing to row " << outer << " in the vector " << std::endl; } //Writing to the spread sheet //Creating the output workbook std::clog << "Creating workbook" << std::endl; xlnt::workbook wbOut; //Setting the destination output file name std::string dest_filename = "output.xlsx"; //Creating the output worksheet xlnt::worksheet wsOut = wbOut.active_sheet(); //Giving the output worksheet a title/name wsOut.title("data"); //We will now be looping through the 2 dimensional vector which we created above //In this case we have two iterators one for the outer loop (row) and one for the inner loop (column) std::clog << "Looping through vector and writing to spread sheet" << std::endl; for (int fOut = 0; fOut < wholeWorksheet.size(); fOut++) { std::clog << "Row" << fOut << std::endl; for (int fIn = 0; fIn < wholeWorksheet.at(fOut).size(); fIn++) { //Take notice of the difference between accessing the vector and accessing the work sheet //As you may already know Excel spread sheets start at row 1 and column 1 (not row 0 and column 0 like you would expect from a C++ vector) //In short the xlnt cell reference starts at column 1 row 1 (hence the + 1s below) and the vector reference starts at row 0 and column 0 wsOut.cell(xlnt::cell_reference(fIn + 1, fOut + 1)).value(wholeWorksheet.at(fOut).at(fIn)); //Further clarification to avoid confusion //Cell reference arguments are (column number, row number); e.g. cell_reference(fIn + 1, fOut + 1) //Vector arguments are (row number, column number); e.g. wholeWorksheet.at(fOut).at(fIn) } } std::clog << "Finished writing spread sheet" << std::endl; wbOut.save(dest_filename); return 0; } ``` -------------------------------- ### Configure Uninstall Target (CMake) Source: https://github.com/tfussell/xlnt/blob/master/source/CMakeLists.txt Sets up a custom `uninstall` target for the CMake build system. This target, when executed, runs a script generated from a template to remove installed files, allowing for clean uninstallation. ```cmake if(NOT TARGET uninstall) # Configure uninstall configure_file("${XLNT_ROOT_DIR}/cmake/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) # Add uninstall target add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) endif() ``` -------------------------------- ### Define pybind11 Interface Library Target (CMake >= 3.0) Source: https://github.com/tfussell/xlnt/blob/master/third-party/pybind11/CMakeLists.txt This code block defines the main 'pybind11' interface library target for CMake version 3.0 and above. It creates an INTERFACE library, an ALIAS target for 'pybind11::pybind11', and specifies include directories for both build and install time. It also sets compile options based on the PYBIND11_CPP_STANDARD. ```cmake if(NOT (CMAKE_VERSION VERSION_LESS 3.0)) # CMake >= 3.0 # Build an interface library target: add_library(pybind11 INTERFACE) add_library(pybind11::pybind11 ALIAS pybind11) # to match exported target target_include_directories(pybind11 INTERFACE $ $ $) target_compile_options(pybind11 INTERFACE $) endif() ``` -------------------------------- ### Manage Cell Comments and Annotations (C++) Source: https://context7.com/tfussell/xlnt/llms.txt Provides examples for adding simple text comments, comments with custom font formatting (bold, size, color), and retrieving comment details such as text and author. It also demonstrates how to check for the existence of a comment and remove it. ```cpp #include int main() { xlnt::workbook wb; xlnt::worksheet ws = wb.active_sheet(); // Add simple comment ws.cell("A1").value("Important data"); ws.cell("A1").comment("This value needs review", "John Doe"); // Add comment with custom font xlnt::font comment_font; comment_font.bold(true); comment_font.size(12); comment_font.color(xlnt::color::red()); ws.cell("B2").value("Critical item"); ws.cell("B2").comment("URGENT: Check this!", comment_font, "Manager"); // Check if cell has comment if (ws.cell("A1").has_comment()) { auto comment_obj = ws.cell("A1").comment(); std::string comment_text = comment_obj.text(); std::string author = comment_obj.author(); } // Remove comment ws.cell("A1").clear_comment(); wb.save("with_comments.xlsx"); return 0; } ``` -------------------------------- ### Setting Workbook Properties in C++ with xlnt Source: https://github.com/tfussell/xlnt/blob/master/docs/advanced/Properties.md This snippet illustrates how to set core, extended, and custom properties for an Excel workbook using the xlnt library in C++. It covers a wide range of metadata fields including author, title, creation date, and application-specific information. The workbook is then saved to a file. ```c++ xlnt::workbook wb; wb.core_property(xlnt::core_property::category, "hors categorie"); wb.core_property(xlnt::core_property::content_status, "good"); wb.core_property(xlnt::core_property::created, xlnt::datetime(2017, 1, 15)); wb.core_property(xlnt::core_property::creator, "me"); wb.core_property(xlnt::core_property::description, "description"); wb.core_property(xlnt::core_property::identifier, "id"); wb.core_property(xlnt::core_property::keywords, { "wow", "such" }); wb.core_property(xlnt::core_property::language, "Esperanto"); wb.core_property(xlnt::core_property::last_modified_by, "someone"); wb.core_property(xlnt::core_property::last_printed, xlnt::datetime(2017, 1, 15)); wb.core_property(xlnt::core_property::modified, xlnt::datetime(2017, 1, 15)); wb.core_property(xlnt::core_property::revision, "3"); wb.core_property(xlnt::core_property::subject, "subject"); wb.core_property(xlnt::core_property::title, "title"); wb.core_property(xlnt::core_property::version, "1.0"); wb.extended_property(xlnt::extended_property::application, "xlnt"); wb.extended_property(xlnt::extended_property::app_version, "0.9.3"); wb.extended_property(xlnt::extended_property::characters, 123); wb.extended_property(xlnt::extended_property::characters_with_spaces, 124); wb.extended_property(xlnt::extended_property::company, "Incorporated Inc."); wb.extended_property(xlnt::extended_property::dig_sig, "?"); wb.extended_property(xlnt::extended_property::doc_security, 0); wb.extended_property(xlnt::extended_property::heading_pairs, true); wb.extended_property(xlnt::extended_property::hidden_slides, false); wb.extended_property(xlnt::extended_property::h_links, 0); wb.extended_property(xlnt::extended_property::hyperlink_base, 0); wb.extended_property(xlnt::extended_property::hyperlinks_changed, true); wb.extended_property(xlnt::extended_property::lines, 42); wb.extended_property(xlnt::extended_property::links_up_to_date, false); wb.extended_property(xlnt::extended_property::manager, "johnny"); wb.extended_property(xlnt::extended_property::m_m_clips, "?"); wb.extended_property(xlnt::extended_property::notes, "note"); wb.extended_property(xlnt::extended_property::pages, 19); wb.extended_property(xlnt::extended_property::paragraphs, 18); wb.extended_property(xlnt::extended_property::presentation_format, "format"); wb.extended_property(xlnt::extended_property::scale_crop, true); wb.extended_property(xlnt::extended_property::shared_doc, false); wb.extended_property(xlnt::extended_property::slides, 17); wb.extended_property(xlnt::extended_property::template_, "template!"); wb.extended_property(xlnt::extended_property::titles_of_parts, { "title" }); wb.extended_property(xlnt::extended_property::total_time, 16); wb.extended_property(xlnt::extended_property::words, 101); wb.custom_property("test", { 1, 2, 3 }); wb.custom_property("Editor", "John Smith"); wb.save("lots_of_properties.xlsx"); ``` -------------------------------- ### Fetch Google Benchmark Dependency with CMake Source: https://github.com/tfussell/xlnt/blob/master/benchmarks/microbenchmarks/CMakeLists.txt This snippet demonstrates how to declare and download the Google Benchmark library using CMake's FetchContent module. It ensures the dependency is available for the project and configures its build settings, such as disabling tests. This is useful for projects that need to integrate external libraries seamlessly during the build process. ```cmake cmake_minimum_required(VERSION 3.11) project(xlnt_ubench) set(BENCHMARK_ENABLE_TESTING OFF) set(BENCHMARK_ENABLE_GTEST_TESTS OFF) include(FetchContent) FetchContent_Declare( googlebenchmark GIT_REPOSITORY https://github.com/google/benchmark GIT_TAG v1.5.0 ) FetchContent_GetProperties(googlebenchmark) if(NOT googlebenchmark_POPULATED) FetchContent_Populate(googlebenchmark) add_subdirectory(${googlebenchmark_SOURCE_DIR} ${googlebenchmark_BINARY_DIR}) endif() FetchContent_MakeAvailable(googlebenchmark) ``` -------------------------------- ### CMake Build Configuration for xlnt Samples Source: https://github.com/tfussell/xlnt/blob/master/samples/CMakeLists.txt This snippet configures the CMake build for the xlnt library samples. It sets the minimum CMake version, project name, enforces C++11 standard, includes the xlnt library, and defines custom build options like STATIC_CRT. It also sets a directory for sample data. ```cmake cmake_minimum_required(VERSION 3.1) project(xlnt.samples) # Require C++11 compiler set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) if(NOT COMBINED_PROJECT) # Include xlnt library add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../source ${CMAKE_CURRENT_BINARY_DIR}/source) endif() if(STATIC_CRT) include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/ucm.cmake) ucm_set_runtime(STATIC) endif() set(XLNT_SAMPLE_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data) ``` -------------------------------- ### CMake Executable Definition and Linking for Benchmarks Source: https://github.com/tfussell/xlnt/blob/master/benchmarks/CMakeLists.txt Defines and links individual benchmark executables. For each C++ source file found, it creates a corresponding executable, links it to the 'xlnt' library, and adds necessary include directories and compile definitions. It also includes logic for post-build custom commands on MSVC. ```cmake foreach(BENCHMARK_SOURCE IN ITEMS ${BENCHMARK_SOURCES}) # Convert .cpp to benchmark- get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) set(BENCHMARK_EXECUTABLE benchmark-${BENCHMARK_NAME}) add_executable(${BENCHMARK_EXECUTABLE} ${BENCHMARK_SOURCE}) target_link_libraries(${BENCHMARK_EXECUTABLE} PRIVATE xlnt) # Need to use some test helpers target_include_directories(${BENCHMARK_EXECUTABLE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../tests) target_compile_definitions(${BENCHMARK_EXECUTABLE} PRIVATE XLNT_BENCHMARK_DATA_DIR=${XLNT_BENCHMARK_DATA_DIR}) if(MSVC AND NOT STATIC) # Copy xlnt DLL into benchmarks directory add_custom_command(TARGET ${BENCHMARK_EXECUTABLE} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $) endif() endforeach() ``` -------------------------------- ### CMake Configuration for libstudxml Build Source: https://github.com/tfussell/xlnt/blob/master/third-party/libstudxml.build/CMakeLists.txt This snippet configures the build for the libstudxml library using CMake. It sets the minimum CMake version, project name, C++ standard to C++11, and defines source files for the main library, genx, and expat. It also sets up compiler definitions and include directories, with conditional logic for static linking and MSVC warnings. ```cmake cmake_minimum_required(VERSION 3.1) project(libstudxml) # Require C++11 compiler set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(LIBSTUDXML_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../libstudxml) set(LIBSTUDXML_INCLUDE_DIR ${LIBSTUDXML_ROOT_DIR}/../libstudxml) if(STATIC_CRT) include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/ucm.cmake) ucm_set_runtime(STATIC) endif() set(LIBSTUDXML ${LIBSTUDXML_ROOT_DIR}/libstudxml/parser.cxx ${LIBSTUDXML_ROOT_DIR}/libstudxml/qname.cxx ${LIBSTUDXML_ROOT_DIR}/libstudxml/serializer.cxx ${LIBSTUDXML_ROOT_DIR}/libstudxml/value-traits.cxx ${LIBSTUDXML_ROOT_DIR}/libstudxml/content.hxx ${LIBSTUDXML_ROOT_DIR}/libstudxml/exception.hxx ${LIBSTUDXML_ROOT_DIR}/libstudxml/forward.hxx ${LIBSTUDXML_ROOT_DIR}/libstudxml/parser ${LIBSTUDXML_ROOT_DIR}/libstudxml/qname ${LIBSTUDXML_ROOT_DIR}/libstudxml/serializer ${LIBSTUDXML_ROOT_DIR}/libstudxml/value-traits) set(GENX ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/genx/char-props.c ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/genx/genx.c ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/genx/genx.h) set(EXPAT ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/xmlparse.c ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/xmlrole.c ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/xmltok.c ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/ascii.h ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/asciitab.h ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/config.h ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/expat_external.h ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/expat.h ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/iasciitab.h ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/internal.h ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/latin1tab.h ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/nametab.h ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/utf8tab.h ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/xmlrole.h ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/xmltok_impl.h ${LIBSTUDXML_ROOT_DIR}/libstudxml/details/expat/xmltok.h) add_library(libstudxml OBJECT ${LIBSTUDXML} ${GENX} ${EXPAT}) target_compile_definitions(libstudxml PUBLIC LIBSTUDXML_STATIC_LIB=1) target_include_directories(libstudxml PUBLIC ${LIBSTUDXML_ROOT_DIR} PUBLIC ${EXPAT_INCLUDE_DIRS}) if(STATIC) target_compile_definitions(libstudxml PUBLIC XML_STATIC=1) endif() # Prevent warning C4996 caused by strcpy, strncpy, sprintf in genx # TODO: would it be better to define this only in genx.c? if(MSVC) target_compile_definitions(libstudxml PRIVATE _CRT_SECURE_NO_WARNINGS=1) endif() # Build with -fPIC when xlnt is a shared library # TODO: is this still necessary? try removing if(NOT STATIC) set_target_properties(libstudxml PROPERTIES POSITION_INDEPENDENT_CODE 1) endif() # When xlnt is a static library, assume expat will be linked statically too # TODO: is this a valid assumption? if(STATIC) target_compile_definitions(libstudxml PUBLIC XML_STATIC=1) endif() ``` -------------------------------- ### xlnt::cell_reference::row Source: https://github.com/tfussell/xlnt/blob/master/docs/api/cell_reference.md Methods to get and set the row of a cell reference using its 1-indexed numeric index. ```APIDOC ## `xlnt::cell_reference::row` ### Description These methods allow you to retrieve or set the row part of a cell reference using its 1-indexed numeric index. ### Method - `row_t xlnt::cell_reference::row() const` - `void xlnt::cell_reference::row(row_t row)` ### Parameters #### Path Parameters - `row` (row_t) - Required - The 1-indexed numeric index of the row. ### Response #### Success Response (200) - Getter method returns the row index (`row_t`). - Setter method returns `void`. ``` -------------------------------- ### Define and Link xlnt Sample Executables Source: https://github.com/tfussell/xlnt/blob/master/samples/CMakeLists.txt This CMake snippet defines executable targets for each C++ sample file found in the current directory. It dynamically generates executable names (e.g., sample-my_sample), links them against the 'xlnt' library, and sets necessary include directories and compile definitions. ```cmake file(GLOB SAMPLE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) foreach(SAMPLE_SOURCE IN ITEMS ${SAMPLE_SOURCES}) # Convert .cpp to sample- get_filename_component(SAMPLE_NAME ${SAMPLE_SOURCE} NAME_WE) set(SAMPLE_EXECUTABLE sample-${SAMPLE_NAME}) add_executable(${SAMPLE_EXECUTABLE} ${SAMPLE_SOURCE}) target_link_libraries(${SAMPLE_EXECUTABLE} PRIVATE xlnt) # Need to use some test helpers target_include_directories(${SAMPLE_EXECUTABLE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../tests) target_compile_definitions(${SAMPLE_EXECUTABLE} PRIVATE XLNT_SAMPLE_DATA_DIR=${XLNT_SAMPLE_DATA_DIR}) ``` -------------------------------- ### xlnt::cell_reference::column & column_index Source: https://github.com/tfussell/xlnt/blob/master/docs/api/cell_reference.md Methods to get and set the column of a cell reference, either by its string representation or its 1-indexed numeric index. ```APIDOC ## `xlnt::cell_reference::column` and `xlnt::cell_reference::column_index` ### Description These methods allow you to retrieve or set the column part of a cell reference. You can use either the string representation (e.g., "A", "B") or the 1-indexed numeric index. ### Method - `column_t xlnt::cell_reference::column() const` - `void xlnt::cell_reference::column(const std::string &column_string)` - `column_t::index_t xlnt::cell_reference::column_index() const` - `void xlnt::cell_reference::column_index(column_t column)` ### Parameters #### Path Parameters - `column_string` (const std::string&) - Required - The string representation of the column (e.g., "A"). - `column` (column_t) - Required - The 1-indexed numeric index of the column. ### Response #### Success Response (200) - Getter methods return the column identifier (`column_t` or `column_t::index_t`). - Setter methods return `void`. ``` -------------------------------- ### Define Executable and Link Libraries in CMake Source: https://github.com/tfussell/xlnt/blob/master/benchmarks/microbenchmarks/CMakeLists.txt This CMake snippet defines an executable target 'xlnt_ubench' and specifies its source files and linked libraries. It also sets the required C++ standard to C++17. This is a common pattern for configuring build targets in C++ projects. ```cmake add_executable(xlnt_ubench) target_sources(xlnt_ubench PRIVATE string_to_double.cpp double_to_string.cpp ) target_link_libraries(xlnt_ubench benchmark_main xlnt) target_compile_features(xlnt_ubench PRIVATE cxx_std_17) ``` -------------------------------- ### Set macOS Deployment Target Source: https://github.com/tfussell/xlnt/blob/master/source/CMakeLists.txt On Apple platforms, this block prevents a warning related to the deployment target not being set. It executes a command to get the current macOS product version and sets CMAKE_OSX_DEPLOYMENT_TARGET accordingly. This ensures compatibility with older macOS versions. ```cmake if(APPLE) # Prevent a warning about deployment target not being set by setting it to current OSX version execute_process(COMMAND "sw_vers -productVersion | awk -F'.' '{print $1"."$2}'" OUTPUT_VARIABLE OSX_VERSION) set(CMAKE_OSX_DEPLOYMENT_TARGET ${OSX_VERSION}) endif() ``` -------------------------------- ### MSVC DLL Copy Command for xlnt Samples Source: https://github.com/tfussell/xlnt/blob/master/samples/CMakeLists.txt This CMake code is specifically for the MSVC compiler and non-static builds. It adds a custom post-build command to copy the 'xlnt' dynamic-link library (DLL) to the output directory of the sample executable, ensuring the executable can find its dependency at runtime. ```cmake if(MSVC AND NOT STATIC) # Copy xlnt DLL into samples directory add_custom_command(TARGET ${SAMPLE_EXECUTABLE} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $) endif() endforeach() ``` -------------------------------- ### CMake Build Configuration for xlnt Benchmarks Source: https://github.com/tfussell/xlnt/blob/master/benchmarks/CMakeLists.txt Configures the CMake build for xlnt benchmarks. It specifies the minimum CMake version, project name, C++ standard requirement, and includes the xlnt library. It also sets up benchmark data directory and dynamically finds benchmark source files. ```cmake cmake_minimum_required(VERSION 3.1) project(xlnt.benchmarks) # Require C++11 compiler set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) if(NOT COMBINED_PROJECT) # Include xlnt library add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../source ${CMAKE_CURRENT_BINARY_DIR}/source) endif() if(STATIC_CRT) include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/ucm.cmake) ucm_set_runtime(STATIC) endif() set(XLNT_BENCHMARK_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data) file(GLOB BENCHMARK_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) ``` -------------------------------- ### xlnt C++ Workbook Creation and Cell Access Source: https://github.com/tfussell/xlnt/blob/master/docs/advanced/Formatting.md Demonstrates the basic creation of an xlnt workbook and accessing a specific cell. This is a foundational step for further manipulation. ```c++ #include #include int main() { xlnt::workbook wb; auto cell = wb.active_sheet().cell("A1"); return 0; } ``` -------------------------------- ### CMake: Configure Include Directories Source: https://github.com/tfussell/xlnt/blob/master/source/CMakeLists.txt This snippet configures the include directories for the xlnt target. It specifies build-time and install-time include paths for public headers, and also includes private directories for internal headers and third-party libraries. ```cmake # Includes target_include_directories(xlnt PUBLIC $ $ PRIVATE ${XLNT_SOURCE_DIR} ${XLNT_SOURCE_DIR}/../third-party/libstudxml ${XLNT_SOURCE_DIR}/../third-party/miniz ${XLNT_SOURCE_DIR}/../third-party/utfcpp) ``` -------------------------------- ### CMake: Define Library Targets and Sources Source: https://github.com/tfussell/xlnt/blob/master/source/CMakeLists.txt This snippet defines the main library targets (xlnt) and lists the source and header files to be compiled. It handles both shared and static library builds based on the 'STATIC' variable. ```cmake set(XLNT_HEADERS ${ROOT_HEADERS} ${CELL_HEADERS} ${CHARTS_HEADERS} ${CHARTSHEET_HEADERS} ${DRAWING_HEADERS} ${FORMULA_HEADERS} ${PACKAGING_HEADERS} ${STYLES_HEADERS} ${UTILS_HEADERS} ${WORKBOOK_HEADERS} ${WORKSHEET_HEADERS} ${DETAIL_HEADERS} ${DETAIL_CRYPTO_HEADERS} ${DRAWING_HEADERS} ${MINIZ_HEADERS}) set(XLNT_SOURCES ${CELL_SOURCES} ${CHARTS_SOURCES} ${CHARTSHEET_SOURCES} ${DRAWING_SOURCES} ${FORMULA_SOURCES} ${PACKAGING_SOURCES} ${STYLES_SOURCES} ${UTILS_SOURCES} ${WORKBOOK_SOURCES} ${WORKSHEET_SOURCES} ${DETAIL_SOURCES} ${DETAIL_CRYPTO_SOURCES} ${DRAWING_SOURCES} ${MINIZ_SOURCES}) if(NOT STATIC) # Compile shared library add_library(xlnt SHARED ${XLNT_HEADERS} ${XLNT_SOURCES} $) target_compile_definitions(xlnt PRIVATE XLNT_SHARED=1) # Set SO version (for symbolic links like libxlnt.so.1.4 and libxlnt.so.1) set_target_properties(xlnt PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH} INSTALL_NAME_DIR "${XLNT_LIB_DEST_DIR}") else() # Compile static library add_library(xlnt STATIC ${XLNT_HEADERS} ${XLNT_SOURCES} $) target_compile_definitions(xlnt PUBLIC XLNT_STATIC=1) endif() ``` -------------------------------- ### CMake Directory Definitions for xlnt Source: https://github.com/tfussell/xlnt/blob/master/source/CMakeLists.txt This snippet sets up common directory variables used within the xlnt project, including the root directory, include directory, source directory, and a directory for third-party libraries. These variables help organize project files. ```cmake # Commonly used project directories set(XLNT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..) set(XLNT_INCLUDE_DIR ${XLNT_ROOT_DIR}/include) set(XLNT_SOURCE_DIR ${XLNT_ROOT_DIR}/source) set(THIRD_PARTY_DIR ${XLNT_ROOT_DIR}/third-party) ``` -------------------------------- ### Create New Workbook and Write Data in C++ Source: https://context7.com/tfussell/xlnt/llms.txt Demonstrates how to create a new Excel workbook, set various cell values (integers, strings, formulas, doubles, booleans), merge cells, freeze panes, and save the workbook using the xlnt C++ library. This is a fundamental operation for generating new spreadsheets programmatically. ```cpp #include int main() { // Create a new workbook with default sheet xlnt::workbook wb; xlnt::worksheet ws = wb.active_sheet(); // Set various cell values ws.cell("A1").value(5); ws.cell("B2").value("string data"); ws.cell("C3").formula("=RAND()"); ws.cell("D4").value(3.14159); ws.cell("E5").value(true); // Merge cells and freeze panes ws.merge_cells("C3:C4"); ws.freeze_panes("B2"); // Save the workbook wb.save("example.xlsx"); return 0; } // Compile: g++ -std=c++14 -Ixlnt/include -lxlnt example.cpp -o example ```