Intermediate commit - just have to add/fix POD for two classes, then done
[p5sagit/Excel-Template.git] / lib / Excel / Template / Element / Cell.pm
index 9272e51..08aece9 100755 (executable)
@@ -14,12 +14,12 @@ sub new
     my $class = shift;
     my $self = $class->SUPER::new(@_);
                                                                                 
-    $self->{TXTOBJ} = Excel::Template::Factory->create('TEXTOBJECT');
+    $self->{TXTOBJ} = Excel::Template::Factory->_create('TEXTOBJECT');
                                                                                 
     return $self;
 }
 
-sub get_text
+sub _get_text
 {
     my $self = shift;
     my ($context) = @_;
@@ -27,7 +27,7 @@ sub get_text
     my $txt = $context->get($self, 'TEXT');
     if (defined $txt)
     {
-        my $txt_obj = Excel::Template::Factory->create('TEXTOBJECT');
+        my $txt_obj = Excel::Template::Factory->_create('TEXTOBJECT');
         push @{$txt_obj->{STACK}}, $txt;
         $txt = $txt_obj->resolve($context);
     }
@@ -37,18 +37,46 @@ sub get_text
     }
     else
     {
-UNI_YES        $txt = Unicode::String::utf8('');
-UNI_NO         $txt = '';
+        $txt = $context->use_unicode
+            ? Unicode::String::utf8('')
+            : '';
     }
                                                                                 
     return $txt;
 }
 
+my %legal_types = (
+    'blank'   => 'write_blank',
+    'formula' => 'write_formula',
+    'number'  => 'write_number',
+    'string'  => 'write_string',
+    'url'     => 'write_url',
+);
+
 sub render
 {
     my $self = shift;
     my ($context, $method) = @_;
 
+    unless ( $method )
+    {
+        my $type = $context->get( $self, 'TYPE' );
+        if ( defined $type )
+        {
+            my $type = lc $type;
+
+            if ( exists $legal_types{ $type } )
+            {
+                $method = $legal_types{ $type };
+            }
+            else
+            {
+                warn "'$type' is not a legal cell type.\n"
+                    if $^W;
+            }
+        }
+    }
+
     $method ||= 'write';
 
     my ($row, $col) = map { $context->get($self, $_) } qw(ROW COL);
@@ -59,9 +87,20 @@ sub render
         $context->add_reference( $ref, $row, $col );
     }
 
+    # Apply the cell width to the current column
+    if (my $width = $context->get($self, 'WIDTH'))
+    {
+        $width =~ s/\D//g;
+        $width *= 1;
+        if ($width > 0)
+        {
+            $context->active_worksheet->set_column($col, $col, $width);
+        }
+    }                                                                         
+
     $context->active_worksheet->$method(
         $row, $col,
-        $self->get_text($context),
+        $self->_get_text($context),
         $context->active_format,
     );
 
@@ -115,9 +154,37 @@ Adds the current cell to the a list of cells that can be backreferenced.
 This is useful when the current cell needs to be referenced by a
 formula. See BACKREF and RANGE.
 
-=back 4
+=item * WIDTH
+
+Sets the width of the column the cell is in. The last setting for a given column
+will win out.
+
+=item * TYPE
+
+This allows you to specify what write_*() method will be used. The default is to
+call write() and let S::WE make the right call. However, you may wish to
+override it. Excel::Template will not do any form of validation on what you
+provide. You are assumed to know what you're doing.
+
+The legal types are:
+
+=over 4
+
+=item * blank
+
+=item * formula
+
+=item * number
+
+=item * string
+
+=item * url
+
+=back
+
+q.v. L<Spreadsheet::WriteExcel> for more info.
 
-There will be more parameters added, as features are added.
+=back
 
 =head1 CHILDREN