I'm attempting to modify an Excel spreadhsheet which
spreadsheet has a merged cell at D8.
I wrote a small program which reads
the format of D8 and writes some data back to D8 in a new sheet with that
formatting:
#!/usr/bin/perl -w
use strict;
use Smart::Comments;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::SaveParser;
# Open the template with SaveParser
my $parser = new Spreadsheet::ParseExcel::SaveParser;
my $template = $parser->Parse('sat.xls');
warn "template:$template:";
my $sheet = 0;
my $workbook;
{
# SaveAs generates a lot of harmless warnings about unset
# Worksheet properties. You can ignore them if you wish.
local $^W = 0;
# Rewrite the file or save as a new file
$workbook = $template->SaveAs('new.xls');
}
# Use Spreadsheet::WriteExcel methods
my $worksheet = $workbook->sheets(0);
my $row = 7;
my $col = 3;
# Get the format from the cell
my $format = $template->{Worksheet}[$sheet]->{Cells}[$row][$col]->{For
+matNo};
$worksheet->write( $row, $col => 'some_originating_entity', $format );
However, the new sheet has all the
merged cells unmerged.
Is there a way to preserve merged cells when updating/modifying cells
in the template spreadsheet?
Both the program and the initial spreadsheet are here
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|