您的位置:首页 > 编程语言 > Qt开发

QXlsx读写excel

2016-06-08 14:21 351 查看
读:
QXlsx::Document xlsx(_filePath);
int intRowStart = xlsx.dimension().firstRow();
int intColStart = xlsx.dimension().firstColumn();
QStringList postHeaderList;
for (int row = intRowStart; row <= xlsx.dimension().rowCount(); row++) {
for (int column = intColStart; column < xlsx.dimension().columnCount(); column++) {
QXlsx::Cell *cell = xlsx.cellAt(xlsx.dimension().firstRow(), j); //获取单元格
if (cell == NULL) {
postHeaderList.append("");
} else {
postHeaderList.append(cell->value().toString());
}
}
}
写:
int cellRow = 1;
int cellColumn = 1;
QXlsx::Format format;
format.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
format.setVerticalAlignment(QXlsx::Format::AlignVCenter);
format.setPatternBackgroundColor("#cccccc");
QXlsx::CellReference cellReferenceTop(cellRow, cellColumn);
xlsx.write(cellReferenceTop, "hello", format);
合并:
xlsx.mergeCells(QXlsx::CellRange(romLeftTop,columnLeftTop, rowRightBottom, columnRightBottom));
设置列宽:
xlsx.setColumnWidth(cellColumn, colWidthCm);	//xls列宽单位为cm
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  xlsx Qt