FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour FWH, ole, Word and Excel
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
FWH, ole, Word and Excel
Posted: Fri Oct 11, 2013 02:17 PM

Hello,

Maybe a strange question but I'm looking in FWH for a way to import an excel-file into a Word-document.

Anyone any idea?

Thanks a lot in advance.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: FWH, ole, Word and Excel
Posted: Fri Oct 11, 2013 02:52 PM

Michel,

Do you mean to embed the spreadsheet into the Word doc, or to export its data into Word ? thanks

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: FWH, ole, Word and Excel
Posted: Sat Oct 12, 2013 01:52 PM

Antonio,

I indeed want to embed the spreadsheet into the Word doc.

Thanks.

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 368
Joined: Sun May 31, 2009 06:25 PM
Re: FWH, ole, Word and Excel
Posted: Sat Oct 12, 2013 05:09 PM
Michel,

I use a lot of copy and paste with excel. You may want to try to adapt the code
Code (fw): Select all Collapse
oExcel := CREATEOBJECT( "Excel.Application" )
oExcel:WorkBooks:Open( "C:\Where_is_the_file\Name_of_the_file" )
nI := which sheet I want to use (1st, 2nd, 3rd ...)
oSheet := oExcel:Sheets( nI )
oTemp := oSheet:Range( the range U want to copy ) //Range( "A1","AL37" )
oTemp:copy()

// I open a new excel file select a sheet then paste

oSheet2:paste()


I do not know if it can be done but you could try something like oPage:paste(). I do not know why but sometime the formating is lost or partialy lost during the operation.
Regards,



André Dutheil

FWH 13.04 + HB 3.2 + MSVS 10
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FWH, ole, Word and Excel
Posted: Sun Oct 13, 2013 05:33 AM
There are other ways, but this is oneway.
Code (fw): Select all Collapse
function Main()

   local oWord, oExcelRange, oDoc

   oWord          := WinWordObj()
   if oWord == nil
      MsgStop( "Can not open Word Application" )
      return nil
   endif
   oExcelRange    := GetExcelRange( "c:\fwh\samples\compare.xls", "Regions", "Sales" )
   if oExcelRange == nil
      MsgStop( "Can not read Excel Range" )
      return nil
   endif

   oDoc     := oWord:Documents:Add()
   oExcelRange:Copy()
   oDoc:Paragraphs( oDoc:Paragraphs:Count ):Range:InsertParagraphAfter()
   oDoc:Paragraphs( oDoc:Paragraphs:Count ):Range:PasteExcelTable( .t., .f., .t. )
   oWord:Visible := .t.

return nil

Keeps a link to excel table and any changes in excel are ready by word.
Retains excel formatting.
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion