Export DBGRID Delphi to Excel

Hichem_81 Posted messages 126 Status Membre -  
 110110100010001 -
Hello,

I know we've probably asked this question time and time again, but I can't seem to figure it out.

I would like to export the content of my DBGRID Delphi to Excel.
I've tried the source codes available online, but I'm not sure where to put them exactly and what else I need to declare as a procedure.

On top of that, I'm not familiar with MACROS.

So if you could help me, that would be really nice.

I am using a simple DATASOURCE.

Thank you in advance.

Configuration: Windows 7 / Firefox 4.0.1

1 réponse

110110100010001
 
Hello,

As for me, we use a TDatasetExport component (Embarcadero ??) - exporting to PDF/Excel, CSV is done in two lines of code (linking the component to the Dataset and executing the Execute function of the component) to automatically open the correct document.

I will inquire next week about the origin of the component we use if you're interested.

Otherwise, here’s a list of free or paid APIs:

http://www.torry.net/pages.php?id=555

See you.
1
Hichem_81 Posted messages 126 Status Membre 28
 
Thank you very much "binary code," if it works with Embarcadero, I would gladly redo the application, since it's not very complicated, and I own Embarcadero.

Yes, I'm interested if you find anything new on the subject.

I will check the link you gave me right away, thank you so much.
0
110110100010001
 
Re,

The graphical component of the palette we are using is the TReportD3 component from ReportSmith (and not TDataSetExport as mentioned in my previous post).

This component is normally provided from version Delphi 3 on your version of Borland (it replaced the TReport component): you may need to configure your palette to make it appear (switch it from "hidden" to "active" in the palette).

If you are interested in obtaining just the package, I think it can be found on the page http://www.torry.net/pages.php?id=188 under the entry named TReportD3 v.1.1 (extract it, place the .dcu files in the Lib of your Borland installation folder, and configure Borland to make the component appear in your palette).

I don't currently have a very specific example on hand to show you how to configure and use this component (even though it only takes two lines to generate an XLS export), and I haven't found anything very conclusive online yet: I will send them to you without fail tomorrow morning at work.

It's something like this (be careful, this is probably not the exact syntax):

RS := TReportD3.Create; RS.dataset := MonDataset; RS.filetype := "XLS"; RS.Run();


We ourselves use this component to perform "raw" XLS exports (the data is unloaded as is without formatting - only with the column names from the DataSet), but I believe from what I've read that we can generate advanced ReportSmith exports.

However, I did not understand your approach with the XLS Macros you mentioned, but if ReportSmith can generate reports with complex formatting, then the ReportSmith API will handle generating the necessary macros "on the fly" to perform these formats - there's nothing you need to do on your side in Excel...

I hope this is indeed what you are looking for - from what I've understood.

Regards and see you on Monday.
0
Hichem_81 Posted messages 126 Status Membre 28
 
I believe I read that ReporteSmth was an old component in Delphi 3, 4, and 5.
I am running my application under Delphi 7, but if this can help me with exporting my DBGRID, then why not, I would gladly add the component.

As for the MACRO, I thought we had to write lines beforehand to make our export work! Apparently, I was wrong...

Actually, I got a bit lost in false leads, like adding a "JVCL" component, looking for code lines, trying to get everything to work... and then nothing.

By the way, the link you gave me yesterday is in English, and... I'm unfortunately not very good at English... so I'll patiently wait for the code lines you will send me tomorrow, please try to tell me which component these code lines are associated with.

Thanks again for detailing your response so much.

See you tomorrow then.
0
110110100010001
 
Re,

ReportSmith is still available on Delphi 7 and it is provided by default with all the other components.

>> We use it to export XLS / CSV and PDF.

I don’t know if it’s the best, but in any case, it is included in the basic license.

For the MACRO, I thought we had to write lines beforehand to make our export work

It’s ReportSmith that takes care of generating the XLS file and all its content - including the necessary macros (for example, to generate a sophisticated Excel table): there is therefore nothing to pre-set on your side with respect to Excel.

So basically, you need to drop your component on your Form and configure it in graphical mode (mainly associating the DataSet and the output file type).

Then you instantiate this component in your code in the FormCreate, make sure that your DataSet is open, and you just need to call the Run() method when you need it (for example, on the activation of a TButton) so that ReportSmith automatically opens your XLS file in Excel loaded with all the data pointed by your DataSet.

And that’s it - you just need to properly do a Free() of your instance when closing the Form FormClose.

To be honest, I got a bit lost in false leads, like: adding a "JVCL" component, looking for code lines, trying to make everything work... then nothing.

I understand - that said, the JVCL package must surely contain specific usage examples to help you use your components - you need to look closely in the installed package because examples .pas are probably provided - which JVCL component were you trying to implement to export your data?

Note: ReportSmith is not a JVCL component.

I will send you detailed code examples tomorrow morning - the sources are only accessible to me at my workplace and I don’t know them by heart - I don’t use RS often.

Reminder: the component is TReportD3 - try to find it on your Borland palette in the meantime.

Best regards.
0
110110100010001
 
Re,

It seems that I'm completely confused because TReportD3 does not properly support the automatic generation of XLS files.

>> It is used to launch its RS scripts.

In any case, we use our own homemade component that goes through the entire DataSet to write to a file - it's not complicated but it still needs to be written.

I will find out about the "free" APIs from the link I gave you above.

As for me, you will have a solution as soon as tomorrow - no problem.

Sorry and talk to you later.
0