Win32::Word::Writer::Table - Add tables to Word documents.


Win32-Word-Writer documentation Contained in the Win32-Word-Writer distribution.

Index


Code Index:

NAME

Top

Win32::Word::Writer::Table - Add tables to Word documents.

SYNOPSIS

Top

Used by the Win32::Word::Writer module.

PROPERTIES

Top

oWriter

Win32::Word::Writer::Table object to write to.

alreadyCreatedRow

Whether a row have been created already.

Default: 0

createdColumnCount

The number of columns actually created in the table.

Default: 0

columnPos

Which column we're adding text to currently

new(oWriter => Win32::Word::Writer $oWriter)

Create new table writer for $oWriter.

init()

Init the object after creation.

TableBegin()

Begin a new table.

Add a RowBegin() and a ColumnBegin() before adding any text to the table.

RowBegin()

Begin a new row in the table. Existing rows and columns are implicitly closed first.

ColumnBegin()

Begin a new column in the row. Existing columns are implicitly closed first.

TableEnd()

End the current table.

DESTROY

Release the oWriter

AUTHOR

Top

Johan Lindström, <johanl[ÄT]DarSerMan.com>

BUGS

Top

Please report any bugs or feature requests to bug-win32-word-document-writer@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Win32-Word-Writer. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


Win32-Word-Writer documentation Contained in the Win32-Word-Writer distribution.
package Win32::Word::Writer::Table;

use warnings;
use strict;





our $VERSION = '0.01';





use strict;
use Win32::OLE::Const;
use Data::Dumper;


use Class::MethodMaker new_with_init => "new", get_set => [ qw(
	oWriter
	alreadyCreatedRow
	createdColumnCount
	columnPos
)];





sub init {
	my $self = shift;
	my (%hParam) = @_;

	$self->createdColumnCount(0);
	$self->columnPos(0);
	$self->alreadyCreatedRow(0);
	$self->oWriter( $hParam{oWriter} ) or die(__PACKAGE__ . "->new() requires an oWriter parameter\n");

	return;
}





sub TableBegin {
    my $self = shift;
    
	my $oTable = $self->oWriter->oDocument->Tables->Add(
			$self->oWriter->oSelection->Range,
			1, 1, 
			$self->oWriter->rhConst->{wdWord9TableBehavior},
			$self->oWriter->rhConst->{wdAutoFitContent},
			);
	$oTable->{PreferredWidthType} = $self->oWriter->rhConst->{wdPreferredWidthAuto};

	$self->alreadyCreatedRow(1);
	$self->createdColumnCount(1);
	$self->columnPos(1);

	return(1);
}





sub RowBegin {
    my $self = shift;

    if( ! $self->alreadyCreatedRow) {
		$self->oWriter->oSelection->InsertRowsBelow(1);
	}

	#Must set the AutoFitBehavior continously it seems, at least not just after creating the table 
	##todo: set wdAutoFitContent or wdAutoFitWindow depending on the 'table width="100%"' setting.
	$self->oWriter->oSelection->Tables(1)->AutoFitBehavior($self->oWriter->rhConst->{wdAutoFitContent});

	$self->alreadyCreatedRow(0);
	$self->columnPos(0);
	$self->createdColumnCount(1) if($self->createdColumnCount == 0);
	
	return(1);
}





sub ColumnBegin {
	my $self = shift;

	if($self->columnPos > 0) {
		if($self->columnPos < $self->createdColumnCount) {
			$self->oWriter->oSelection->MoveRight( { Unit => $self->oWriter->rhConst->{wdCell} } );
		} else {
			$self->oWriter->oSelection->InsertColumnsRight();
			$self->createdColumnCount( $self->createdColumnCount + 1 );
		}
	}
	
	$self->columnPos( $self->columnPos + 1 );

	return(1);
}





sub TableEnd {
    my $self = shift;
			#This may work badly if the edit isn't linear, but have moved to another place in the document
			#but this was the only way I could get it to work. Improvements welcome.
	$self->oWriter->oSelection->EndKey({Unit => $self->oWriter->rhConst->{wdStory}});

	return(1);
}





sub DESTROY {
    my $self = shift;
	$self->{oWriter} = undef;
}









1;





__END__