Hi guys, I'm afraid I'm stuck and in need of assistance!

I currently have my code writing into 2 .csv files but I would like to change that. Is there a way I can have it write into a separate worksheet on the same workbook as the input file ($excel)?

Thanks in advance!

Here's my code...
use warnings; use Spreadsheet::XLSX; my $outfile = "C:\\Users\\Owner\\Documents\\Herping\\Data\\Moon_Illum. +csv"; open my $ofh, ">", $outfile or die "cannot open $outfile: $!\n"; print $ofh ""; my $outfile2 = "C:\\Users\\Owner\\Documents\\Herping\\Data\\Moon_Phase +.csv"; open my $ofh2, ">", $outfile2 or die "cannot open $outfile2: $!\n"; print $ofh2 ""; my $excel = Spreadsheet::XLSX->new('C:\\Users\\Owner\\Documents\\Herpi +ng\\Snake_Data_2010.xlsm'); my $col = 41,; # Read col L , $col has to be a number foreach my $sheet (@{$excel->{Worksheet}}) { $sheet->{MaxRow} ||= $sheet->{MinRow}; foreach my $row ( $sheet->{MinRow} .. $sheet->{MaxRow} ) { my $cell = $sheet->{Cells}[$row][$col]; if ($cell) { my @value = $cell->{Val}; use Astro::MoonPhase; foreach my $i (@value) { my $outfile = "C:\\Users\\Owner\\Documents\\Herping\\Data\ +\Moon_Illum.csv"; open my $ofh, ">>", $outfile or die "cannot open $outfile: + $!\n"; if ($i =~ /^\d/) { (my $MoonPhase, my $MoonIllum) = Astro::MoonPhase: +:phase(($i-24107)*60*60*24+25200); push(my @Illum, $MoonIllum); print $ofh "@Illum\n"; + } } } } } foreach my $sheet (@{$excel->{Worksheet}}) { $sheet->{MaxRow} ||= $sheet->{MinRow}; foreach my $row ( $sheet->{MinRow} .. $sheet->{MaxRow} ) { my $cell = $sheet->{Cells}[$row][$col]; if ($cell) { my @value = $cell->{Val}; use Astro::MoonPhase; foreach my $i (@value) { my $outfile = "C:\\Users\\Owner\\Documents\\Herping\\Data\ +\Moon_Phase.csv"; open my $ofh, ">>", $outfile or die "cannot open $outfile: + $!\n"; if ($i =~ /^\d/) { + (my $MoonPhase, my $MoonIllum) = Astro::MoonPhase: +:phase(($i-24107)*60*60*24+25200); push(my @Phase, $MoonPhase); print $ofh "@Phase\n"; + } } } } }

In reply to Writing into Excel Worksheet by perl_n00b

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.