上一遍讲述了基于Qt5.9.8下编译Xtxlsx,本遍讲述基于Qt5.9.8下使用Qtxlsx

1、打开Qt Creator 4.8.2(Enterprise),创建工程,选择版本

  

2、在pro文件中添加QT += xlsx

  

3、在main.cpp中添加头文件

  

4、main函数添加如下代码

  QFile::remove("D:/1.xlsx");

  QXlsx::Document doc("D:/1.xlsx");

  

  //报表标题(1-4行)

  doc.setRowHeight(1,4,30);

  Format title_format;

  title_format.setFontSize(11);

  title_format.setFontBold(true);

  title_format.setFontColor(QColor(Qt::red));

  title_format.setBorderStyle(Format::BorderThin);

  title_format.setHorizontalAlignment(Format::AlignLeft);

  title_format.setVerticalAlignment(Format::AlignVCenter);

  doc.mergeCells("A1:H1",title_format);

  doc.mergeCells("A2:H2",title_format);

  doc.mergeCells("A3:H3",title_format);

  doc.mergeCells("A4:H4",title_format);

  doc.write("A1","巡视单位:高岐变");

  doc.write("A2","巡视路线:安防巡视");

  doc.write("A3","巡视时间:2019-08-28 14:47:30");

  doc.write("A4","巡视人员:hs");

  //巡视属性(5行)

  doc.setColumnWidth(1,15);

  doc.setColumnWidth(2,15);

  doc.setColumnWidth(3,15);

  doc.setColumnWidth(4,15);

  doc.setColumnWidth(5,15);

  doc.setColumnWidth(6,50);

  doc.setColumnWidth(7,50);

  doc.setColumnWidth(8,15);

  doc.setRowHeight(5,20);

  Format attr_format;

  attr_format.setFontSize(11);

  attr_format.setFontBold(true);

  attr_format.setFontColor(QColor(Qt::black));

  attr_format.setBorderStyle(Format::BorderThin);

  attr_format.setHorizontalAlignment(Format::AlignHCenter);

  attr_format.setVerticalAlignment(Format::AlignVCenter);

  attr_format.setPatternBackgroundColor(QColor(Qt::gray));

  doc.write("A5","变电站名称",attr_format);

  doc.write("B5","巡视路线名",attr_format);

  doc.write("C5","巡视点名",attr_format);

  doc.write("D5","分析时间",attr_format);

  doc.write("E5","分析结果",attr_format);

  doc.write("F5","原始图片",attr_format);

  doc.write("G5","分析图片",attr_format);

  doc.write("H5","备注",attr_format);

  //内容(从第6行开始)

  for(int i=6;i<20;i++)

  {

    doc.setRowHeight(i,180);

    Format cell_format;

    cell_format.setFontSize(11);

    cell_format.setFontColor(QColor(Qt::black));

    cell_format.setBorderStyle(Format::BorderThin);

    cell_format.setHorizontalAlignment(Format::AlignHCenter);

    cell_format.setVerticalAlignment(Format::AlignVCenter);

    doc.write(i,1,"测试变电站",cell_format);

    doc.write(i,2,"测试路线",cell_format);

    doc.write(i,3,"测试点",cell_format);

    doc.write(i,4,"2019-11-11 00:00:00",cell_format);

    doc.write(i,5,"无",cell_format);

    QImage image1("D:/CPSB_test_2016.jpg");

    QImage image2("D:/ZJFX_test_2016.jpg");

    doc.insertImage(i-1,6-1,image1.scaled(360,240,Qt::IgnoreAspectRatio,Qt::SmoothTransformation));

    doc.insertImage(i-1,7-1,image2.scaled(360,240,Qt::IgnoreAspectRatio,Qt::SmoothTransformation));

    doc.write(i,8," ",cell_format);

  }

  doc.save();

5、最后生成的报表如下

6、更多的使用可以参照E:/QtXlsxWriter-master/examples

  

  里面包含了Qtxlsx各种各样的使用。

Qtxlsx的使用的更多相关文章

  1. qt 使用qtxlsx 读写excel

    https://github.com/dbzhang800/QtXlsxWriter 下载qtxlsx地址 QtXlsx is a library that can read and write Ex ...

  2. 使用QtXlsx来读写excel文件

    概述:QtXlsx是功能非常强大和使用非常方便的操作excel类库.包括对excel数据读写.excel数据格式设置及在excel里面根据数据生成各种图表. 下面重点介绍如何安装和使用QtXlsx. ...

  3. windows下Qt编译Qtxlsx库和qtxlsx库的使用方法

    最近接了个项目,合作的学长让用Qt写,而其中最重要的需求是将数据库的数据写入excel表格中和将excel的数据导入到数据库中,自己查阅了和多资料,最后决定使用qtxlsx开源库来操作excel,在编 ...

  4. 基于Qt 5.9.8,编译Qtxlsx

    1.源码下载地址:https://github.com/dbzhang800/QtXlsxWriter 2.下载并安装编译时需要的工具 Perl:https://www.perl.org/get.ht ...

  5. Qtxlsx

    https://blog.csdn.net/qq_40194498/article/details/80817264

  6. 【转贴】-- 基于QT的跨平台应用开发

    原帖地址:http://www.cnblogs.com/R0b1n/p/4106613.html 1 Qt简介 Qt是1991年奇趣科技开发的一个跨平台的C++图形用户界面应用程序框架.它提供给应用程 ...

  7. QtXlsxWriter

    Code Issues26 Pull requests2   Pulse Graphs HTTPS clone URL You can clone with HTTPS orSubversion. C ...

  8. vs2008中xlslib与libxls库的编译及使用

    C++用来操作Excel的方法很多,但是涉及到跨平台,同时又要对Excel的读写操作兼顾,而且免费的库,那应该是要用xlslib和libxls了.由于技术比较菜,折腾这个折腾了一个星期了.最开始是使用 ...

  9. 39.QT-Qtxlsx库使用

    之前参考博客https://blog.csdn.net/c3060911030/article/details/51560239下载Qtxlsx库,然后编译的时候,显示: error: invalid ...

随机推荐

  1. 深入delphi编程理解之消息(二)发送消息函数及消息编号、消息结构体的理解

    一.delphi发送消息的函数主要有以下三个: (一).SendMessage函数,其原型如下: function SendMessage( hWnd: HWND; {目标句柄} Msg: UINT; ...

  2. JS高级---原型的简单的语法

    原型的简单的语法 构造函数,通过原型添加方法,以下语法,手动修改构造器的指向 实例化对象,并初始化,调用方法 <!DOCTYPE html> <html lang="en& ...

  3. 《macOS 使用手册》之远程控制

    https://support.apple.com/zh-cn/guide/mac-help/mchlp1066/mac 选择版本: macOS Catalina 10.15 macOS Mojave ...

  4. wordpress 不用插件添加友情链接

    哎,也不知道为啥,网上说的那个link manager这个插件死活找不到啊, 找了一个类似的,但是不是,这么多的英文看了好几遍才发现不是 然后从大神哪里找到一个好方法 在你用的那个主题的functio ...

  5. Java JDK 1.5 1.6 1.7 新特性整理

    Java JDK 1.5的新特性 1.泛型 List<String> strs = new ArrayList<String>();//给集合指定存入类型,上面这个集合在存入数 ...

  6. Go_排序

    package main import ( "fmt" "sort" "math/rand" ) //1.声明Hero结构体 type He ...

  7. JS中的数组创建,初始化

    JS中没有专门的数组类型.但是可以在程序中利用预定义的Array对象及其方法来使用数组. 在JS中有三种创建数组的方法: var arr = new Array(1,2,3,4); var arr = ...

  8. try catch和if else

    当错误发生时,当事情出问题时,JavaScript 引擎通常会停止,并生成一个错误消息.描述这种情况的技术术语是:JavaScript 将抛出一个错误. try 语句允许我们定义在执行时进行错误测试的 ...

  9. buu Crypto 刷题记录

    1.MD5 直接解. 2.url编码 直接解. 3.一眼就解密 base64. 4.看我回旋踢 对文本内容全部CaesarDecode. 5.摩丝 直接MorseDecode. 6.Quoted-pr ...

  10. php中截取中文不乱吗

    php截取中文的使用是随处可见的,譬如,博客首页显示简介,可能会用到,或一些相册简介会用到,以前不知道,还傻傻的自己去写函数用来做“智能截取”,效果还不十分好,幸运的是,今天因为一位同学做项目,让我一 ...