line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Win32::Word::Writer::Table - Add tables to Word documents.
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Used by the Win32::Word::Writer module.
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=cut
|
11
|
|
|
|
|
|
|
package Win32::Word::Writer::Table;
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
28243
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
14
|
1
|
|
|
1
|
|
5
|
use strict;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
50
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION = '0.01';
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
4
|
use strict;
|
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
23
|
|
27
|
1
|
|
|
1
|
|
5183
|
use Win32::OLE::Const;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Data::Dumper;
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 PROPERTIES
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 oWriter
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Win32::Word::Writer::Table object to write to.
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 alreadyCreatedRow
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Whether a row have been created already.
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Default: 0
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 createdColumnCount
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
The number of columns actually created in the table.
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Default: 0
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 columnPos
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Which column we're adding text to currently
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut
|
57
|
|
|
|
|
|
|
use Class::MethodMaker new_with_init => "new", get_set => [ qw(
|
58
|
|
|
|
|
|
|
oWriter
|
59
|
|
|
|
|
|
|
alreadyCreatedRow
|
60
|
|
|
|
|
|
|
createdColumnCount
|
61
|
|
|
|
|
|
|
columnPos
|
62
|
|
|
|
|
|
|
)];
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 new(oWriter => Win32::Word::Writer $oWriter)
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Create new table writer for $oWriter.
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 init()
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Init the object after creation.
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut
|
79
|
|
|
|
|
|
|
sub init {
|
80
|
|
|
|
|
|
|
my $self = shift;
|
81
|
|
|
|
|
|
|
my (%hParam) = @_;
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$self->createdColumnCount(0);
|
84
|
|
|
|
|
|
|
$self->columnPos(0);
|
85
|
|
|
|
|
|
|
$self->alreadyCreatedRow(0);
|
86
|
|
|
|
|
|
|
$self->oWriter( $hParam{oWriter} ) or die(__PACKAGE__ . "->new() requires an oWriter parameter\n");
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return;
|
89
|
|
|
|
|
|
|
}
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 TableBegin()
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Begin a new table.
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Add a RowBegin() and a ColumnBegin() before adding
|
100
|
|
|
|
|
|
|
any text to the table.
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut
|
103
|
|
|
|
|
|
|
sub TableBegin {
|
104
|
|
|
|
|
|
|
my $self = shift;
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $oTable = $self->oWriter->oDocument->Tables->Add(
|
107
|
|
|
|
|
|
|
$self->oWriter->oSelection->Range,
|
108
|
|
|
|
|
|
|
1, 1,
|
109
|
|
|
|
|
|
|
$self->oWriter->rhConst->{wdWord9TableBehavior},
|
110
|
|
|
|
|
|
|
$self->oWriter->rhConst->{wdAutoFitContent},
|
111
|
|
|
|
|
|
|
);
|
112
|
|
|
|
|
|
|
$oTable->{PreferredWidthType} = $self->oWriter->rhConst->{wdPreferredWidthAuto};
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$self->alreadyCreatedRow(1);
|
115
|
|
|
|
|
|
|
$self->createdColumnCount(1);
|
116
|
|
|
|
|
|
|
$self->columnPos(1);
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
return(1);
|
119
|
|
|
|
|
|
|
}
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 RowBegin()
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Begin a new row in the table. Existing rows and columns are implicitly
|
128
|
|
|
|
|
|
|
closed first.
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut
|
131
|
|
|
|
|
|
|
sub RowBegin {
|
132
|
|
|
|
|
|
|
my $self = shift;
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
if( ! $self->alreadyCreatedRow) {
|
135
|
|
|
|
|
|
|
$self->oWriter->oSelection->InsertRowsBelow(1);
|
136
|
|
|
|
|
|
|
}
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
#Must set the AutoFitBehavior continously it seems, at least not just after creating the table
|
139
|
|
|
|
|
|
|
##todo: set wdAutoFitContent or wdAutoFitWindow depending on the 'table width="100%"' setting.
|
140
|
|
|
|
|
|
|
$self->oWriter->oSelection->Tables(1)->AutoFitBehavior($self->oWriter->rhConst->{wdAutoFitContent});
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
$self->alreadyCreatedRow(0);
|
143
|
|
|
|
|
|
|
$self->columnPos(0);
|
144
|
|
|
|
|
|
|
$self->createdColumnCount(1) if($self->createdColumnCount == 0);
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
return(1);
|
147
|
|
|
|
|
|
|
}
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 ColumnBegin()
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Begin a new column in the row. Existing columns are implicitly closed
|
156
|
|
|
|
|
|
|
first.
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut
|
159
|
|
|
|
|
|
|
sub ColumnBegin {
|
160
|
|
|
|
|
|
|
my $self = shift;
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
if($self->columnPos > 0) {
|
163
|
|
|
|
|
|
|
if($self->columnPos < $self->createdColumnCount) {
|
164
|
|
|
|
|
|
|
$self->oWriter->oSelection->MoveRight( { Unit => $self->oWriter->rhConst->{wdCell} } );
|
165
|
|
|
|
|
|
|
} else {
|
166
|
|
|
|
|
|
|
$self->oWriter->oSelection->InsertColumnsRight();
|
167
|
|
|
|
|
|
|
$self->createdColumnCount( $self->createdColumnCount + 1 );
|
168
|
|
|
|
|
|
|
}
|
169
|
|
|
|
|
|
|
}
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$self->columnPos( $self->columnPos + 1 );
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
return(1);
|
174
|
|
|
|
|
|
|
}
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 TableEnd()
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
End the current table.
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut
|
185
|
|
|
|
|
|
|
sub TableEnd {
|
186
|
|
|
|
|
|
|
my $self = shift;
|
187
|
|
|
|
|
|
|
#This may work badly if the edit isn't linear, but have moved to another place in the document
|
188
|
|
|
|
|
|
|
#but this was the only way I could get it to work. Improvements welcome.
|
189
|
|
|
|
|
|
|
$self->oWriter->oSelection->EndKey({Unit => $self->oWriter->rhConst->{wdStory}});
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
return(1);
|
192
|
|
|
|
|
|
|
}
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 DESTROY
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Release the oWriter
|
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut
|
203
|
|
|
|
|
|
|
sub DESTROY {
|
204
|
|
|
|
|
|
|
my $self = shift;
|
205
|
|
|
|
|
|
|
$self->{oWriter} = undef;
|
206
|
|
|
|
|
|
|
}
|
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 AUTHOR
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Johan Lindström, C<< >>
|
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 BUGS
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Please report any bugs or feature requests to
|
219
|
|
|
|
|
|
|
C, or through the web interface at
|
220
|
|
|
|
|
|
|
L.
|
221
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on
|
222
|
|
|
|
|
|
|
your bug as I make changes.
|
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS
|
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Copyright 2009 Johan Lindström, All Rights Reserved.
|
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
231
|
|
|
|
|
|
|
under the same terms as Perl itself.
|
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=cut
|
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
1;
|
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
__END__
|