FWH, ole, Word and Excel

Post Reply
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

FWH, ole, Word and Excel

Post by driessen »

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. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: FWH, ole, Word and Excel

Post by Antonio Linares »

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
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: FWH, ole, Word and Excel

Post by driessen »

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. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
ADutheil
Posts: 352
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: FWH, ole, Word and Excel

Post by ADutheil »

Michel,

I use a lot of copy and paste with excel. You may want to try to adapt the code

Code: Select all

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 BCC 5.82 MinGW 4.5.2 MSVS 10
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: FWH, ole, Word and Excel

Post by nageswaragunupudi »

There are other ways, but this is oneway.

Code: Select all

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
Post Reply