// 1. declare an object
// – fileName contains the path to the Excel file
// – sheetName is the name of the Excel sheet
// – tableView is the pointer to a QTableView
ExportExcelObject obj(fileName, sheetName, tableView);
// 2. define fields (columns) to the Excel sheet file
// – the first parameter is referred to the column number in QTableView
// – the second parameter is the name of the column of the Excel sheet
// – the third parameter is the type of this column, you can use char(x) (max(x) is 255)
// int, datetime, etc
obj.addField(1, tr("name"), "char(60)");
obj.addField(2, tr("ID"), "int");
obj.addField(3, tr("time"), " datetime ");
// 3. connect the signal “exportedRowCount†to a progress widget to show the exporting
// progress if necessary, this makes the exporting progress more user-friendly
connect(&obj, SIGNAL(exportedRowCount(int)), progressBar, SLOT(setValue(int)));
// 4. do the work
int retVal = obj.export2Excel();
if(retVal > 0)
{//done
}
else
{//something wrong
[FONT=Calibri] }[/FONT]
// 1. declare an object
// – fileName contains the path to the Excel file
// – sheetName is the name of the Excel sheet
// – tableView is the pointer to a QTableView
ExportExcelObject obj(fileName, sheetName, tableView);
// 2. define fields (columns) to the Excel sheet file
// – the first parameter is referred to the column number in QTableView
// – the second parameter is the name of the column of the Excel sheet
// – the third parameter is the type of this column, you can use char(x) (max(x) is 255)
// int, datetime, etc
obj.addField(1, tr("name"), "char(60)");
obj.addField(2, tr("ID"), "int");
obj.addField(3, tr("time"), " datetime ");
// 3. connect the signal “exportedRowCount†to a progress widget to show the exporting
// progress if necessary, this makes the exporting progress more user-friendly
connect(&obj, SIGNAL(exportedRowCount(int)), progressBar, SLOT(setValue(int)));
// 4. do the work
int retVal = obj.export2Excel();
if(retVal > 0)
{//done
}
else
{//something wrong
[FONT=Calibri] }[/FONT]
To copy to clipboard, switch view to plain text mode
QString dsn
= QString("DRIVER={Microsoft Excel Driver (*.xls)};DSN=''; FIRSTROWHASNAMES=1; READONLY=FALSE;CREATE_DB=\"%1\";DBQ=%2").
arg(excelFilePath).arg(excelFilePath);
QString dsn = QString("DRIVER={Microsoft Excel Driver (*.xls)};DSN=''; FIRSTROWHASNAMES=1; READONLY=FALSE;CREATE_DB=\"%1\";DBQ=%2").
arg(excelFilePath).arg(excelFilePath);
To copy to clipboard, switch view to plain text mode
Bookmarks