-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
55 lines (44 loc) · 1.76 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QAxWidget excel("Excel.Application");
excel.setProperty("Visible", false);
QAxObject* workbooks=excel.querySubObject("WorkBooks");
workbooks->dynamicCall("Add"); // Add new workbook
QAxObject* workbook=excel.querySubObject("ActiveWorkBook");
QAxObject* sheets=workbook->querySubObject("WorkSheets");
QAxObject * cell;
int count= sheets->dynamicCall("Count()").toInt();
bool isEmpty = true;
for(int k=1;k<=count;k++)
{
//sheet pointer
QAxObject* sheet = sheets->querySubObject( "Item( int )", k );
for(int i=1; i<11/*row*/ ; i++)
{
for(int j=1; j<7/*column*/ ;j++)
{
QString text= "ventor";//qrandom(); // value you want to export
//get cell
QAxObject* cell = sheet->querySubObject( "Cells( int, int )", i,j);
//set your value to the cell of ith row n jth column
cell->dynamicCall("SetValue(QString)",text);
// if you wish check your value set correctly or not by retrieving and printing it
QVariant value = cell->dynamicCall( "Value()" );
}
}
}
QString fileName=QFileDialog::getSaveFileName(0,"save file","export_table", "XML Spreadhseet(*.xlsx);;eXceL Spreadsheet(*.xls);;Comma Seperated Value(*.csv)");
fileName.replace("/","\\");
workbook->dynamicCall("SaveAs(QString&)",fileName);
workbook->dynamicCall("Close (Boolean)",false);
}