Hello all, I am trying to use a hash to efficiently create multiple Excel workbooks with different worksheets in each. Unfortunately, while the over all workbooks are created, and I don't see any errors, I can't get information written into the actual worksheets. Any help here would be appreciated. The following sample code creates three different workbooks, each with one worksheet. The worksheets should each be named "Test," but that doesn't work. Also, the string "TEST TEST" should be written into A1 on each worksheet.
#!/usr/bin/perl use Getopt::Std; use Time::Local; use Spreadsheet::WriteExcel; use OLE::Storage_Lite; my $data_directory="."; my $SP_summary_filename=""; my $LUN_summary_filename=""; my $DISK_summary_filename=""; my $SP_workbook=""; my $LUN_workbook=""; my $DISK_workbook=""; my $ge_sec=""; my $ge_min=""; my $ge_hour=""; my $ge_mday=""; my $ge_mon=""; my $ge_year=""; my $ge_wday=""; my $ge_yday=""; my $ge_isdist=""; ($ge_sec,$ge_min,$ge_hour,$ge_mday,$ge_mon,$ge_year,$ge_wday,$ge_y +day,$ge_isdst)=localtime(time); $SP_summary_filename=sprintf("NARA_SP_"."%4d-%02d-%02d_%02d%02d%02d.xl +s",$ge_year+1900,$ge_mon+1,$ge_mday,$ge_hour,$ge_min,$ge_sec); $LUN_summary_filename=sprintf("NARA_LUN_"."%4d-%02d-%02d_%02d%02d%02d. +xls",$ge_year+1900,$ge_mon+1,$ge_mday,$ge_hour,$ge_min,$ge_sec); $DISK_summary_filename=sprintf("NARA_Disk_"."%4d-%02d-%02d_%02d%02d%02 +d.xls",$ge_year+1900,$ge_mon+1,$ge_mday,$ge_hour,$ge_min,$ge_sec); $INFO=SP; $AH{'SS'}{$INFO}{'POINTER'}=Spreadsheet::WriteExcel->new($SP_summary_f +ilename); $AH{'SS'}{$INFO}{'SS_NAME'}=$SP_summary_filename; $INFO=LUN; $AH{'SS'}{$INFO}{'POINTER'}=Spreadsheet::WriteExcel->new($LUN_summary_ +filename); $AH{'SS'}{$INFO}{'SS_NAME'}=$LUN_summary_filename; $INFO=DISK; $AH{'SS'}{$INFO}{'POINTER'}=Spreadsheet::WriteExcel->new($DISK_summary +_filename); $AH{'SS'}{$INFO}{'SS_NAME'}=$DISK_summary_filename; for $INFO (keys %{$AH{'SS'}}) { print "The spreadsheet is $AH{'SS'}{$INFO}{'SS_NAME'}.\n"; $AH{'SS'}{$INFO}{'top_left_header_format'}=$AH{'SS'}{$INFO}{'POINTER'} +->add_format(); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_color('white'); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_bg_color('navy'); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_font('Arial'); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_size(8); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_bold(1); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_text_wrap(1); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_align('center'); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_valign('vcenter'); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_left('2'); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_top('2'); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_bottom('1'); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_right('1'); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_left_color('8'); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_top_color('8'); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_bottom_color('9'); $AH{'SS'}{$INFO}{'top_left_header_format'}->set_right_color('9'); $AH{'SS'}{$INFO}{'FIRST_WS'} = $AH{'SS'}{$INFO}{'POINTER'}->add_worksh +eet("Test"); $AH{'SS'}{$INFO}{'FIRST_WS'}->set_column('A:A', 2); $AH{'SS'}{$INFO}{'FIRST_WS'}->write_string('A1',"TEST TEST",$AH{'SS'}{ +$INFO}{'top_left_header_format'}); print "For fun:\n"; print "$AH{'SS'}{$INFO}{'POINTER'}\n"; print "$AH{'SS'}{$INFO}{'top_left_header_format'}\n"; print "$AH{'SS'}{$INFO}{'FIRST_WS'}\n"; print "End of pass.\n"; print "\n"; }
UPDATE: Apparently in this situation you actually need to "close" the workbook. The docs say that the workbook will close on program execution. So, I'll I did was make the following change:
...... print "End of pass.\n"; print "\n"; $AH{'SS'}{$INFO}{'POINTER'}->close(); }

In reply to Hash with WriteExcel by wsand101

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.