tags:

views:

442

answers:

4

Hi,

How would you go about saving TRichedit text to an Excel file?

I have the data delimited with the vertical tab #9 and if I save it to .xls it opens, but I would like to save the users the trouble of saving it again as excel after opening it.

Thanks, Dave Albert

+1  A: 

I would look at using the office open xml format. It is fairly easy to program too, and would allow you the most control over your output. A good reference would be the OpenXML Developer website.

skamradt
+2  A: 

There are a number of ways to do it. Your question isn't very precise about what kind of data you're working with so you should be aware that there may be limits in Excel (particularly based on the Excel version) for displaying extensive RichEdit data unless you use a text box. Since you then say you have the data delimited, I'm assuming this is actually a table-like structure and it doesn't contain pictures and the like. Following that assumption, you could use:

  • OpenOffice as a solution as skamradt mentions. You should be aware that it's not ActiveX and uses, IMO, a poorly documented OLE interface. If you go this way, you'll find that Andrew Pitonyak's site really helps. You will also want to pickup Bernard Marcelly's Delphi OO samples from SourceForge as a nice starting point.
  • Use Excel as an OLE automation object. There are a lot of examples out there on how to do this. One guide that might be similar to what you want is here. This is likely the easiest solution since you can open your tabbed data via automation and then do a Save As.
  • Use something other than a RichEdit. For instance, DevExpress has a grid product that comes with an Excel converter. Excel is a pretty common target for certain types of components, particularly in purchased packages, but I'm not sure if that's acceptable for your project.
Marshall Fryman
Thanks so much, the Excel as an OLE automation object was what helped.
Dave Albert
+1  A: 

I would not save tab-delimited text with an xls file extension - that's a kludge.

I find that saving tabular data in comma-delimited format works well, and often use this solution for the following reasons:

  • If Excel is installed, the .csv file extension is generally associated so double-clicking works, without "faking" the file extension
  • If Excel is not installed or not associated with .csv, the user may have another program associated with the .csv extension and this solution will still work
Argalatyr
I definitely agree with NOT using a fake file extension.
Hemant
I don't disagree, but this is kludge of kludge situation (I am a Clinical Application Analyst not a developer) thanks for everyone's input.
Dave Albert
A: 

Have a look at the XLSReadWrite component (http://www.axolot.com/components/xlsrwii20.htm). It provides an API where you can save directly to xls files without the need for an excel installation or any external dependencies.

ajob