githubEdit

Read Me

CircleCI Build statusarrow-up-right Coverage Statusarrow-up-right Documentationarrow-up-right API referencearrow-up-right Licensearrow-up-right

Introduction

xlnt is a modern C++ library (requiring c++11 or above) for manipulating spreadsheets in memory and reading/writing them from/to XLSX (Microsoft Excel®) files as described in ECMA-376 5th editionarrow-up-right. The first public release of xlnt version 1.0 was on May 10th, 2017. Current work is focused on increasing compatibility, improving performance, and brainstorming future development goals. For a high-level summary of what you can do with this library, see the feature listarrow-up-right. Contributions are welcome in the form of pull requests or discussions on the repository's Issues pagearrow-up-right.

About this fork

This repo is a community effort to continue the development of xlnt, after the original repo of tfusselarrow-up-right has been unmaintained for many years (see Issue #748arrow-up-right). The xlnt community editionarrow-up-right is hosted at GitHub. Feel free to participate in this community effort by submitting issuesarrow-up-right and PRsarrow-up-right to this new community-driven repo. Issues and PRs on the original repo will not be transferred in bulk to this repo, but you may consider creating a similar issue or PR against this repo for items of interest to you.

String encoding

XLNT generally expects strings to be encoded as UTF-8. This is required when saving files created by XLNT, which will fail when using special characters not encoded as UTF-8. This is an issue on compilers and IDEs that do not use UTF-8 by default, like Microsoft Visual Studio. There are a few things to keep in mind:

  • For string literals (like "test") written in the source code, you will need to make sure, at a minimum, that the execution character set for strings passed to XLNT is UTF-8:

    • Using u8 string literals like u8"test" will ensure that these strings are encoded as UTF-8 during compilation. However, since C++20, u8 string literals need to be used with std::u8string or std::u8string_view, which XLNT currently supports only for paths.

    • Alternatively, the execution character set can be changed in the compiler settings to force all string literals like "test" to be encoded as UTF-8 during compilation. For Visual Studio, compile using /execution-charset:utf-8arrow-up-right.

    • Optionally, the best solution would be to use UTF-8 for both the source and execution character set. To do this:

      1. Convert existing source code files to UTF-8, if they already contain special characters (outside of US-ASCII).

      2. Configure the IDE / editor to save future files as UTF-8. For Visual Studio, use this solutionarrow-up-right to set this project-wide.

      3. Configure the compiler to use UTF-8. For Visual Studio, compile using /utf-8arrow-up-right.

  • For locale-aware formatting functions that can produce special characters, like string processing/formatting of the C and C++ Standard Libraries or of the Windows API, the above steps will not be enough if you want to pass such strings to XLNT. You will also need to ensure that the character encoding (active code page) is UTF-8 on all computers that run your application. Note that all major operating systems use UTF-8 by default nowadays, with a notable exception being Windows.

    • Windows only supports UTF-8 as the active code page since Windows 10 1903 (May 2019 Update) and Windows Server 2022, and is not enabled by default. The easiest is to enforce UTF-8 code page using a manifestarrow-up-right for your application.

    • For all other cases and operating systems, setting std::locale::global and/or setlocale to a UTF-8 encoding should work if the operating system supports UTF-8 character encodings.

  • An alternative to all of the steps above is to use a Unicode library and convert all strings to UTF-8 before passing them to XLNT. However, this is slower and needs more code (but works for all operating systems), so try to avoid this when possible.

  • For strings coming from external sources (e.g. files, databases, APIs), you will need to ensure that they always return UTF-8 encoded strings, or convert them to UTF-8 using a Unicode library before passing such strings to XLNT.

For more details, please see issue #134arrow-up-right.

Example

Including xlnt in your project, creating a new spreadsheet, and saving it as "example.xlsx"

More examplesarrow-up-right are available.

Documentation

More information is available in the xlnt documentationarrow-up-right and in the xlnt API referencearrow-up-right.

Building xlnt - From source

You can download the xlnt source codearrow-up-right and install the latest xlnt version as follows:

For more information, see the full installation instructionsarrow-up-right.

Building xlnt - Using vcpkg

You can download and install xlnt using the vcpkgarrow-up-right dependency manager:

The xlnt port in vcpkgarrow-up-right is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull requestarrow-up-right on the vcpkg repository.

License

xlnt is released to the public for free under the terms of the MIT License. See LICENSE.md for the full text of the license and the licenses of xlnt's third-party dependencies. LICENSE.md should be distributed alongside any assemblies that use xlnt in source or compiled form.

Last updated