Giter VIP home page Giter VIP logo

Comments (2)

uniqss avatar uniqss commented on August 21, 2024

I think this may help you:
`#include <OpenXLSX.hpp>
#include

using namespace std;
using namespace OpenXLSX;

char transCellType(const OpenXLSX::XLValueType& vt)
{
// Empty, Boolean, Integer, Float, Error, String
static char type[] = { 'N', 'B', 'I', 'F', 'E', 'S' };
return type[(int)vt];
}

int main()
{
cout << "\n";
cout << "DEMO PROGRAM #1: Basic Usage\n";
cout << "
\n";

XLDocument doc;
doc.create("./Demo01.xlsx");
auto wks = doc.workbook().worksheet("Sheet1");

wks.cell(XLCellReference("A1")).value() = 3.14159;
wks.cell(XLCellReference("B1")).value() = 42;
wks.cell(XLCellReference("C1")).value() = "  Hello OpenXLSX!  ";
wks.cell(XLCellReference("D1")).value() = true;
wks.cell(XLCellReference("E1")).value() = wks.cell(XLCellReference("C1")).value();


wks.cell(XLCellReference("A2")).value() = 1234;
wks.cell(XLCellReference("B2")).value() = "asdf";
wks.cell(XLCellReference("A3")).value() = 3333;
wks.cell(XLCellReference("B3")).value() = "xxxx";
wks.cell(XLCellReference("C3")).value() = "wwwwww";

auto A1 = wks.cell(XLCellReference("A1")).value();
auto B1 = wks.cell(XLCellReference("B1")).value();
auto C1 = wks.cell(XLCellReference("C1")).value();
auto D1 = wks.cell(XLCellReference("D1")).value();
auto E1 = wks.cell(XLCellReference("E1")).value();

auto valueTypeAsString = [](OpenXLSX::XLValueType type) {
    switch (type) {
        case XLValueType::String:
            return "string";

        case XLValueType::Boolean:
            return "boolean";

        case XLValueType::Empty:
            return "empty";

        case XLValueType::Error:
            return "error";

        case XLValueType::Float:
            return "float";

        case XLValueType::Integer:
            return "integer";

        default:
            return "";
    }
};

cout << "Cell A1: (" << valueTypeAsString(A1.valueType()) << ") " << A1.get<double>() << endl;
cout << "Cell B1: (" << valueTypeAsString(B1.valueType()) << ") " << B1.get<int>() << endl;
cout << "Cell C1: (" << valueTypeAsString(C1.valueType()) << ") " << C1.get<std::string>() << endl;
cout << "Cell D1: (" << valueTypeAsString(D1.valueType()) << ") " << D1.get<bool>() << endl;
cout << "Cell E1: (" << valueTypeAsString(E1.valueType()) << ") " << E1.get<std::string_view>() << endl;

doc.save();

doc.open("./Demo01.xlsx");
wks = doc.workbook().worksheet("Sheet1");

cout << " wks.rowCount() :" << wks.rowCount() << endl;
cout << " wks.columnCount() :" << wks.columnCount() << endl;
cout << " wks.lastCell().row() :" << wks.lastCell().row() << endl;
cout << " wks.lastCell().column() :" << wks.lastCell().column() << endl;
cout << " wks.lastCell().address() :" << wks.lastCell().address() << endl;
cout << " wks.range().numRows() :" << wks.range().numRows() << endl;
cout << " wks.range().numColumns() :" << wks.range().numColumns() << endl;

for (auto rowidx = 1;rowidx < wks.rowCount() + 1;rowidx++)
{
    auto row = wks.row(rowidx);
    cout << "rowidx:" << rowidx << " cellCount:" << row.cellCount() << endl;
    for (auto colidx = 1;colidx <= row.cellCount();++colidx)
    {
        auto cell = wks.cell(rowidx, colidx);
        cout << rowidx << "|" << colidx << " cell.valueType():" << transCellType(cell.valueType()) << endl;
    }
}

return 0;

}`

from openxlsx.

troldal avatar troldal commented on August 21, 2024

This bug has now been fixed.

from openxlsx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.