码迷,mamicode.com
首页 > 其他好文 > 详细

qt 使用qtxlsx 读写excel

时间:2018-06-13 15:12:59      阅读:1403      评论:0      收藏:0      [点我收藏+]

标签:load   include   for   rect   cto   this   XA   下载   highlight   

https://github.com/dbzhang800/QtXlsxWriter 下载qtxlsx地址

QtXlsx is a library that can read and write Excel files. It doesn‘t require Microsoft Excel and can be used in any platform that Qt5 supported. The library can be used to

  • Generate a new .xlsx file from scratch
  • Extract data from an existing .xlsx file
  • Edit an existing .xlsx file

Getting Started

  • For linux user, if your Qt is installed through package manager tools such "apt-get", make sure that you have installed the Qt5 develop package qtbase5-private-dev

Usage(1): Use Xlsx as Qt5‘s addon module

Building the module

Note: Perl is needed in this step.

  • Download the source code.

  • Put the source code in any directory you like

  • Go to top directory of the project in a terminal and run

    qmake
    make
    make install

The library, the header files, and others will be installed to your system.

make html_docs can be used to generate documentations of the library, and make check can be used to run unit tests of the library.

Using the module

  • Add following line to your qmake‘s project file:
    QT += xlsx
  • Then, using Qt Xlsx in your code
    #include <QtXlsx>
    int main()
    {
        QXlsx::Document xlsx;
        xlsx.write("A1", "Hello Qt!");
        xlsx.saveAs("Test.xlsx");
        return 0;
    }

Usage(2): Use source code directly

The package contains a qtxlsx.pri file that allows you to integrate the component into applications that use qmake for the build step.

  • Download the source code.

  • Put the source code in any directory you like. For example, 3rdparty:

    |-- project.pro
    |-- ....
    |-- 3rdparty    |     |-- qtxlsx    |     |
  • Add following line to your qmake project file:
    include(3rdparty/qtxlsx/src/xlsx/qtxlsx.pri)

Note: If you like, you can copy all files from src/xlsx to your application‘s source path. Then add following line to your project file:

include(qtxlsx.pri)

> **Note**: If you do not use qmake, you need to define the following macro manually

> ```
    XLSX_NO_LIB
  • Then, using Qt Xlsx in your code
    #include "xlsxdocument.h"
    int main()
    {
        QXlsx::Document xlsx;
        xlsx.write("A1", "Hello Qt!");
        xlsx.saveAs("Test.xlsx");
        return 0;
    }

在构建的时候,可能会有如下的错误,

 

xlsxzipreader.cpp: In member function ‘void QXlsx::ZipReader::init()’:
xlsxzipreader.cpp:51:66: error: conversion from ‘QVector<QZipReader::FileInfo>’ to non-scalar type ‘QList<QZipReader::FileInfo>’ requested
     QList<QZipReader::FileInfo> allFiles = m_reader->fileInfoList();
 

 

这里只需要吧出错的文件添加 :
 #include <QVector>
然后把出错的地方的"QList" 用"QVector" 替换掉重新构建就可以了。

 

qt 使用qtxlsx 读写excel

标签:load   include   for   rect   cto   this   XA   下载   highlight   

原文地址:https://www.cnblogs.com/wangjian8888/p/9176662.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!