2012年3月24日星期六

Cheap CoachIf you are doinga report class program

If you are doinga report class program ,may be content to export to Excel file is a must function .Prior to the use of MFC when I wrote a class ,used to grid data export to Excel file .In the use of the QtSql module, I easily this class will be rewritten application program in Qt .
Class name is &ldquo ;ExportExcelObject &rdquo ;.Is very simple to use :/ / 1 declare / / &ndash an object ;fileName Excel file path / / &ndash ;sheetName Excel worksheet ( sheet ) name / / &ndash ;tableView QTableView ExportExcelObject obj need to be derived pointer ( fileName ,sheetName ,tableView ) ;/ / 2 define fields ( columns ) to the Excel sheet file / / &ndash ;the first parameter is a column of QTableView / / &ndash ;the second parameter is to should be Excel sheet ,/ / &ndash ;the third parameter is the type of the column ,Beats Headphones,you can use the char ( x ) ( x 255 ) ,int ,datetime ,obj.
addField ( 1 ,tr ( " ;name" ;" ;char ) ,Beats by dre solo,( 60) ) ;obj.addField ( " ;2 ,tr ( " ;ID" ;" ;int" ;) ,( 3 ,TR ) ;obj.addField ( " ;time" ;" ;datetime " ;,beats tour,) ) ;/ / 3 this kind of specific SIGNAL for connection a progress control ,can display the progress of derived connect ( & ;obj ,Cheap Coach,SIGNAL ( exportedRowCount ( int ) ) ,progressBar ,SLOT ( setValue ( int ) ) ) ;/ / 4 do the work int retVal = obj.
export2Excel ( ) ;if ( retVal > ;0) { / / done} else { / / something so this is how wrong } To achieve ?1 the Excel file as a database using MS ODBC or ADO Excel files can be used as a database ,Monster Beats Butterfly,so we only need to use the DSN connection strings to create and connect to the Excel file :QString DSN = QString ( " ;DRIVER = {Microsoft Excel Driver ( *.
XLS ) } ;DSN = ;FIRSTROWHASNAMES = 1 ;;CREATE_DB = / " ;%1 / " ;DBQ =%2" ;;) .Arg ( excelFilePath ) . Arg ( excelFilePath ) ;2 will Excel sheet ( sheet ) as a database table can use the SQL statement to &ldquo ;CREATE TABLE&rdquo ;to create a working table .
3 insert data into table using the SQL &ldquo ;INSERT &rdquo ;insert into data .4 Unicode support is ,the column names and data support Unicode .I wrote an example for the presentation of this class ( ) .
This procedure in WinXP / Vista / 7 can be normal operation .This procedure does not require your computer to install a Excel ,because the {Microsoft Excel Driver ( *. XLS ) } since Windows 2000 is the system comes with support .
Related articles:

没有评论:

发表评论