简体   繁体   English

C ++ Builder DBGrid以xlsx文件格式导出到Excel

[英]C++ Builder DBGrid export to Excel in xlsx file

Before, I always used TXLSWorkbook and SaveDialog to export excel(.xls) from DBGrid. 以前,我一直使用TXLSWorkbook和SaveDialog从DBGrid导出excel(.xls)。

However, now the exported data is too big, .xls file can't fill with all data. 但是,现在导出的数据太大,.xls文件无法填充所有数据。

I tried to export .xlsx file ,but TXLSWorkbook didn't seem to support .xlsx file. 我尝试导出.xlsx文件,但TXLSWorkbook似乎不支持.xlsx文件。

When I open the .xlsx file , the error message said the file is broken. 当我打开.xlsx文件时,错误消息指出文件已损坏。

Did I miss something or I have to find another way to export .xlsx file? 我错过了什么吗,还是必须找到另一种导出.xlsx文件的方法?

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/ 请参阅: 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. 这是一个可以将Delphi应用程序中的数据库数据导出为多种格式(包括Excel文件格式)的库。 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. 它不使用COM,因此不受TX的COM实现的限制,尽管我不确定TXLSWorkBook是否使用COM。 AFAIK, SMExport writes directly to an Excel-format file. AFAIK,SMExport直接写入Excel格式的文件。

There is a trial version available, iirc. 有一个可用的试用版,iirc。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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