Thread Problem mit Zugriff auf MS-Word Dokumente (8 answers)
Opened by Andreas Rickert at 2009-10-01 16:25

Gast Andreas Rickert
 2009-10-01 16:25
#126397 #126397
Hallo!

Ich versuche, ein MS-Word Dokument nach bestimmten Mustern zu durchsuchen. An den Fundstellen möchte ich die aktuelle Seite ermitteln und mit abspeichern. Dazu habe ich das folgende Skript geschrieben:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use Win32::OLE qw(in);
$Win32::OLE::Warn = 3;

my $pkorr = 'E:/temp/';
my $file_in = $pkorr.'test2.doc';

$file_out = $pkorr.'reqs.txt';

my $rw = open(SCHREIBEN,"> ".$file_out);


my $Word = Win32::OLE->new('Word.Application', 'Quit') or die "Word problem: ",Win32::OLE->LastError();
my $Doc = $Word->Documents->Open($file_in) or die "Word problem: ",Win32::OLE->LastError();

print "There are ".$Doc->Paragraphs()->Count()." paragraphs.\n";

foreach my $Paragraph ( in( $Doc->Paragraphs() ) )
{
$ParaCount++;
print "(Paragraph $ParaCount) " . $Paragraph->Range()->Characters()->Count() . " characters\n";

$style = $Paragraph->Style()->NameLocal();
print "+$style\n";

if ($style =~ /Überschrift/)
{
$ueberschrift = $Paragraph->Range()->Text();
}

$in = $Paragraph->Range()->Text();
print $in."\n";
if ($in =~ /(RAS-ID [0-9]{0,5}) (.*) \[(.*)\](.*)\[(.*)\]/)
{
$Paragraph->Range()->Select();
my $Selection = $Word->Selection();
$page = $Selection->Information(wdActiveEndPageNumber);
# $page = $Paragraph->Range()->Information(wdActiveEndPageNumber);

print SCHREIBEN "****** Requirement found\n";
print SCHREIBEN "ID: $1\n";
print SCHREIBEN "Text: $2\n";
print SCHREIBEN "Referenzen: $3\n";
print SCHREIBEN "Internal ID: $5\n";
print SCHREIBEN "Kapitel: $ueberschrift\n\n";
print SCHREIBEN "Seite: ".$page;

print "****** Requirement found\n";
print "ID: $1\n";
print "Text: $2\n";
print "Referenzen: $3\n";
print "Internal ID: $5\n";
print "Kapitel: $ueberschrift\n\n";
print "Seite: ".$page;

}
}
close(SCHREIBEN);


Der Aufruf meldet mir nun:
Win32::OLE(0.1709) error 0x80020005: "Typkonflikt"
in METHOD/PROPERTYGET "Information" argument 1 at test2.pl line 36

Der Fehler muss also in dieser Zeile liegen:
$page = $Selection->Information(wdActiveEndPageNumber);

Ich habe per Google schon eine Zeit lang rumgesucht... finde aber keine Lösung?!
Könnt ihr mir helfen?

Der Rest des Skripts funktioniert zu meiner Überraschung nämlich schon ziemlich gut - ich kenne mich mit Perl nämlich nicht sooo gut aus.

Gruß und Vielen Dank im voraus,
Andreas

View full thread Problem mit Zugriff auf MS-Word Dokumente