Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win32::OLE Again :/ Adding front/end page...

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi,

I've currently got the following code, which works fine;

Code:
    my $doc;
	$doc  = $Word->Documents->Open($fullpath_doc) || die Win32::OLE->LastError;

    # if (ref $doc->BuiltInDocumentProperties("Title") eq "HASH") {

    $doc->BuiltInDocumentProperties("Title")->{Value} = $title;
    $doc->BuiltInDocumentProperties("Subject")->{Value} = $title;
    $doc->BuiltInDocumentProperties("Author")->{Value} = $title;
    $doc->BuiltInDocumentProperties("Manager")->{Value} = $title;
    $doc->BuiltInDocumentProperties("Company")->{Value} = $title;
    $doc->BuiltInDocumentProperties("Comments")->{Value} = $comments;
    $doc->BuiltInDocumentProperties("Category")->{Value} = $title;
    $doc->BuiltInDocumentProperties("Keywords")->{Value} = $title;
    $doc->BuiltInDocumentProperties("Hyperlink Base")->{Value} = "[URL unfurl="true"]http://www.$destsite";[/URL]
    $doc->CustomDocumentProperties->Add({
		    Name          => "Downloaded From",
		    LinkToContent => 0,
		    Type          => 4,
		    Value         => "[URL unfurl="true"]http://www.$destsite/"[/URL]
    });
	$doc->CustomDocumentProperties->Add({
		    Name          => "Owner",
	    	LinkToContent => 0,
		    Type          => 4,
		    Value         => "$destsite/"
	});
	$doc->CustomDocumentProperties->Add({
		    Name          => "Copyright",
		    LinkToContent => 0,
		    Type          => 4,
		    Value         => "$destsite"
	});
	$doc->CustomDocumentProperties->Add({
		    Name          => "Can Redistribute",
		    LinkToContent => 0,
		    Type          => 4,
		    Value         => "No, do not redistribute/"
	});

	$doc->Range->InsertBefore("$insert_before_one\n\n");
	$doc->Range->InsertBefore("$insert_before_two\n\n");

	my $fontTitleParagraph = $doc->Paragraphs->Count - $doc->Paragraphs->Count + 2;
	my $fontExampleParagraph = $doc->Paragraphs->Count - $doc->Paragraphs->Count + 3;
	my $range = $doc->Paragraphs($fontTitleParagraph)->Range;

	$range->Font->{Name} = "Verdana";
	$range->Font->{Size} = 10;
	$range->Font->{Bold} = -1;
	$range = $doc->Paragraphs($fontExampleParagraph)->Range;
	
	$doc->Hyperlinks->Add();
	$doc->Hyperlinks->Add( {Anchor => $range, Address => "[URL unfurl="true"]http://www.$destsite",[/URL] SubAddress => ""});

	$range->Font->{Name} = "Verdana";
	$range->Font->{Size} = 8;
	my $formatStart = $doc->Paragraphs($fontTitleParagraph)->Range->Start;
	my $formatEnd = $doc->Paragraphs($fontExampleParagraph)->Range->End;

	$doc->Range->InsertAfter("\n\n$insert_after_one\n\n");
	$doc->Range->InsertAfter("$insert_after_two\n\n");
	$fontTitleParagraph = $doc->Paragraphs->Count - 3;
	$fontExampleParagraph = $doc->Paragraphs->Count - 2;
	$range = $doc->Paragraphs($fontTitleParagraph)->Range;
	$range->Font->{Name} = "Verdana";
	$range->Font->{Size} = 10;
	$range->Font->{Bold} = -1;
	$range = $doc->Paragraphs($fontExampleParagraph)->Range;

	$doc->Hyperlinks->Add();
	$doc->Hyperlinks->Add( {Anchor => $range, Address => "[URL unfurl="true"]http://$destsite",[/URL] SubAddress => ""});

	$range->Font->{Name} = "Verdana";

	$range->Font->{Size} = 8;
	my $formatStart = $doc->Paragraphs($fontTitleParagraph)->Range->Start;
	my $formatEnd = $doc->Paragraphs($fontExampleParagraph)->Range->End;
   
	$doc->Save();	
	$doc->Close();

However, I'm now trying to add a header/footer page to every document (to stop theives, or at least discourage them).

Does anyone know how to do this with Win32::OLE in Word?

TIA

Andy
 
Ok, managed to fix this now :)

Something I'm still struggling with, is;

$range->Font->{Name} = "Verdana";
$range->Font->{Size} = 8;
$range->Font->{Underline} = 'msoFalse';

The part in bold is where I'm having the problem. Basically, the content around that area is being underlined (taken from the document I guess, as the first line is underlined). I just need to be able to turn "underline" off, but can't find the right combination :|

TIA

Andy
 
While I don't use the OLE module for anything I do, would you post the solution to your original question so others may pick up what you've learned?

- Rieekan
 
heheh.. the solution was actually pretty simple for the new page thing. Just change these lines;

$doc->Range->InsertAfter("\n\n$insert_after_one\n\n");
$doc->Range->InsertAfter("$insert_after_two\n\n");

..to it looks something like;

$doc->Range->InsertAfter("\n\n\n\n$insert_after_one\n\n\n\n\n\n\n\n");
$doc->Range->InsertAfter("\n\n$insert_after_two\n\n\n\n\n\n");

Seems to work perfectly for me :)

Cheers

Andy
 
Code:
 $range->Font->{Underline} = '[COLOR=red].[/color]msoFalse';
is worth a try
--Paul

cigless ...
 
Hi,

Thanks for the reply :) It didn't work though :'(

Cheers

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top