AW: [PHP-WIN] Re: MS Word COM Object formatting
| From: | (Sven Schnitzke) | Date: | Sat, 23 Aug 2003 11:59:27 +0000 |
| Subject: | AW: [PHP-WIN] Re: MS Word COM Object formatting | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-21235@lists.php.net to get a copy of this message | ||
Hi,
sadly enough it's not that easy. But it is possible:
$word->visible = 0;
$word->Options->ConfirmConversions = false; // menu: options->general->confirm
conversions
// search for HTML Converter
$fcList = $word->FileConverters();
$count = $fcList->Count();
for($i=1; $i<=$count; $i++) {
$fc = $fcList->Item($i);
// go for ClassName, it's locale-independent
if ($fc->ClassName() == 'HTML') break;
}
if ($i <= $count) {
/* HTML Converter available
Documents.Open FileName:="dl.php", ConfirmConversions:=True, ReadOnly:= _
False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
"", Revert:=False, WritePasswordDocument:="",
WritePasswordTemplate:="", _
Format:=wdOpenFormatAuto <- Here you specify the converters index
*/
$word->Documents->Open ('anyfile.html', False, False, False, '',
'', False, "", "", $fc->OpenFormat());
$word->Documents[1]->SaveAs('anyfile.doc', wdFormatDocument);
$word->Document[1]->Close();
$word->Quit();
$word->Release();
}
Some words of caution:
a) At least Word 8.0 (aka Word 97) is at least a little stupid when it comes to understanding HTML.
So don't expect too much of the conversion of complicated formats.
b) Word tends to ask if you want it to update the converters over the internet. This question can
and
must be suppressed once in manually processing a convesion by checking "don't ask
again" or else
word will hang while automatically opening the HTML file.
c) Ron, of course you can set any font spec using COM: a macro suggesting assignment of a property
works just the same in COM. If you see
...Name = "aName"
just make it
...->Name = 'aName';
happy hacking
--
Sven
> -----Ursprüngliche Nachricht-----
> Von: Chris Kranz [SMTP:chris.kranz@cradleygp.co.uk]
> Gesendet am: Freitag, 22. August 2003 15:07
> An: php-windows@lists.php.net
> Betreff: [PHP-WIN] Re: MS Word COM Object formatting
>
> you should be able to ... in word ... open up the html page from word
> itself, and then save it as a word doc... thinking in my head, soemthing
> along the lines of...
>
> $file="bios.html"
> $word=new COM("Word.Application") or die("Cannot start word for you");
> $word->visible =0 ;
> $word->Documents->Open($file);
> $word->Documents[1]->SaveAs("testwrite.doc");
> $word->Quit();
>
>
> in theory, should work... although i could be wrong...
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>