简体   繁体   中英

C++ Builder DBGrid export to Excel in xlsx file

Before, I always used TXLSWorkbook and SaveDialog to export excel(.xls) from DBGrid.

However, now the exported data is too big, .xls file can't fill with all data.

I tried to export .xlsx file ,but TXLSWorkbook didn't seem to support .xlsx file.

When I open the .xlsx file , the error message said the file is broken.

Did I miss something or I have to find another way to export .xlsx file?

Here's my code. Thanks for watching.

 TXLSWorkbook *WorkBook; IXLSWorksheet *WorkSheet; IXLSRange *Cells; int Row; TDateTime dt=Now(); String date = dt; date = FormatDateTime("yyyymmdd",date); FileName = date+".xls"; WorkBook = new TXLSWorkbook(); WorkSheet = WorkBook->Sheets->Add(); Cells = WorkSheet->Cells; . . . (input item to Cells...) . . . SaveDialog1->FileName = FileName; if( SaveDialog1->Execute() == true ) { WorkBook->SaveAs(SaveDialog1->FileName); } 

I don't like posting an answer which is a recommendation to use another 3rd-party library, but in this case it is perhaps appropriate.

See: http://www.scalabium.com/sme/

This is a library which can export database data from Delphi apps to a wide variety of formats, including Excel file formats. It does not use COM, so is not subject to limitations imposed by Excel's COM implementation, though I am not sure whether TXLSWorkBook uses COM. AFAIK, SMExport writes directly to an Excel-format file.

There is a trial version available, iirc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM