QT操作Excel封装类(包含高级功能:合并单元格,文本及单元格格式设定等)

Pro 文件

 

CONFIG += qaxcontainer  
  
QT       += core  
  
QT       -= gui  
  
TARGET = QExcel  
CONFIG   += console  
CONFIG   -= app_bundle  
  
TEMPLATE = app  
  
  
SOURCES += main.cpp \  
    qexcel.cpp  
  
HEADERS += \  
    qexcel.h  

 

 

头文件:qexcel.h

#ifndef QEXCEL_H  
#define QEXCEL_H  
  
#include <QString>  
#include <QVariant>  
  
class QAxObject;  
  
class QExcel : public QObject  
{  
public:  
    QExcel(QString xlsFilePath, QObject *parent = 0);  
    ~QExcel();  
  
public:  
    QAxObject * getWorkBooks();  
    QAxObject * getWorkBook();  
    QAxObject * getWorkSheets();  
    QAxObject * getWorkSheet();  
  
public:  
    /**************************************************************************/  
    /* 工作表                                                                 */  
    /**************************************************************************/  
    void selectSheet(const QString& sheetName);  
    //sheetIndex 起始于 1  
    void selectSheet(int sheetIndex);  
    void deleteSheet(const QString& sheetName);  
    void deleteSheet(int sheetIndex);  
    void insertSheet(QString sheetName);  
    int getSheetsCount();  
    //在 selectSheet() 之后才可调用  
    QString getSheetName();  
    QString getSheetName(int sheetIndex);  
  
    /**************************************************************************/  
    /* 单元格                                                                 */  
    /**************************************************************************/  
    void setCellString(int row, int column, const QString& value);  
    //cell 例如 "A7"  
    void setCellString(const QString& cell, const QString& value);  
    //range 例如 "A5:C7"  
    void mergeCells(const QString& range);  
    void mergeCells(int topLeftRow, int topLeftColumn, int bottomRightRow, int bottomRightColumn);  
    QVariant getCellValue(int row, int column);  
    void clearCell(int row, int column);  
    void clearCell(const QString& cell);  
  
    /**************************************************************************/  
    /* 布局格式                                                               */  
    /**************************************************************************/  
    void getUsedRange(int *topLeftRow, int *topLeftColumn, int *bottomRightRow, int *bottomRightColumn);  
    void setColumnWidth(int column, int width);  
    void setRowHeight(int row, int height);  
    void setCellTextCenter(int row, int column);  
    void setCellTextCenter(const QString& cell);  
    void setCellTextWrap(int row, int column, bool isWrap);  
    void setCellTextWrap(const QString& cell, bool isWrap);  
    void setAutoFitRow(int row);  
    void mergeSerialSameCellsInAColumn(int column, int topRow);  
    int getUsedRowsCount();  
    void setCellFontBold(int row, int column, bool isBold);  
    void setCellFontBold(const QString& cell, bool isBold);  
    void setCellFontSize(int row, int column, int size);  
    void setCellFontSize(const QString& cell, int size);  
  
    /*************
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值