Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I think this will do what you want:

#!/usr/bin/perl use strict; use warnings; use Excel::Writer::XLSX; use Spreadsheet::XLSX; my $master = 'master.xlsx'; -f $master or die "Spreadsheet '$master' not found: $!"; my $excel = Spreadsheet::XLSX->new($master) or die "Cannot open spreadsheet '$master' for reading: $!"; my $sheet = $excel->{Worksheet}[0]; my $last_old_id = $sheet->{Cells}[ $sheet->{MaxRow} ][0]{Val} // 'IT +S0000'; $last_old_id =~ /(\d+)/; my $first_new_id = $1 + 1; print "How many Serial Numbers do you need?\n"; my $mal = <STDIN>; my $comp = 'ITS'; my @array; for my $number (1 .. ($first_new_id + $mal - 1)) { my $exp = $comp . sprintf("%04d", $number); push @array, $exp; } my $simple = 'simple.xlsx'; my $workbook = Excel::Writer::XLSX->new($simple) or die "Cannot open spreadsheet '$simple' for writing: $!"; my $worksheet = $workbook->add_worksheet(); my @array2 = @array[($first_new_id - 1) .. ($first_new_id + $ma +l - 2)]; $worksheet->write_col(0, 0, \@array2); $workbook = Excel::Writer::XLSX->new($master) or die "Cannot open spreadsheet '$master' for writing: $!"; $worksheet = $workbook->add_worksheet(); $worksheet->write_col(0, 0, \@array);

The full set of IDs is stored in the first column of master.xlsx. The new IDs are (over-)written into the file simple.xlsx, as before.

Hope that helps,

Update: As Anonymous Monk implies below, you have to create an Excel file called master.xlsx first (using Excel), before you run the code. The file should initially be empty.

Athanasius <°(((><contra mundum


In reply to Re^3: serial number generator by Athanasius
in thread serial number generator by royserna03

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (4)
    As of 2014-09-17 01:56 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (56 votes), past polls