FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour FW_AdoToExcel and sheet
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
FW_AdoToExcel and sheet
Posted: Tue Sep 28, 2021 07:47 AM

Hello Rao
it is possible with the function FW_AdoToExcel determine in which sheet to export ?

Maurizio

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FW_AdoToExcel and sheet
Posted: Tue Sep 28, 2021 12:11 PM

FW_AdoToExcel( cSql ) --> oSheet

This function creates a new Excel Book, exports to only sheet available, i.e., "Sheet1" and returns the Sheet object.
You can use the oSheet object and do anything with it, including rename it :
oSheet:Name := "SomeOtherName".

Regards



G. N. Rao.

Hyderabad, India
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: FW_AdoToExcel and sheet
Posted: Tue Sep 28, 2021 12:36 PM

Thanks Rao
This Works :D ,
is there a possibility to export more recordest in different Sheets of the same Excel file?
Maurizio

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FW_AdoToExcel and sheet
Posted: Wed Sep 29, 2021 09:51 AM
Code (fw): Select all Collapse
   local oExcel, oBook, oSheet
   local oCn, oRs, n

   oCn      := FW_MSSQLDB()
   oRs      := FW_OpenRecordSet( oCn, "states" )
   xbrowser oRs
   oExcel   := ExcelObj()
   oBook    := oExcel:WorkBooks:Open( "c:\fwh\tests\testbook.xlsx" )
   oSheet   := oBook:WorkSheets( "two" )
   oSheet:Activate()
   oSheet:Cells:Clear()
   for n := 1 to oRs:Fields:Count()
      oSheet:Cells( 1, n ):Value := oRs:Fields( n - 1 ):Name
   next
   oSheet:Cells( 2, 1 ):CopyFromRecordSet( oRs )
   oRs:Close()
   oCn:Close()

   oExcel:Visible := .t.

   return nil
Regards



G. N. Rao.

Hyderabad, India
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: FW_AdoToExcel and sheet
Posted: Thu Sep 30, 2021 07:08 AM

Thanks Rao

Continue the discussion