On Mon, Nov 09, 2009 at 03:46:19PM -0000, Andy Maginnis wrote:
> Apologies if this the wrong list for this question, if so could someone
> point me in the right direction!
>
> I am trying to generate an script to process multiple CSV's into a
> single excel doc, create tables
> and then create a shell report document template. I have managed all
> this so far but cannot
> seem to add a TOC. From what I can tell I have translated the VBA
> command correctly.
>
> Ideally I would like to add it at the start of the document, however I
> also cannot move the
> selector position & have been trying to just insert a TOC anywhere as a
> first step.
>
> $Word = Win32::OLE->GetActiveObject('Word.Application') ||
> Win32::OLE->new('Word.Application');
> my $document = $Word->Documents->Add;
>
> foreach my $file (getFileListAsArray($basedir,"\.(?:gif|GIF)\$")){
> print "Adding $file to document\n";
> $name=$file;
> $name=~s/$striphead//;
> $name=~s/$striptail//;
>
> $document->ActiveWindow->Selection -> {Style} = "Heading 1";
> $document->ActiveWindow->Selection -> TypeText("$name\n");
>
> $document->ActiveWindow->Selection -> {Style} = "Normal";
> $document->ActiveWindow->Selection -> TypeText("Type Text here
> 1\n");
>
> $Word->Selection->InlineShapes->AddPicture({
> FileName => "$basedir\\$file",
> LinkToFile => "False",
> SaveWithDocument => "True"});
>
> $document->ActiveWindow->Selection -> TypeText("Type Text here
> 2\n");
> $Word->Selection->InsertBreak({Type=>wdSectionBreakNextPage});
>
> }
>
> $Range = $Word->Selection->{'Range'};
> $Word->ActiveDocument->TablesOfContents->Add ({
> Range=>$Range,
> RightAlignPageNumbers=>"True",
> UseHeadingStyles=>"True",
> UpperHeadingLevel=>"1",
> LowerHeadingLevel=>"4",
> IncludePageNumbers=>"True",
> AddedStyles=>"",
> UseHyperlinks=>"True",
> HidePageNumbersInWeb=>"True",
> UseOutlineLevels=>"True"
> });
>
> $document ->SaveAs( $outfile );
> $document ->Close;
>
> Im using Word 2007
>
> many thanks.
You would probably be better off discussing this topic on a more generalised
perl list or forum.
This list is on using DBI - the independent database interface for Perl.