Displaying a word document into GdViewer

Example requests & Code samples for GdPicture Toolkits.
Post Reply
User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Displaying a word document into GdViewer

Post by Loïc » Fri Oct 17, 2008 4:55 pm

Hi,

Here a code snipet to dispaly a word document into the GdViewer control:


Code: Select all

Dim oWord As Object
 Set oWord = CreateObject("Word.Application")
   
 oWord.Documents.Open "myfile.doc", False, True, False
 oWord.Documents(1).Activate
 Clipboard.Clear
 oWord.Documents(1).Select
 oWord.Selection.CopyAsPicture
 oWord.Application.Documents(1).Close False
 oWord.Quit
 Set oWord = Nothing

 Call GdViewer1.DisplayFromClipboardData

Tom Moran
Posts: 102
Joined: Thu May 24, 2007 9:41 am
Location: Phoenix, Arizona

Re: Displaying a word document into GdViewer

Post by Tom Moran » Fri Oct 17, 2008 9:54 pm

Hey Loic:

Great code!

And... since word can also open html and rtf files you can use the same code to convert those formatted files.

Thanks for the code.

Tom

clocklear
Posts: 16
Joined: Fri Jan 11, 2008 11:04 pm

Re: Displaying a word document into GdViewer

Post by clocklear » Mon Jun 22, 2009 4:59 pm

Loic, when I perform this in my code, I get error 7 (Win32Error) when trying to display clipboard data. Any ideas why? It works when I manually copy an image to the clipboard, but not when I use the Word code.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Displaying a word document into GdViewer

Post by Loïc » Mon Jun 22, 2009 6:42 pm

Hi,

Using the latest release I was able to run this code without any problem. Maybe you are using an older version ?

Kind regards,

Loïc

clocklear
Posts: 16
Joined: Fri Jan 11, 2008 11:04 pm

Re: Displaying a word document into GdViewer

Post by clocklear » Mon Jun 22, 2009 7:10 pm

I just upgraded to the latest version and still the same problem. I am using FoxPro 9 SP2.

Here is a code excerpt:

Code: Select all

PROCEDURE DOCtoTIF
LPARAMETERS cInDoc,cOutTIF

LOCAL oWord As Object,lcTmpFile as String
oWord = CreateObject("Word.Application")

oWord.Documents.Open("&cInDoc", .f., .t., .f.)
oWord.Documents(1).Activate
oImaging.DeleteClipboardData()
oWord.Documents(1).Select
oWord.Selection.CopyAsPicture
oWord.Application.Documents(1).Close(.f.)
oWord.Quit
RELEASE oWord
lnClipImage = oImaging.CreateImageFromClipboard()
IF lnClipImage = 0
	MESSAGEBOX(oImaging.getstat,0+16+4096)
ENDIF 
The messagebox returns 7, and no picture is created.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Displaying a word document into GdViewer

Post by Loïc » Mon Jun 22, 2009 7:38 pm

Hi,

No problem for me.

Here what I've done Using vfp9 sp2 + last GdPicture Pro Imaging SDK version:

- Start new project
- add a GdViewer object (renamed as oGdViewer)
- Add an Imaging object (renamed as oImaging)

Code: Select all

LOCAL oWord As Object
oWord = CreateObject("Word.Application")

oWord.Documents.Open("c:\test.docx", .f., .t., .f.)
oWord.Documents(1).Activate
thisform.oImaging.DeleteClipboardData()
oWord.Documents(1).Select
oWord.Selection.CopyAsPicture
oWord.Application.Documents(1).Close(.f.)
oWord.Quit
RELEASE oWord
lnClipImage = thisform.oImaging.CreateImageFromClipboard()
IF lnClipImage = 0
   MESSAGEBOX(oImaging.getstat,0+16+4096)
ELSE
   thisform.ogdviewer.Setnativeimage(thisform.oImaging.GetNativeImage())
ENDIF 

clocklear
Posts: 16
Joined: Fri Jan 11, 2008 11:04 pm

Re: Displaying a word document into GdViewer

Post by clocklear » Mon Jun 22, 2009 7:46 pm

Replicating exactly what you have posted I still get error 7. :(

Is there any way to pull out any more debugging information?

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Displaying a word document into GdViewer

Post by Loïc » Mon Jun 22, 2009 7:53 pm

Hi,

Did you dried to add:

Code: Select all

application.AutoYield = .F. 
in the init event of your main form ?

Loïc

clocklear
Posts: 16
Joined: Fri Jan 11, 2008 11:04 pm

Re: Displaying a word document into GdViewer

Post by clocklear » Mon Jun 22, 2009 7:54 pm

Just tried. No help.

clocklear
Posts: 16
Joined: Fri Jan 11, 2008 11:04 pm

Re: Displaying a word document into GdViewer

Post by clocklear » Mon Jun 22, 2009 8:13 pm

Ok so I moved it to another computer and it works... the only difference I believe is that the other machine has Office 2007 and my workstation has Office 2003.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest