Export to excel file

Hi all

I want to export data to excel file, but I don't know how can I save that file into my directory, anyone has any idea?

thanks!
 
hi,
Can you explain more clearly?
My code:

CREATE "Excel.Application" hExcel .
IF NOT VALID-HANDLE(hExcel) THEN RETURN.
hExcel:Visible = FALSE.
hwb = hExcel:WorkBooks:ADD.
hws = hwb:worksheets:ADD.

/* assign some data to hws */

hExcel:activeworkbook:Save.

RELEASE OBJECT hws.
RELEASE OBJECT hwb.
RELEASE OBJECT hExcel.


I dont know where excel file to save.

thank in advance!
 

Jupiter

Member
Code:
ASSIGN vExcelFilePath = "C:\FolderName\FileName.xls".
    IF SEARCH(vExcelFilePath) <> ? THEN
        OS-DELETE VALUE(vExcelFilePath).
    
      chWorkSheet:SaveAs (vExcelFilePath,,,,,,,,).

You can try the above.
 

dayv2005

Member
WOw i completely didn't read this my bad i posted an example of an excel dump. hwell if you need an example pm me
 

sridevi.stalin

New Member
v can use the following code also,


DEFINE VARIABLE icntr AS INTEGER NO-UNDO.
DEFINE VARIABLE chExcelApplication AS COM-HANDLE.
DEFINE VARIABLE chWorkbook AS COM-HANDLE.
DEFINE VARIABLE chWorksheet AS COM-HANDLE.
DEFINE VARIABLE lcDate AS CHARACTER FORMAT "X(10)" NO-UNDO.
CREATE "Excel.Application" chExcelApplication NO-ERROR.
chExcelApplication:VISIBLE = TRUE NO-ERROR.
chWorkbook = chExcelApplication:Workbooks:Add(1).
chWorkSheet = chExcelApplication:Sheets:Item(1).
chWorkSheet:Range("B1") :Font:Bold = TRUE NO-ERROR.
chWorkSheet:Range("A2:K6"):Font:Bold = TRUE NO-ERROR.
chExcelApplication:Workbooks:ITEM(1):Windows:ITEM(1)isplayGridLines = TRUE NO-ERROR.
lcDate = STRING(TODAY).
ASSIGN chWorkSheet:Range("B1"):Value = "Customer - Report"
chWorkSheet:Range("A4"):Value = "Date:"
chWorkSheet:Range("B4"):Value = lcDate
chWorkSheet:Range("A5"):Value = "Cust-No"
chWorkSheet:Range("B5"):Value = "Name"NO-ERROR.
chWorksheet:Range("D5:G5"):HorizontalAlignment = -4152 NO-ERROR. /* For Right Alignment */
chWorksheet:Range("I5:K5"):HorizontalAlignment = -4152 NO-ERROR.
icntr = 7.
FOR EACH Customer:
icntr = icntr + 1.
chExcelApplication:Worksheets("Sheet1"):Cells(icntr,1) = Customer.Name .
ASSIGN chWorkSheet:Range("A" + string(icntr)):Value = Customer.Cust-Num
chWorkSheet:Range("B" + string(icntr)):Value = Customer.NAME NO-ERROR.
END. /* End of FOR EACH */
chWorkSheet:Range("A1:K"+ STRING(icntr)):COLUMNS:Autofit() NO-ERROR.
RELEASE OBJECT chExcelApplication.
RELEASE OBJECT chWorkbook.
RELEASE OBJECT chWorksheet.

the above code applicable for Sports Database.
 

jongpau

Member
Another option you have, which I find is faster than using ActiveX and as an extra big bonus will also work on UNIX, is to create your Excel file in XML format (but with the normal Excel file extension). The newer (from Office 2002 onward I believe ??) will read the xml and load it into without problems. Good thing with this approach (compared to csv files for instance) is that you can create multiple worksheets and use all formatting options available in Excel as well.

If you want to see how to format the XML, you can just create a little spreadsheet in Excel and then save it in Excel XML format (should be one of the options). Wordpad (or any other text editor) can then be used to look at the actual file contents.
 

lord_icon

Member
How dumb ARE you and that is NOT a rhetorical question.

All the replies given complicate the instance. Look at it objectively, you wish to create an excel file and populate with data from the db. Simple logic dictates Output your stream to a *.xls file. Windows will apply the appropriate formatting. You just require the 4GL to create the excel document and populate with data as appropriate. Do NOT complicate matters.
Regards,
 

Jupiter

Member
All the replies given complicate the instance
I beg to differ Lord. This is beginner's level question and the answer should be straight forward. It seems that replies 1 & 2 are to the point and appropriate at this level.
While Sridevi has given a complete procedure, this may not be newbie's requirement. ;)
Jongpau's reply may not be what newbie exactly wanted. But this may interest others. There are other visitors to this thread also.

Look at it objectively, you wish to create an excel file and populate with data from the db. Simple logic dictates Output your stream to a *.xls file. Windows will apply the appropriate formatting. You just require the 4GL to create the excel document and populate with data as appropriate.

Your reply may be erudite but unfortunately not very useful at the beginner's level.

How dumb ARE you and that is NOT a rhetorical question.
Therefore, seems that people not are exactly dumb. But many of us tend to overdo things or do things which were not essential. For example, I reply to your comment! :lol:
 
Top