diff --git a/README.md b/README.md index 108d940d..323f1703 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ xlnt [![Build Status](https://travis-ci.org/tfussell/xlnt.svg)](https://travis-ci.org/tfussell/xlnt) ## 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 Including xlnt in your project @@ -43,37 +43,29 @@ for(auto row : wb2["sheet2"].rows()) ## Building 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: ```batch -cd build/genie -genie vs2015 -start vs2015/xlnt.sln +mkdir build +cd build +cmake -G "Visual Studio 14 2015" ../cmake +start xlnt.sln ``` In Linux or OSX, with GNU Make: ```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 cd build -cmake .. +cmake -G "Unix Makefiles" ../cmake make ``` diff --git a/samples/sample1.cpp b/samples/sample1.cpp index 1e8286aa..8cde6278 100644 --- a/samples/sample1.cpp +++ b/samples/sample1.cpp @@ -1,37 +1,36 @@ #include #include -/// -/// Read sample1.xlsx and print out a 2-dimensional -/// representation of each sheet. Cells are separated by commas. -/// Each new line is a new row. -/// +// Read sample1.xlsx and print out a 2-dimensional +// representation of each sheet. Cells are separated by commas. +// Each new line is a new row. int main() { // 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. // 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. - 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. // Cell vectors don't actually contain cells to reduce overhead. // 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. // This allows easy and fast iteration over a row (sometimes a column) in the worksheet. - for(auto row : sheet.rows()) - { - for(auto cell : row) - { + for(auto row : sheet.rows()) + { + for(auto cell : row) + { // 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; + } + } } diff --git a/samples/sample2.cpp b/samples/sample2.cpp index 18e37089..d1071fce 100644 --- a/samples/sample2.cpp +++ b/samples/sample2.cpp @@ -1,28 +1,28 @@ #include #include -/// -/// Make 3 sheets containing 10,000 cells with unique numeric values. -/// +// Make 3 sheets containing 10,000 cells with unique numeric values. int main() { // create the workbook - xlnt::workbook workbook; + xlnt::workbook workbook; // 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" // if we don't specify a title, these would be "Sheet#" where // # 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 column = 1; column < 101; column++) - { + for(int row = 1; row < 101; row++) + { + for(int column = 1; column < 101; column++) + { // Since we can't overload subscript to accept both number, // create a cell_reference which "points" to the current cell. xlnt::cell_reference ref(column, row); @@ -35,10 +35,10 @@ int main() // set_value has overloads for many types such as strings and ints cell.set_value(row * 100 + column); - } - } - } + } + } + } // This will be written to the current directory. - workbook.save("sample2.xlsx"); + workbook.save("sample2.xlsx"); }