1.创建一个Qt工程
2. 把xlsx库文件放到工程里面
3.属性配置
C/C++----常规------附件包含目录--:$(SolutionDir)QtXlsx\qtxlsxwriter\include
链接器-----常规---附加库目录---:$(SolutionDir)QtXlsx\qtxlsxwriter\lib
链接器-----输入---附加依赖项:Qt5Xlsx.lib
?4.添加头文件:
#include?"xlsxdocument.h",
#include?"xlsxformat.h"
例子:
QXlsx::Document outxlsx;
//表头
QXlsx::Format format1;
format1.setFontSize(15);
format1.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
format1.setVerticalAlignment(QXlsx::Format::AlignVCenter);
//format1.setBorderStyle(QXlsx::Format::BorderDashDot);
outxlsx.write("A1", QString::fromLocal8Bit("退役报废枪械销毁处理情况全过程登记表"), format1);
outxlsx.mergeCells("A1:X1", format1);
//第一行
QXlsx::Format format2;
format2.setHorizontalAlignment(QXlsx::Format::AlignHCenter);
format2.setVerticalAlignment(QXlsx::Format::AlignVCenter);
outxlsx.write("A2", QString::fromLocal8Bit("枪械名称"), format2);
outxlsx.write("J2", QString::fromLocal8Bit("单位"), format2);
outxlsx.write("L2", QString::fromLocal8Bit("数量"), format2);
outxlsx.write("N2", QString::fromLocal8Bit("来源"), format2);
outxlsx.write("T2", QString::fromLocal8Bit("文件号"), format2);
outxlsx.mergeCells("B2:I2");
outxlsx.mergeCells("O2:S2");
outxlsx.mergeCells("U2:X2");
第二行
outxlsx.write("A3", QString::fromLocal8Bit("序号"), format2);
outxlsx.write("B3", QString::fromLocal8Bit("枪械号码"), format2);
outxlsx.write("F3", QString::fromLocal8Bit("检查拆解记录"), format2);
outxlsx.write("J3", QString::fromLocal8Bit("毁形装箱记录"), format2);
outxlsx.write("N3", QString::fromLocal8Bit("装卸运输记录"), format2);
outxlsx.write("T3", QString::fromLocal8Bit("投炉熔炼记录"), format2);
outxlsx.write("X3", QString::fromLocal8Bit("备注"), format2);
outxlsx.mergeCells("C3:E3");
outxlsx.mergeCells("H3:I3");
outxlsx.mergeCells("L3:M3");
outxlsx.mergeCells("O3:S3");
outxlsx.mergeCells("U3:W3");
第三行
outxlsx.write("B4", QString::fromLocal8Bit("主枪号"), format2);
outxlsx.write("C4", QString::fromLocal8Bit("枪管号"), format2);
outxlsx.write("D4", QString::fromLocal8Bit("机枪号或套筒号"), format2);
outxlsx.write("E4", QString::fromLocal8Bit("机枪框号"), format2);
outxlsx.write("F4", QString::fromLocal8Bit("日期"), format2);
outxlsx.write("G4", QString::fromLocal8Bit("检查人"), format2);
outxlsx.write("H4", QString::fromLocal8Bit("拆解人"), format2);
outxlsx.write("I4", QString::fromLocal8Bit("监督人"), format2);
outxlsx.write("J4", QString::fromLocal8Bit("日期"), format2);
outxlsx.write("K4", QString::fromLocal8Bit("箱(捆)号"), format2);
outxlsx.write("L4", QString::fromLocal8Bit("毁形装箱人"), format2);
outxlsx.write("M4", QString::fromLocal8Bit("监督人"), format2);
outxlsx.write("N4", QString::fromLocal8Bit("日期"), format2);
outxlsx.write("O4", QString::fromLocal8Bit("运输车号"), format2);
outxlsx.write("P4", QString::fromLocal8Bit("押运人"), format2);
outxlsx.write("Q4", QString::fromLocal8Bit("装车人"), format2);
outxlsx.write("R4", QString::fromLocal8Bit("卸车人"), format2);
outxlsx.write("S4", QString::fromLocal8Bit("监督人"), format2);
outxlsx.write("T4", QString::fromLocal8Bit("日期"), format2);
outxlsx.write("U4", QString::fromLocal8Bit("点验人"), format2);
outxlsx.write("V4", QString::fromLocal8Bit("核查人"), format2);
outxlsx.write("W4", QString::fromLocal8Bit("监销人"), format2);
outxlsx.save();
5.运行。得到结果
参考:
(456条消息) Qt Xlsx使用教程、Qt操作Excel、Qt生成Excel图表、跨平台不依赖Office_超级大洋葱的博客-CSDN博客_qtxlsx
第三方精美控件的添加使用:(450条消息) Qt UI界面美化教程1:【“飞扬青云” Qt精美控件】使用教程1_超级大洋葱的博客-CSDN博客_飞扬青云
|