Jump to content

PHP COM ->ms word


genius_supreme

Recommended Posts

Hi guys,

 

I'm trying to export records from php to ms word which appends text + image.

 

i have got this code from http://www.thaicreate.com/php/php-word.application-addpicture.html

<html>
<head>
<title>ThaiCreate.Com PHP Word.Application Tutorial</title>
</head>
<body>
<?	
$wdColorDarkRed = "&H80";

$wdAlignParagraphCenter = "1";
$wdAlignParagraphLeft = "0";
$wdParagraph = "4";
$wdHorizontalPositionMargin = "0";
$wdTableLeft = "-999998";
$wdCollapseEnd = "0";

$Wrd = new COM("Word.Application");

$DocName = "MyDoc/MyWord.doc";

//$strPath = realpath(basename(getenv($_SERVER["SCRIPT_NAME"]))); // C:/AppServ/www/myphp

$Wrd->Application->Visible = False;

$WrdDoc = $Wrd->Documents->Add();

$MyRange1 = $WrdDoc->Paragraphs->Add->Range;	
$MyRange1->ParagraphFormat->Alignment = $wdAlignParagraphCenter;
$MyRange1->Font->Name = "Verdana";
$MyRange1->Font->Size = "30";		
$MyRange1->Font->Bold = True;
$MyRange1->InsertBefore(chr(13).chr(13)."www.ThaiCreate.Com".chr(13)."Version 2009");

$MyRange1->InlineShapes->AddPicture(realpath("thaicreate-2009.gif"));
//$WrdDoc->InlineShapes->AddPicture(realpath("thaicreate-2009.gif"));
//$WrdDoc->Shapes->AddPicture(realpath("thaicreate-2009.gif"),0,0,MyRange1);
//$WrdDoc->Shapes->AddPicture(realpath("thaicreate-2009.gif"),0,0,Wrd->Selection->Range);

$MyRange2 = $WrdDoc->Paragraphs->Add->Range;	
$MyRange2->ParagraphFormat->Alignment = $wdAlignParagraphCenter;
$MyRange2->Font->Name = "Verdana";
$MyRange2->Font->Size = "15";		
$MyRange2->Font->Bold = True;
$MyRange2->InsertBefore(chr(13).chr(13)."PHP,ASP and ASP.NET Tutorial");

$MyRange2->InlineShapes->AddPicture(realpath("doc.gif"));

$MyRange3 = $WrdDoc->Paragraphs->Add->Range;	
$MyRange3->ParagraphFormat->Alignment = $wdAlignParagraphCenter;
$MyRange3->Font->Name = "Verdana";
$MyRange3->Font->Size = "10";		
$MyRange3->Font->Bold = True;
$MyRange3->Font->Color = $wdColorDarkRed;
$MyRange3->Underline = True;
$MyRange3->InsertBefore(chr(13).chr(13).chr(13).chr(13)."All Rights Reserved");

//$WrdDoc->SaveAs($strPath."/".$DocName);
$WrdDoc->SaveAs(realpath($DocName));
$Wrd->Application->Quit;
$Wrd = null;
?>
Word Created <a href="<?=$DocName?>">Click here</a> to Download.
</body>
</html>

 

This is the best code i've found so far that guides on how to format the text in ms word via PHP. All set to go but one thing that I am trying to accomplish : to have a clickable email address (hyperlink) in the same ms word file.

 

i have got this code somewhere from the net:

$MyRange3->Hyperlinks->Add({range}, 'http://www.google.com', '','',' hyperlink text to display');
// where {range} refers to as anchor

according to that website this methods could be found in ms word visual basic editor (Alt+F11) then object browser (F2)

 

when i replace the {range} above with let say variable $MyRange3.

$MyRange3->Hyperlinks->Add($MyRange3, 'http://www.google.com', '','',' hyperlink text to display');

The output will be produced but overwriting everything in $MyRange3 and displays only the hyperlink.

I would like the email address (hyperlink) to appear at the end of $MyRange3 text.

 

example output

All right reserved [u]hyperlink text to display[/u] 

 

anyone can shed some light on this.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.