mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
update readme and fix samples
This commit is contained in:
parent
e16d381b11
commit
6ab2c4e2ec
36
README.md
36
README.md
|
@ -4,7 +4,7 @@ xlnt
|
||||||
[![Build Status](https://travis-ci.org/tfussell/xlnt.svg)](https://travis-ci.org/tfussell/xlnt)
|
[![Build Status](https://travis-ci.org/tfussell/xlnt.svg)](https://travis-ci.org/tfussell/xlnt)
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
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.
|
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 roughly 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.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
Including xlnt in your project
|
Including xlnt in your project
|
||||||
|
@ -43,37 +43,29 @@ for(auto row : wb2["sheet2"].rows())
|
||||||
## Building
|
## Building
|
||||||
xlnt is regularly built and passes all 200+ tests in GCC 4.8.2, MSVC 14, and Clang (using Apple LLVM 7.0).
|
xlnt is regularly built and passes all 200+ tests in GCC 4.8.2, MSVC 14, and Clang (using Apple LLVM 7.0).
|
||||||
|
|
||||||
Workspaces for Visual Studio 2015, GNU Make, and Xcode can be created using GENie and the genie.lua script in the build/genie directory.
|
Build configurations for Visual Studio 2015, GNU Make, and Xcode can be created using cmake and the cmake scripts in the project directory, cmake.
|
||||||
|
|
||||||
GENie binaries and source are currently available [here](https://github.com/bkaradzic/genie).
|
In OSX, with Xcode:
|
||||||
|
```bash
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake -G Xcode ../cmake
|
||||||
|
open xlnt.xcproject
|
||||||
|
```
|
||||||
|
|
||||||
In Windows, with Visual Studio 2015:
|
In Windows, with Visual Studio 2015:
|
||||||
```batch
|
```batch
|
||||||
cd build/genie
|
mkdir build
|
||||||
genie vs2015
|
cd build
|
||||||
start vs2015/xlnt.sln
|
cmake -G "Visual Studio 14 2015" ../cmake
|
||||||
|
start xlnt.sln
|
||||||
```
|
```
|
||||||
|
|
||||||
In Linux or OSX, with GNU Make:
|
In Linux or OSX, with GNU Make:
|
||||||
```bash
|
```bash
|
||||||
cd build/genie
|
|
||||||
genie gmake
|
|
||||||
cd gmake && make
|
|
||||||
```
|
|
||||||
|
|
||||||
In OSX, with Xcode (Xcode 4 projects can be opened in Xcode 7.0)
|
|
||||||
```bash
|
|
||||||
cd build/genie
|
|
||||||
genie xcode4
|
|
||||||
open xcode4/xlnt.xcworkspace
|
|
||||||
```
|
|
||||||
|
|
||||||
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
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake ..
|
cmake -G "Unix Makefiles" ../cmake
|
||||||
make
|
make
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -1,37 +1,36 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <xlnt/xlnt.hpp>
|
#include <xlnt/xlnt.hpp>
|
||||||
|
|
||||||
/// <summary>
|
// Read sample1.xlsx and print out a 2-dimensional
|
||||||
/// Read sample1.xlsx and print out a 2-dimensional
|
// representation of each sheet. Cells are separated by commas.
|
||||||
/// representation of each sheet. Cells are separated by commas.
|
// Each new line is a new row.
|
||||||
/// Each new line is a new row.
|
|
||||||
/// </summary>
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// Create a new workbook by reading sample1.xlsx in the current directory.
|
// Create a new workbook by reading sample1.xlsx in the current directory.
|
||||||
auto wb = xlnt::excel_reader::load_workbook("sample1.xlsx");
|
xlnt::workbook wb;
|
||||||
|
wb.load("sample1.xlsx");
|
||||||
|
|
||||||
// The workbook class has begin and end methods so it can be iterated upon.
|
// The workbook class has begin and end methods so it can be iterated upon.
|
||||||
// Each item is a sheet in the workbook.
|
// Each item is a sheet in the workbook.
|
||||||
for(auto sheet : wb)
|
for(const auto sheet : wb)
|
||||||
{
|
{
|
||||||
// Print the title of the sheet on its own line.
|
// Print the title of the sheet on its own line.
|
||||||
std::cout << sheet.get_title() << ": " << std::endl;
|
std::cout << sheet.get_title() << ": " << std::endl;
|
||||||
|
|
||||||
// Iterating on a range, such as from worksheet::rows, yields cell_vectors.
|
// Iterating on a range, such as from worksheet::rows, yields cell_vectors.
|
||||||
// Cell vectors don't actually contain cells to reduce overhead.
|
// Cell vectors don't actually contain cells to reduce overhead.
|
||||||
// Instead they hold a reference to a worksheet and the current cell_reference.
|
// Instead they hold a reference to a worksheet and the current cell_reference.
|
||||||
// Internally, calling worksheet::get_cell with the current cell_reference yields the next cell.
|
// Internally, calling worksheet::get_cell with the current cell_reference yields the next cell.
|
||||||
// This allows easy and fast iteration over a row (sometimes a column) in the worksheet.
|
// This allows easy and fast iteration over a row (sometimes a column) in the worksheet.
|
||||||
for(auto row : sheet.rows())
|
for(auto row : sheet.rows())
|
||||||
{
|
{
|
||||||
for(auto cell : row)
|
for(auto cell : row)
|
||||||
{
|
{
|
||||||
// cell::operator<< adds a string represenation of the cell's value to the stream.
|
// cell::operator<< adds a string represenation of the cell's value to the stream.
|
||||||
std::cout << cell << ", ";
|
std::cout << cell << ", ";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <xlnt/xlnt.hpp>
|
#include <xlnt/xlnt.hpp>
|
||||||
|
|
||||||
/// <summary>
|
// Make 3 sheets containing 10,000 cells with unique numeric values.
|
||||||
/// Make 3 sheets containing 10,000 cells with unique numeric values.
|
|
||||||
/// </summary>
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create the workbook
|
// create the workbook
|
||||||
xlnt::workbook workbook;
|
xlnt::workbook workbook;
|
||||||
|
|
||||||
// workbooks have a single sheet called "Sheet" initially so let's get rid of it
|
// workbooks have a single sheet called "Sheet" initially so let's get rid of it
|
||||||
workbook.clear();
|
auto to_remove = workbook.get_sheet_by_name("Sheet");
|
||||||
|
workbook.remove_sheet(to_remove);
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++)
|
// this loop will create three sheets and populate them with data
|
||||||
{
|
for(int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
// the title will be "Sample2-1", "Sample2-2", or "Sample2-3"
|
// the title will be "Sample2-1", "Sample2-2", or "Sample2-3"
|
||||||
// if we don't specify a title, these would be "Sheet#" where
|
// if we don't specify a title, these would be "Sheet#" where
|
||||||
// # is the lowest number that doesn't have a corresponding sheet yet.
|
// # is the lowest number that doesn't have a corresponding sheet yet.
|
||||||
auto sheet = workbook.create_sheet("Sample2-" + std::to_string(i));
|
auto sheet = workbook.create_sheet("Sample2-" + std::to_string(i));
|
||||||
|
|
||||||
for(int row = 1; row < 101; row++)
|
for(int row = 1; row < 101; row++)
|
||||||
{
|
{
|
||||||
for(int column = 1; column < 101; column++)
|
for(int column = 1; column < 101; column++)
|
||||||
{
|
{
|
||||||
// Since we can't overload subscript to accept both number,
|
// Since we can't overload subscript to accept both number,
|
||||||
// create a cell_reference which "points" to the current cell.
|
// create a cell_reference which "points" to the current cell.
|
||||||
xlnt::cell_reference ref(column, row);
|
xlnt::cell_reference ref(column, row);
|
||||||
|
@ -35,10 +35,10 @@ int main()
|
||||||
|
|
||||||
// set_value has overloads for many types such as strings and ints
|
// set_value has overloads for many types such as strings and ints
|
||||||
cell.set_value(row * 100 + column);
|
cell.set_value(row * 100 + column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will be written to the current directory.
|
// This will be written to the current directory.
|
||||||
workbook.save("sample2.xlsx");
|
workbook.save("sample2.xlsx");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user