Comments (2)
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.
This bug has now been fixed.
from openxlsx.
Related Issues (20)
- Random Rows Random Columns Write Crash XLCell object has not been properly initiated
- Is there any API to set a cell's color
- A debug build error at the last step on Windows using other default options
- Huge call time for XLWorksheet::cell ->XLRowDataProxy::XLRowDataProxy
- the number 3.0 can't be read to double; HOT 1
- How do I insert a picture as embedded in a cell ?
- Error opening file
- cmake error in linux HOT 1
- Build Doubt:: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
- A fork for C++ 11 HOT 1
- Any way to force re-calculation of formulas? HOT 2
- error: '::_wfopen' has not been declared
- Add CMake option to disable installing HOT 4
- How to set the cell format of a date cell from "General" to "Date"?
- Writing largeish sheets/xlsx-files(30-50MB) seems very slow/unable to complete writing files from std::strings HOT 1
- compile error, need to add #include <cstdint> in XLCellReference.hpp, XLColor.hpp, XLDateTime.cpp HOT 2
- So many bugs, is it REALLY useful? HOT 15
- Primary performance improvement wanted HOT 3
- configure_file Problem configuring file
- [OpenXLSX::XLInputError]Dont open file.xlsx. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openxlsx.