2016-08-02 08:22:06 +08:00
< img height = "100" src = "https://raw.githubusercontent.com/tfussell/xlnt/gh-pages/images/xlnt.png" alt = "xlnt" > < br / >
2014-05-07 05:28:38 +08:00
====
2015-11-22 03:21:52 +08:00
[![Travis Build Status ](https://travis-ci.org/tfussell/xlnt.svg )](https://travis-ci.org/tfussell/xlnt)
[![AppVeyor Build status ](https://ci.appveyor.com/api/projects/status/2hs79a1xoxy16sol?svg=true )](https://ci.appveyor.com/project/tfussell/xlnt)
2016-06-18 16:17:28 +08:00
[![Coverage Status ](https://coveralls.io/repos/github/tfussell/xlnt/badge.svg?branch=master )](https://coveralls.io/github/tfussell/xlnt?branch=master)
2015-11-22 03:21:52 +08:00
[![ReadTheDocs Documentation Status ](https://readthedocs.org/projects/xlnt/badge/?version=latest )](http://xlnt.readthedocs.org/en/latest/?badge=latest)
2015-11-22 03:15:45 +08:00
[![License ](http://img.shields.io/badge/license-MIT-blue.svg?style=flat )](http://opensource.org/licenses/MIT)
2015-10-27 03:46:16 +08:00
2014-05-20 08:52:04 +08:00
## Introduction
2016-09-08 06:40:19 +08:00
xlnt is a C++14 library for reading, writing, and modifying XLSX files as described in [ECMA 376 4th edition ](http://www.ecma-international.org/publications/standards/Ecma-376.htm ). The API is based on [openpyxl ](https://bitbucket.org/openpyxl/openpyxl ), a Python library to read/write Excel 2007 xlsx/xlsm files, and ultimately on [PHPExcel ](https://github.com/PHPOffice/PHPExcel ), pure PHP library for reading and writing spreadsheet files upon which openpyxl was based. This project is still very much a work in progress, but the core development work is complete.
2014-05-07 05:28:38 +08:00
2014-05-20 08:52:04 +08:00
## Usage
Including xlnt in your project
2014-05-20 05:37:00 +08:00
```c++
2015-10-19 03:51:25 +08:00
// with -std=c++14 -Ixlnt/include -Lxlnt/lib -lxlnt
2015-12-25 04:51:11 +08:00
// can also use the generated "xlnt.pc" in ./build directory with pkg-config to get these flags
2014-07-30 05:39:00 +08:00
#include <xlnt/xlnt.hpp>
2014-05-20 05:37:00 +08:00
```
2015-12-25 04:51:11 +08:00
Creating a new spreadsheet and saving it as book1.xlsx
2014-05-20 05:34:35 +08:00
```c++
xlnt::workbook wb;
xlnt::worksheet ws = wb.get_active_sheet();
2015-10-02 00:30:48 +08:00
ws.get_cell("A1").set_value(5);
ws.get_cell("B2").set_value("string data");
ws.get_cell("C3").set_formula("=RAND()");
2014-05-20 05:34:35 +08:00
ws.merge_cells("C3:C4");
ws.freeze_panes("B2");
wb.save("book1.xlsx");
2014-05-20 05:35:24 +08:00
```
2014-05-20 05:34:35 +08:00
2015-12-25 04:51:11 +08:00
Opening an existing spreadsheet, book2.xlsx, and printing all cells
2014-05-20 05:35:24 +08:00
```c++
2014-05-20 05:34:35 +08:00
xlnt::workbook wb2;
wb2.load("book2.xlsx");
2014-07-30 05:39:00 +08:00
2015-12-25 04:51:11 +08:00
// no need to use references, "cell", "range", and "worksheet" classes are only wrappers around pointers to memory in the workbook
2014-07-30 05:39:00 +08:00
for(auto row : wb2["sheet2"].rows())
2014-05-20 05:34:35 +08:00
{
for(auto cell : row)
{
2015-10-19 03:51:25 +08:00
std::cout < < cell < < std::endl ;
2014-05-20 05:34:35 +08:00
}
}
```
2014-05-20 08:52:04 +08:00
## Building
2016-07-06 19:13:42 +08:00
xlnt uses continous integration and passes all 300+ tests in GCC 4.9, VS2015, and Clang (using Apple LLVM 7.0).
2014-07-30 05:39:00 +08:00
2016-07-06 19:13:42 +08:00
Build configurations for Visual Studio 2015, GNU Make, and Xcode can be created using [cmake ](https://cmake.org/ ) and the cmake scripts in the project's cmake directory. A full list of cmake generators can be found [here ](https://cmake.org/cmake/help/v3.0/manual/cmake-generators.7.html ). A basic build would look like (starting in the root xlnt directory):
2015-10-13 05:41:20 +08:00
2015-11-02 13:29:39 +08:00
```bash
2016-07-06 19:13:42 +08:00
mkdir build
2015-11-02 13:29:39 +08:00
cd build
2016-07-06 19:13:42 +08:00
cmake ..
make -j8
2015-10-19 03:51:25 +08:00
```
2016-07-06 19:13:42 +08:00
The resulting library, libxlnt.dylib or libxlnt.so or xlnt.dll, would be found in the build/lib directory. Other cmake configuration options can be found using "cmake -LH". These options include shared vs static library and whether to build tests or not. An example of building a static library with tests as an Xcode project:
2015-12-25 04:51:11 +08:00
```bash
2016-07-06 19:13:42 +08:00
mkdir build
2015-12-25 04:51:11 +08:00
cd build
2016-07-06 19:13:42 +08:00
cmake -D TESTS=1 -D SHARED=0 -D STATIC=1 -G Xcode ..
cmake --build .
bin/xlnt.test
2015-12-25 04:51:11 +08:00
```
2014-05-20 08:52:04 +08:00
## Dependencies
2015-12-25 04:51:11 +08:00
xlnt uses the following libraries, which are included in the source tree (all but miniz as [git submodules ](https://git-scm.com/book/en/v2/Git-Tools-Submodules#Cloning-a-Project-with-Submodules )) for convenience:
2014-07-30 05:39:00 +08:00
- [miniz v1.15_r4 ](https://code.google.com/p/miniz/ ) (public domain/unlicense)
2015-10-19 03:51:25 +08:00
- [pugixml v1.6 ](http://pugixml.org/ ) (MIT license)
2015-12-25 04:51:11 +08:00
- [Optional ](https://github.com/akrzemi1/Optional ) (Boost Software License, Version 1.0)
- [utfcpp v2.3.4 ](http://utfcpp.sourceforge.net/ ) (Boost Software License, Version 1.0)
2015-09-28 23:19:55 +08:00
- [cxxtest v4.4 ](http://cxxtest.com/ ) (LGPLv3 license [only used for testing, separate from main library assembly])
2014-05-07 05:28:38 +08:00
2016-07-06 19:13:42 +08:00
Initialize the submodules with this command:
```bash
git submodule update --init
```
2015-11-04 07:58:36 +08:00
## Documentation
2015-12-25 04:51:11 +08:00
More extensive documentation with examples can be found on [Read The Docs ](http://xlnt.readthedocs.org/en/latest/ ).
2015-11-04 07:58:36 +08:00
2014-05-20 08:52:04 +08:00
## License
xlnt is currently released to the public for free under the terms of the MIT License:
2014-05-20 05:34:35 +08:00
2016-07-06 19:13:42 +08:00
Copyright (c) 2015-2016 Thomas Fussell
2014-05-20 05:34:35 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2016-07-14 11:13:54 +08:00