How to save Excel report in different formats

Good day

I have an Intraweb 14 Delphi VCL program which exports information associated with a SQL query to Excel but can not get it to allow me to save the streamed output in anything other than the default .xls format of the original template. How do I change this?

I currently use an XLSXAdapter (using the older technology which produces an component in my datamodule, represented by an icon although I have the latest version of Flexcel (6.7.1) as well as version 3.81. The XLSXAdapter has save formats defined as snXLS, snCSVComma, snCSVsemicolon and snXLSX set true. The command to save to a web stream is



This allows me to open or save the file as .xls but if I change the file name to have a .xlsx or .csv extension it does not work.

Any guidance would be appreciated.




FlexCel 3 had a somehow overcomplicated way to save in different formats: You could select multiple formats and they all would be saved at the same time. But of course, this meant that you needed a way to tell the xlsxadapter the filename or stream for each one of the formats. There are 2 events you can use for that:
e</div><div><div>procedure TIWForm1.FlexCelReport1GetFilename(Sender: TObject;</div><div>&nbsp; const FileFormat: Integer; var Filename: TFileName);</div><div>begin</div><div><br></div><div>end;</div><div><br></div><div>procedure TIWForm1.FlexCelReport1GetOutStream(Sender: TObject;</div><div>&nbsp; const FileFormat: Integer; var OutStream: TStream);</div><div>begin</div><div><br></div><div>end;</div></div><div><br></div><div>

In your case, as you are saving to a stream you would use the second one.

But I wouldn't use any of this. As said, this is a bad overcomplicated design in FlexCel 3. But also, by doing it this way you will only get the formats you mentioned (csv, xls, xlsx) and you will anyway miss pdf and html, which are probably more interesting (especially html since you are doing intraweb)

So my advise would be to extract the FlexCel 6 TXlsFile object from the XlsxAdapter, and use that to export to different file formats. 

I've uploaded a little sample on how to do this here:

Basically, you unselect all the save formats in the XlsxAdapter, so when you call run the report is generated but not saved. Then in the AfterGenerateWorkbook event, you grab the real FlexCel 6 TXlsFile object used by TXlsxAdapter, and use that to export. There are much more options this way (for example when exporting to text you can specify the encoding to be utf8 or whatever). And you can get pdf and html too.  (the main issue with html is images)

The only thing to be aware is that there is an "old" TExcelFile object (used in FlexCel 3) and the new TExcelFIle object used in FlexCel 6. You might need to prefix TExcelFile with FlexCel.Core.TExcelFile.