xlnt/README.md

106 lines
3.6 KiB
Markdown
Raw Normal View History

2014-05-07 05:28:38 +08:00
xlnt
====
2014-05-20 08:52:04 +08:00
## Introduction
2015-10-24 02:44:27 +08:00
xlnt is a C++14 library for reading, writing, and modifying xlsx files as described in [ECMA 376](http://www.ecma-international.org/publications/standards/Ecma-376.htm). The API is generally based on [openpyxl](https://bitbucket.org/openpyxl/openpyxl), a python library for reading and writing xlsx/xlsm files. This 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
#include <xlnt/xlnt.hpp>
2014-05-20 05:37:00 +08:00
```
2014-05-20 08:52:04 +08:00
Creating a new spreadsheet and saving it
```c++
xlnt::workbook wb;
xlnt::worksheet ws = wb.get_active_sheet();
ws.get_cell("A1").set_value(5);
ws.get_cell("B2").set_value("string data");
ws.get_cell("C3").set_formula("=RAND()");
ws.merge_cells("C3:C4");
ws.freeze_panes("B2");
wb.save("book1.xlsx");
2014-05-20 05:35:24 +08:00
```
2014-05-20 08:52:04 +08:00
Opening an existing spreadsheet and printing all rows
2014-05-20 05:35:24 +08:00
```c++
xlnt::workbook wb2;
wb2.load("book2.xlsx");
// no need to use references, iterators are only wrappers around pointers to memory in the workbook
for(auto row : wb2["sheet2"].rows())
{
for(auto cell : row)
{
2015-10-19 03:51:25 +08:00
std::cout << cell << std::endl;
}
}
```
2014-05-20 08:52:04 +08:00
## Building
2015-10-19 03:51:25 +08:00
xlnt is regularly built and passes all 200+ tests in GCC 4.8.2, MSVC 14, and Clang (using Apple LLVM 7.0).
2015-10-19 03:51:25 +08:00
Workspaces for Visual Studio 2015, GNU Make, and Xcode can be created using GENie and the genie.lua script in the build/genie directory.
2015-10-13 05:41:20 +08:00
2015-10-19 03:51:25 +08:00
GENie binaries and source are currently available [here](https://github.com/bkaradzic/genie).
2015-10-19 03:51:25 +08:00
In Windows, with Visual Studio 2015:
```batch
2015-10-19 03:51:25 +08:00
cd build/genie
genie vs2015
start vs2015/xlnt.sln
```
2014-05-07 05:28:38 +08:00
2015-10-19 03:51:25 +08:00
In Linux or OSX, with GNU Make:
```bash
2015-10-19 03:51:25 +08:00
cd build/genie
genie gmake
cd gmake && make
```
2015-10-19 03:51:25 +08:00
In OSX, with Xcode (Xcode 4 projects can be opened in Xcode 7.0)
```bash
2015-10-19 03:51:25 +08:00
cd build/genie
genie xcode4
open xcode4/xlnt.xcworkspace
```
2014-05-07 05:28:38 +08:00
2015-10-19 03:51:25 +08:00
For users who prefer CMake, cmake scripts are provided in build/cmake. To use this system, a build might look like:
```bash
cd build/cmake
mkdir build
cd build
cmake ..
make
```
2014-05-20 08:52:04 +08:00
## Dependencies
2015-09-28 23:19:55 +08:00
xlnt uses the following libraries, which are included in the source tree (pugixml and cxxtest as [git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules#Cloning-a-Project-with-Submodules)) for convenience:
- [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-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
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:
Copyright (c) 2014 Thomas Fussell
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.