Qt实现Excle文件合并,并保留原文件单元格样式

简介

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操作功能较多,目前做的只能实现基础的功能,后续功能会一点点迭代更新。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值