473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

help with word object model and perl

I need to locate a particular table in a document. I cannot hardcode the table number since it could be different in every doc.
I do have some header text that comes right before it consistently, though. So, I tried to find that text, and then move to the next table.
Then I need to add a row to the table which already has 4 columns. I need to maintain the old content of the table too.
I think I am pretty close, but having a little trouble converting the vb into perl. Do you mind looking this script over and telling me where I went wrong, PLEASE?
use Win32::OLE qw(in);
use Win32::OLE;
use Win32::OLE::Variant;
use Win32::OLE::Const;
use Win32::Process ;
use Win32::OLE::Const 'Microsoft Word';

my $VERSION=$ENV{CLEARCASE_ID_STR};
$VERSION=~s/^\\//;
my $cidate=`date +%d-%B-%Y`;
chomp($cidate);
my $author=$ENV{CLEARCASE_USER};
my $comment=$ENV{CLEARCASE_COMMENT};

my $file=$ENV{CLEARCASE_PN};
$file=~s/\\/\//g;

# start up ms word
#print "starting word\n";
#print `date`;

my $word = Win32::OLE->new('Word.Application','Quit') or die "Could not load MS Word";

my $wd = Win32::OLE::Const->Load($word);
#print `date`;

$word->{'Visible'} = 1; # if you want to see what's going on

# open the word document, you need the full path name

my $doc = $word->Documents->Open( { FileName => $file } );
#print "opened the doc\n";

die "Failed to load doc $file\n" unless $doc;

#print `date`;
$txt = $word->version;
$WordVersion = substr($txt, 0, index($txt,"."));
#$WordVersion = 10;
#print "figured out the version\n";
#print `date`;

$prevsub = $doc->BuiltInDocumentProperties("Subject")->{Value};
#print "Subject = $prevsub\n";
$doc->BuiltInDocumentProperties("Subject")->{Value} = "$VERSION";
$word->Options->{SavePropertiesPrompt} = $FALSE;

# If Word version before 2003, then set the fields separately from the property
# The fields cannot be updated in versions older than 2003.
#
$Word_2003_Version = 11;
if ($WordVersion < $Word_2003_Version) {
$word->ActiveWindow->ActivePane->View->{Type} = wdPageView ;
$word->ActiveWindow->ActivePane->View->{SeekView} = wdSeekCurrentPageHeader;
my $Active = $word->Selection() ;

# do a search and replace
my $find=$Active->Find;

$find->ClearFormatting;
$find->Replacement->ClearFormatting;

$find->{Text} = "$prevsub";

# print "version is $VERSION\n";
$find->Replacement->{Text} = "$VERSION";
$find->Forward => $wd->{True};
$find->Wrap => $wd->{wdFindContinue};

$find->Execute( {
Replace => $wd->{wdReplaceAll},
} );

} else {
# Modify all Fields in the document to reflect the current value
# of their associated Document Variables. The following is specific
# to Microsoft Word 2003 and later
foreach my $obj_Story (in($doc->StoryRanges)) {
$obj_Story->Fields->{Update};
while ($obj_Story->NextStoryrange != "") {
$obj_Story = $obj_Story->NextStoryRange;
$obj_Story->Fields->{Update};
}
}
}

$word->ActiveWindow->ActivePane->View->{Type} = wdPageView ;
$word->ActiveWindow->ActivePane->View->{SeekView} = wdSeekMainDocument;
my $Active = $word->Selection() ;
my $find=$Active->Find;

$find->ClearFormatting;
$find->{Text} = "REVISION HISTORY^p";
$find->Forward => $wd->{True};
$find->Wrap => $wd->{wdFindContinue};
$result=$find->Execute;

$word->ActiveWindow->ActivePane->View->{SeekView}=wdGoToTable;
my $Activetbl = $word->Selection() ;
print "active tbl is $Activetbl\n";
my $row=$Activetbl->Rows->Add();
print "row is $row\n";
for ($col = 4; $col>=0&$col<=4; $col++) {
my $cell=$Activetbl->Cell($row, $col)->Range;
$cell->Text = "Name";
}


# save the file
$doc->SaveAs( "$file" );

$doc->Close( { SaveChanges => $wd->{wdSaveChanges} } );
#$doc->Close( { SaveChanges => $wd->{wdDoNotSaveChanges} } );


# close word

$word->Quit();
Oct 5 '06 #1
0 3978

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: R | last post by:
Hello everybody. I'm writing my own Content System in PHP5. I've written so far main classes for handling DB connections, XML, XForms and Sessions. But I've got problem with one thing - it's...
41
by: Ruby Tuesday | last post by:
Hi, I was wondering if expert can give me some lite to convert my word table into access database. Note: within each cell of my word table(s), some has multi-line data in it. In addition, there...
2
by: srinivas | last post by:
HI All, I am planning to use word object model for printing auto letters for an ASP.NET application , I am not sure If its the best way to do it . The alternative would be use of Crystal...
3
by: andreas | last post by:
With a vb.net application (vb.net 2003) , I want to make a new word doc where I put several bookmarks and also text in paragraphs following the bookmarks How to do? Thanks for any response
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
1
by: JDeats | last post by:
If I embed an WebBrowser control on a WinForm I have the ability to load any ActiveX containable object into that control using this syntax: webBrowser1.Url = new Uri(@"c:\myfile.doc"); Using...
6
by: cj2 | last post by:
I need to create a cover letter in VB. It will have a customers account number at the top and be addressed to them by name for example (Dear Mr. Smith). After this it will be the same text for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.