自己编写的一个Qt C++类,用于操作excel表格,在Qt中操作excel需在.pro中增加CONFIG+=qaxcontainer配置。
1、打开Excel:objExcel = new QAxObject("Excel.Application"); <?xml:namespace prefix = o />

2、创建工作表:workSheet->dynamicCall("Add");

3、打开工作表:workExcel->dynamicCall("Open (const QString&)", file);

4、建立表头:pExcelCell->setProperty("Value", QVariant(strTemp));<?xml:namespace prefix = o />

5、写入数据:pExcelCell->setProperty("Value", QVariant(sLTestMsg.at(i-1)));

6、保存:workExcel->dynamicCall("SaveAs (const QString&)", saveFile);

7、退出:objExcel->dynamicCall("Quit (void)")。

/* Copyrignt (C). 2013-2016. TECHNOLOGIES LTD. */

/**

*Copyrignt (C). 2013-2016. TECHNOLOGIES LTD.

*@file qexcel.h

*@brief Operate Excel

*@author lichenglong

*@version 1.0

*@date 2013/8/10

*@History:

<author>      <time>       <version>   <desc>

lichenglong   2013/8/10    1.0             Operate Excel

*/

#ifndef QEXCEL_H

#define QEXCEL_H

#include <QAxObject>

#include <QAxWidget>

#include <QString>

#include <QDebug>

#include <QObject>

#include <QList>

#include <QDir>

#include <QMessageBox>

#include <assert.h>

#include "qt_windows.h"

#include "apps/ATSCommm.h"

/**

* @brief Operate Excel in Qt

*/

class QExcel : public QObject

{

Q_OBJECT

public:

/**

* @brief Construction Function of QExcel

* @param No

* @return void

*/

explicit QExcel(QObject *parent = 0);

~QExcel();

/**

* @brief Create Excel File

* @param no

* @return 0:success   -1:failed

*/

bool CreateExcel(QString file);

/**

* @brief Open Excel File

* @param file [QString]  the name of the opened file

* @param uColumn [unsigned int]

* @return 0:success   -1:failed

*/

bool OpenExcel(QString file, unsigned int uColumn);

/**

* @brief set Work Talbe Header

* @param no

* @return void

*/

void  setRatioAllSigExcelHeader();

/**

* @brief set Work Talbe Header: Resolution Ratio

* @param no

* @return void

*/

void  SetResRatioExcelHeader();

/**

* @brief set Work Talbe Header:  Signal 1 resolution ratios

* @param no

* @return void

*/

void  SetRatio1SigExcelHeader();

/**

* @brief set Work Talbe Header: Signal & 2 resolution ratios

* @param no

* @return void

*/

void  SetRatio2SigExcelHeader();

/**

* @brief Write a Test Message

* @param sLTestMsg [QList<QString>]  the Qstring List of test message

* @param

* @return void

*/

void WriteExcelMsg(QList<QString> sLTestMsg);

/**

* @brief Save Excel File

* @param saveFile [QString]

* @return 0:success   -1:failed

*/

bool SaveExcel(QString saveFile);

private:

QAxObject *objExcel;                  /**< excel application.*/

QAxObject * workExcel;              /**< excel  Handle of the opened file.*/

QString fileName;                       /**< save path and name of the Work Table .*/

unsigned int uiMaxColumn;        /**< colunm of the Work Table.*/

unsigned int uiMaxRow;              /**< row of the Work Table.*/

//QList<QString> sLTestMsg;         /**< row of the Work Table.*/

};

#endif // QEXCEL_H

/* Copyrignt (C). 2013-2016. LTD. */

/**

*Copyrignt (C). 2013-2016. LTD.

*@file qexcel.cpp

*@brief Operate Excel

*@author lichenglong

*@version 1.0

*@date 2013/8/10

*@History:

<author>      <time>       <version>   <desc>

lichenglong   2013/8/10    1.0             Operate Excel

*/

#include "qexcel.h"

#include <QMessageBox>

/**

* @brief Construction Function of QExcel

* @param No

* @return void

*/

QExcel::QExcel(QObject *parent) :

QObject(parent)

{

/**< initlialize parameter.*/

uiMaxColumn = MAXCOLUMN;

uiMaxRow = 0;

/**< use Excel ActiveX.*/

objExcel = new QAxObject("Excel.Application");

qDebug()<<objExcel;

//QMessageBox::information(this,"success","save figure parameter.    ");

/**< show current window.*/

objExcel->setProperty("Visible", false);

if(0)    //测试代码

{

/**< Create/Open Excel.*/

QString tabelSavePath;

// tabelSavePath.append("D:\QtProject\ATS - 20130730\result\lcl_20120808200000_8.xls");

tabelSavePath.append("D:\\1.xls" );

if(this->CreateExcel(tabelSavePath))

{

this->OpenExcel(tabelSavePath,RES3SIGCOLUMN);

this->setRatioAllSigExcelHeader();

}

else

{

//uiMaxColumn = RES3SIGCOLUMN;

this->OpenExcel(tabelSavePath,RES3SIGCOLUMN);

}

QList<QString> sLTestMsg;

sLTestMsg<<tr("1")<<tr("2013/8/7 20:30:20")<<tr("COM1")<<tr("192.168.1.1")<<tr("VCL-H3L")<<tr("Vtron123456");

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

{

sLTestMsg<<tr("正确");

}

this->WriteExcelMsg(sLTestMsg);

/**< save excel.*/

this->SaveExcel(tabelSavePath);

/**< Create/Open Excel.*/

tabelSavePath.clear();

// tabelSavePath.append("D:\QtProject\ATS - 20130730\result\lcl_20120808200000_8.xls");

tabelSavePath.append("D:\\2.xls" );

if(this->CreateExcel(tabelSavePath))

{

this->OpenExcel(tabelSavePath,RES1SIGCOLUMN);

this->SetRatio1SigExcelHeader();

}

else

{

//uiMaxColumn = RES1SIGCOLUMN;

this->OpenExcel(tabelSavePath,RES1SIGCOLUMN);

}

sLTestMsg.clear();

sLTestMsg<<tr("1")<<tr("2013/8/7 20:30:20")<<tr("COM1")<<tr("192.168.1.1")<<tr("VCL-H3L")<<tr("Vtron123456");

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

{

sLTestMsg<<tr("_正确");

}

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

{

sLTestMsg[i].replace("_","LCL_");

/*

QString temp(sLTestMsg.at(6));

qDebug()<< temp.replace("_","lcl");

//sLTestMsg.at(6).clear();

sLTestMsg.removeAt(6);

sLTestMsg.insert(6,temp);

//sLTestMsg.at(6) = temp;*/

}

this->WriteExcelMsg(sLTestMsg);

/**< save excel.*/

this->SaveExcel(tabelSavePath);

qDebug()<<"lcl::::";

/**< Create/Open Excel.*/

tabelSavePath.clear();

// tabelSavePath.append("D:\QtProject\ATS - 20130730\result\lcl_20120808200000_8.xls");

tabelSavePath.append("D:\\3.xls" );

if(this->CreateExcel(tabelSavePath))

{

this->OpenExcel(tabelSavePath,RES1SIGCOLUMN);

this->SetRatio2SigExcelHeader();

}

else

{

//uiMaxColumn = RES2SIGCOLUMN;

this->OpenExcel(tabelSavePath,RES2SIGCOLUMN);

}

sLTestMsg.clear();

sLTestMsg<<tr("1")<<tr("2013/8/7 20:30:20")<<tr("COM1")<<tr("192.168.1.1")<<tr("VCL-H3L")<<tr("Vtron123456");

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

{

sLTestMsg<<tr("正确");

}

this->WriteExcelMsg(sLTestMsg);

/**< save excel.*/

this->SaveExcel(tabelSavePath);

}

}

QExcel::~QExcel()

{

/**< exit Excel.*/

objExcel->dynamicCall("Quit (void)");

qDebug()<<"Qexcel exit... ";

//OleUninitialize();

}

/**

* @brief Create Excel File

* @param file [QString]  the name of the opened file

* @return 0:success   -1:failed

*/

bool QExcel::CreateExcel(QString file)

{

QDir  dTemp;

if(dTemp.exists(file))

{

qDebug()<<" QExcel::CreateExcel: exist file"<<file;

return false;

}

qDebug()<<" QExcel::CreateExcel: succes";

/**< create new excel sheet file.*/

QAxObject * workSheet = objExcel->querySubObject("WorkBooks");

workSheet->dynamicCall("Add");

/**< save Excel.*/

QAxObject * workExcel= objExcel->querySubObject("ActiveWorkBook");

objExcel->setProperty("DisplayAlerts", 0);

workExcel->dynamicCall("SaveAs (const QString&,int,const QString&,const QString&,bool,bool)",file,56,QString(""),QString(""),false,false);

objExcel->setProperty("DisplayAlerts", 1);

workExcel->dynamicCall("Close (Boolean)", false);

/**< exit Excel.*/

//objExcel->dynamicCall("Quit (void)");

return true;

}

/**

* @brief Open Excel File

* @param file [QString]  the name of the opened file

* @param uColumn [unsigned int]

* @return 0:success   -1:failed

*/

bool QExcel::OpenExcel(QString file, unsigned int uColumn)

{

if(file.isEmpty())

return false;

workExcel = objExcel->querySubObject("WorkBooks");

assert(workExcel);

/**< open  EXCEL, open file.xls.*/

workExcel->dynamicCall("Open (const QString&)", file);

assert(workExcel);

uiMaxColumn = uColumn;

return true;

}

/**

* @brief set Work Talbe Header: Signal 1 resolution ratios

* @param no

* @return void

*/

void  QExcel::SetRatio1SigExcelHeader()

{

/**< get active work books.*/     //获取活动工作簿:

QAxObject * activeSheets = objExcel->querySubObject("ActiveWorkBook");

/**< get table i.*/                         //获取第一个工作表sheet1:

QAxObject * worksheet = activeSheets->querySubObject("Worksheets(int)", 1);

//qDebug() << worksheet->property("Name").toString();     //获取工作表名:

/**< get/set  cell value.*/              // 获取cell的值

QAxObject * pExcelCell;

/**< initlialize parameter.*/

uiMaxColumn = RES1SIGCOLUMN;

/**< set Work Table header.*/

QString strTemp;

strTemp = tr("编号");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 1 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("时间");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 2 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("串口");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 3 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("IP");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 4 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("硬件型号");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 5 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("序列号");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 6 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("OSD");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 7 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("DRGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 8 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("ARGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 9 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("校准园");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 10 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("黑白点");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 11 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("工厂图");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 12 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("CVBS");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 13 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("YC");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 14 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("HDTV");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 15 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("HDMI");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 16 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("DRGB-S");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 17 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("ARGB-S");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 18 );

pExcelCell->setProperty("Value", QVariant(strTemp));

//qDebug() <<"Excel::setRatioAllSigExcelHeader(): "<< strTemp<<pExcelCell->property("Value").toString();

}

/**

* @brief set Work Talbe Header: Signal & 2 resolution ratios

* @param no

* @return void

*/

void  QExcel::SetRatio2SigExcelHeader()

{

/**< get active work books.*/     //获取活动工作簿:

QAxObject * activeSheets = objExcel->querySubObject("ActiveWorkBook");

/**< get table i.*/                         //获取第一个工作表sheet1:

QAxObject * worksheet = activeSheets->querySubObject("Worksheets(int)", 1);

//qDebug() << worksheet->property("Name").toString();     //获取工作表名:

/**< get/set  cell value.*/              // 获取cell的值

QAxObject * pExcelCell;

/**< initlialize parameter.*/

uiMaxColumn = RES2SIGCOLUMN;

/**< set Work Table header.*/

QString strTemp;

strTemp = tr("编号");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 1 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("时间");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 2 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("串口");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 3 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("IP");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 4 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("硬件型号");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 5 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("序列号");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 6 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("OSD");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 7 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("DRGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 8 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("ARGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 9 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("校准园");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 10 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("黑白点");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 11 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("CVBS");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 12 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("YC");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 13 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("HDTV");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 14 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("HDMI");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 15 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("DRGB-S");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 16 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("ARGB-S");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 17 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("工厂图");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 18 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("OSD");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 19 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("DRGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 20 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("ARGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 21 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("校准园");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 22 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("黑白点");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 23 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("工厂图");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 24 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("CVBS");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 25 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("YC");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 26 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("HDTV");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 27 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("HDMI");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 28 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("DRGB-S");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 29 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("ARGB-S");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 30 );

pExcelCell->setProperty("Value", QVariant(strTemp));

//qDebug() <<"Excel::setRatioAllSigExcelHeader(): "<< strTemp<<pExcelCell->property("Value").toString();

}

/**

* @brief set Work Talbe Header

* @param no

* @return void

*/

void  QExcel::setRatioAllSigExcelHeader()

{

/**< get active work books.*/     //获取活动工作簿:

QAxObject * activeSheets = objExcel->querySubObject("ActiveWorkBook");

/**< get table i.*/                         //获取第一个工作表sheet1:

QAxObject * worksheet = activeSheets->querySubObject("Worksheets(int)", 1);

//qDebug() << worksheet->property("Name").toString();     //获取工作表名:

/**< get/set  cell value.*/              // 获取cell的值

QAxObject * pExcelCell;

/**< initlialize parameter.*/

uiMaxColumn = RES3SIGCOLUMN;

/**< set Work Table header.*/

QString strTemp;

strTemp = tr("编号");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 1 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("时间");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 2 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("串口");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 3 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("IP");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 4 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("硬件型号");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 5 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("序列号");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 6 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("OSD");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 7 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("DRGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 8 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("ARGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 9 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("校准园");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 10 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("黑白点");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 11 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("CVBS");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 12 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("YC");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 13 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("HDTV");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 14 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("HDMI");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 15 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("DRGB-S");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 16 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("ARGB-S");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 17 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("工厂图");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 18 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("OSD");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 19 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("DRGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 20 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("ARGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 21 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("校准园");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 22 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("黑白点");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 23 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("工厂图");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 24 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("CVBS");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 25 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("YC");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 26 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("HDTV");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 27 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("HDMI");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 28 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("DRGB-S");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 29 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("ARGB-S");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 30 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("OSD");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 31 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("DRGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 32 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("ARGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 33 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("校准园");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 34 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("黑白点");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 35 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("工厂图");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 36 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("CVBS");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 37 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("YC");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 38 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("HDTV");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 39 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("HDMI");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 40 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("DRGB-S");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 41 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("ARGB-S");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 42 );

pExcelCell->setProperty("Value", QVariant(strTemp));

//qDebug() <<"Excel::setRatioAllSigExcelHeader(): "<< strTemp<<pExcelCell->property("Value").toString();

}

/**

* @brief set Work Talbe Header: Resolution Ratio

* @param no

* @return void

*/

void  QExcel::SetResRatioExcelHeader()

{

/**< get active work books.*/     //获取活动工作簿:

QAxObject * activeSheets = objExcel->querySubObject("ActiveWorkBook");

/**< get table i.*/                         //获取第一个工作表sheet1:

QAxObject * worksheet = activeSheets->querySubObject("Worksheets(int)", 1);

//qDebug() << worksheet->property("Name").toString();     //获取工作表名:

/**< get/set  cell value.*/              // 获取cell的值

QAxObject * pExcelCell;

/**< initlialize parameter.*/

uiMaxColumn = RESRATIOCOLUMN;

/**< set Work Table header.*/

QString strTemp;

strTemp = tr("编号");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 1 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("时间");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 2 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("串口");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 3 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("IP");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 4 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("硬件型号");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 5 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("序列号");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 6 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("OSD");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 7 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("DRGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 8 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("ARGB");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 9 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("校准园");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 10 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("黑白点");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 11 );

pExcelCell->setProperty("Value", QVariant(strTemp));

strTemp = tr("工厂图");

pExcelCell= worksheet->querySubObject("Cells(int,int)", 1, 12 );

pExcelCell->setProperty("Value", QVariant(strTemp));

//qDebug() <<"Excel::setRatioAllSigExcelHeader(): "<< strTemp<<pExcelCell->property("Value").toString();

}

/**

* @brief Write a Test Message

* @param sLTestMsg [QList<QString>]  the Qstring List of test message

* @param  Eg:  sLTestMsg<<tr("1")<<tr("2013/8/7 20:30:00")<<tr("COM1")<<tr("192.168.1.1")<<tr("VCL-H3L")

* @param  <<tr("正确")<<tr("正确")<<tr("正确")<<tr("正确")<<tr("正确")<<tr("正确");

* @return void

*/

void QExcel::WriteExcelMsg(QList<QString> sLTestMsg)

{

qDebug()<<sLTestMsg<<sLTestMsg.count();

/**< get active work books.*/

QAxObject * activeSheets = objExcel->querySubObject("ActiveWorkBook");

/**< get table 1.*/

QAxObject * worksheet = activeSheets->querySubObject("Worksheets(int)", 1);

/**< get the max  of rows.*/

QAxObject * pExcelRange = worksheet->querySubObject("UsedRange");

QAxObject * pExcelRows = pExcelRange->querySubObject("Rows");

uiMaxRow = pExcelRows->property("Count").toInt();

//qDebug()<<"lcl..........."<<uiMaxRow<<uiMaxColumn;

/**< get/set  cell value.*/

QAxObject * pExcelCell;

for(unsigned int i=1;i<=uiMaxColumn;i++)

{

pExcelCell= worksheet->querySubObject("Cells(int,int)", uiMaxRow+1, i );

pExcelCell->setProperty("Value", QVariant(sLTestMsg.at(i-1)));

}

}

/**

* @brief Save Excel File

* @param saveFile [QString]

* @return 0:success   -1:failed

*/

bool QExcel::SaveExcel(QString saveFile)

{

qDebug()<<" QExcel::SaveExcel:"<<saveFile;

/**< save Excel.*/

QAxObject * workExcel= objExcel->querySubObject("ActiveWorkBook");

objExcel->setProperty("DisplayAlerts", 0);

workExcel->dynamicCall("SaveAs (const QString&)", saveFile);

objExcel->setProperty("DisplayAlerts", 1);

workExcel->dynamicCall("Close (Boolean)", false);

/**< exit Excel.*/

//objExcel->dynamicCall("Quit (void)");

return true ;

}

qt 操作excel表格的更多相关文章

  1. Python 利用Python操作excel表格之openyxl介绍Part2

    利用Python操作excel表格之openyxl介绍 by:授客 QQ:1033553122 欢迎加入全国软件测试交流qq群(群号:7156436) ## 绘图 c = LineChart()    ...

  2. Python 利用Python操作excel表格之openyxl介绍Part1

    利用Python操作excel表格之openyxl介绍 by:授客 QQ:1033553122 欢迎加入全国软件测试交流qq群(群号:7156436),免费获取以下性能监控工具(类似Nmon精简版) ...

  3. 【转】python操作excel表格(xlrd/xlwt)

    [转]python操作excel表格(xlrd/xlwt) 最近遇到一个情景,就是定期生成并发送服务器使用情况报表,按照不同维度统计,涉及python对excel的操作,上网搜罗了一番,大多大同小异, ...

  4. Python 利用Python操作excel表格之xlwt介绍

    利用Python操作excel表格之xlwt介绍   by:授客 QQ:1033553122 直接上代码   案例1 #!/usr/bin/env python # -*- coding:utf-8 ...

  5. 用NPOI、C#操作Excel表格生成班级成绩单

    在C#中利用NPOI操作Excel表格非常方便,几乎上支持所有的Excel表格本身所有的功能,如字体设置.颜色设置.单元格合并.数值计算.页眉页脚等等. 这里准备使用NPOI生成一个班级成绩单Exce ...

  6. python - 操作excel表格

    说明:由于公司oa暂缺,人事妹子在做考勤的时候,需要通过几个excel表格去交叉比对员工是否有旷工或迟到,工作量大而且容易出错. 这时候it屌丝的机会来啦,花了一天时间给妹子撸了一个自动化脚本. 1. ...

  7. 转载:python操作excel表格(xlrd/xlwt)

    python操作excel表格(xlrd/xlwt)   最近遇到一个情景,就是定期生成并发送服务器使用情况报表,按照不同维度统计,涉及python对excel的操作,上网搜罗了一番,大多大同小异,而 ...

  8. 使用Java操作Excel表格

    目录 一.配置第三方库 二.使用Apache POI API 1. 打开Excel文件 2. 选择对应的sheet 3. Sheet接口的基本使用 3.1 获取开头行和结束行 3.2 获取Row对象 ...

  9. Qt 操作Excel

    Qt对Excel的数据读/写操作没有现存的类,需要使用QAxObject,下面是从网上下载下来的一个封装好的类,感觉还可以,一般情况下够用,拿来给大家分享. 头文件: #ifndef EXCELENG ...

随机推荐

  1. javasscript学习笔记 之 数组学习二 数组的所有方法

    1.push() 和 pop()  栈的方法 后进先出 push() 该方法是向数组末尾添加一个或者多个元素,并返回新的长度. push()方法可以接收任意数量的参数,把它们逐个添加到数组的末尾,并返 ...

  2. oracle数据库事务相关【weber出品必属精品】

    事务的概念:事务:一个事务由一组构成一个逻辑操作的DML语句组成 事务有开始有结束,事务以DML语句开始,以Conmmit和Rollback结束.以下情况会使得事务结束: 1. 执行COMMIT 或者 ...

  3. iOS中UISearchBar(搜索框)使用总结

    http://my.oschina.net/u/2340880/blog/509756

  4. 重写String类,也有些区别,供参考

    头文件如下: #pragma once #include <string> #include <string.h> #include <stdlib.h> #inc ...

  5. 内存管理pbuf.c源码解析——LwIP学习

    声明:个人所写所有博客均为自己在学习中的记录与感想,或为在学习中总结他人学习成果,但因本人才疏学浅,如果大家在阅读过程中发现错误,欢迎大家指正. 本文自己尚有认为写的不完整的地方,源代码没有完全理清, ...

  6. jQuery中Ajax事件顺序及各参数含义

    Ajax会触发很多事件.有两种事件,一种是局部事件,一种是全局事件: 局部事件:通过$.ajax来调用并且分配. $.ajax({ beforeSend: function(){ // Handle ...

  7. 初学 Play Framework 以及可能遇到的问题

    这段话之后都是我从别人那拷贝过来的资料,方便大家查阅 红色标注字体是我自己遇到的一些问题: 如果你遇到了这样的问题  :

  8. 查看Linux系统相关版本信息

    1.“uname -a” 查看电脑以及操作系统的相关信息 2.“cat /proc/version” 查看运行的内核版本 3."cat /etc/redhat-release",  ...

  9. 阅读书目_2014H1

    1.<程序员修炼之道 专业程序员必知的33个技巧>(完成) 注:更多是面向程序员全工作流程的. 2.linux shell脚本攻略 适合初学,但不方便作为参考手册查阅. 3.编写可读代码的 ...

  10. 配置Kestrel 网址Urls

    配置Kestrel 网址Urls ASP.NET Core中如何配置Kestrel Urls呢,大家可能都知道使用UseUrls() 方法来配置. 今天给介绍全面的ASP.NET Core 配置 Ur ...