简介
1.QtExcel操作接口,该文章excel接口可实现多个文件进行合并,但是并不保留原有的单元格格式,下面操作将保留原格式进行合并。
上代码
1.接口函数TableCellAttr readCellStyle(QAxObject* cell);
2.该接口实现读取单元格样式进行解析,转换结构体。
3.该结构体内容并不是非常丰富,可以进行扩展,只是实现了一些常用样式。
TableCellAttr ExcelThread::readCellStyle(QAxObject *cell)
{
if (cell->isNull()) return TableCellAttr();
TableCellAttr tableCellAttr;
QAxObject* temp = cell->querySubObject("Interior");
tableCellAttr.fillColor = temp->dynamicCall("ColorIndex").toInt();
temp = cell->querySubObject("Borders");;
tableCellAttr.border = temp->dynamicCall("Weight").toInt();
temp = cell->querySubObject("Font");;
tableCellAttr.fontColor = temp->dynamicCall("ColorIndex").toInt();
temp = cell->querySubObject("Font");;
tableCellAttr.fontSize = temp->dynamicCall("Size").toInt();
temp = cell->querySubObject("Font");;
tableCellAttr.fontStr = temp->dynamicCall("Name").toString();
temp = cell->querySubObject("Font");;
tableCellAttr.isItalic = temp->dynamicCall("Italic").toBool();
temp = cell->querySubObject("Font");;
tableCellAttr.isBoldface = temp->dynamicCall("Bold").toBool();
temp = cell->querySubObject("Font");;
tableCellAttr.isUnderline = temp->dynamicCall("UnderLine").toBool();
tableCellAttr.isWrapText = cell->dynamicCall("WrapText").toBool();
tableCellAttr.isAutoFitRow = cell->dynamicCall("AutoFit()").toBool();
QString cellFormat = cell->dynamicCall("NumberFormatLocal").toString();
if (cellFormat.contains("yyyy")) {
tableCellAttr.cellFormat = 2;
}
else if (cellFormat.contains("0.00_")) {
tableCellAttr.cellFormat = 3;
}
else if (cellFormat.contains("??#")) {
tableCellAttr.cellFormat = 4;
}
else if (cellFormat.contains("0.00%")) {
tableCellAttr.cellFormat = 5;
}
else {
tableCellAttr.cellFormat = 1;
}
return tableCellAttr;
}
结尾
1.excel操作功能较多,目前做的只能实现基础的功能,后续功能会一点点迭代更新。