Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about "wks.ColumnCount()" and "wks.RowCount()" ? #38

Closed
error408 opened this issue Apr 15, 2020 · 2 comments
Closed

Question about "wks.ColumnCount()" and "wks.RowCount()" ? #38

error408 opened this issue Apr 15, 2020 · 2 comments

Comments

@error408
Copy link

"wks.ColumnCount()" and "wks.RowCount()" is accroding to "LastCell()"'s position, but why if I create a new sheet, the ColumnCount is 1 and RowCount is 0 ?
The same as other sheet, ColumnCount always bigger than real it is.

@uniqss
Copy link

uniqss commented Dec 24, 2020

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;

}`

@troldal
Copy link
Owner

troldal commented Oct 8, 2021

This bug has now been fixed.

@troldal troldal closed this as completed Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants