in reply to CSV to Excel Converter

Thanks (and ++)! Just a few minor nits...

Does everything in the output xls file really have to be bold?

Given that you start out like this:

my $infile = shift; usage() unless defined $infile && -f $infile;
your usage synopsis really should be like this:
sub usage { print "csv2xls infile [outfile] [subject]\n"; exit; }
(i.e. no brackets around "infile", because it is a required arg)

When I saw this:

# We store the string width as data in the Worksheet object. We us +e # a double underscore key name to avoid conflicts with future name +s. # my $old_width = $worksheet->{__col_widths}->[$col];
I was reminded of having to face a similar issue with DBI; in that module, the handy convention is that any time you want to add some "novel" attributes (hash keys) to the "normal" module object, you simply prefix the attribute name with "private_" -- I don't remember all the circumstances that made this "the right way to do it" with DBI, but it seems like a nice convention to use in general.

BTW, doesn't Excel already support a simple means for importing data from a csv file? I can appreciate the notion of having column widths adjusted for me automatically as the data are loaded, but in most cases, adjusting the column width in Excel isn't that much harder. I also understand the issues with really long csv data sets and the need to split them up somehow to be digestible by Excel, but in those cases, I'd have to wonder: why use Excel at all for that kind of data?

As for the last chunk of your code:

# Very simple conversion between string length and string width for Ar +ial 10. # See below for a more sophisticated method. # sub string_width { return length $_[0]; }
Is that supposed to be a joke, or did you actually leave something off at the end when you posted this? (just curious)

Replies are listed 'Best First'.
Re^2: CSV to Excel Converter
by eric256 (Parson) on Aug 28, 2007 at 14:29 UTC

    Everything isn't bold, just the headers.

    The usage should definitly be changed.../me goes to fix it now.

    From these two points down I plead guilty! That code is all cut and past from the Spreadsheet::WriteExcel examples and once it worked I never looked back ;). I needed a way to make fairly nice excel files out of 100-300k record CSV files, and so I put this together. I agree its pretty worthless loaded into excel and spread accross six worksheets, but when thats what they want no matter what they are told thats what they get. I'm working with someone who doesn't believe the totals i produce so they want the data, of coures they've never found any discrepancies, but some people just like to be in control ;)


    ___________
    Eric Hodges

      Thanks Eric! This works very well. I am in the middle of changing the field headers, but everything works like it was meant to work.

Re^2: CSV to Excel Converter
by Anonymous Monk on Aug 19, 2008 at 11:15 UTC
    Hi, just tried your script, and somehow it does convert "input" to Excel. But not CSV Files. To be specific it converts everything BUT CSV-Files. When I noticed that I made an input file myself like "1";"2";"3" 1;2;3 '1';'2';'3' 1 2 3 The result looked like Failed on "1";"2";"3" and an Excelfile like 1;2;3 (in bold) '1';'2';'3' 1 2 3 each written in the first column of course ;) Any idea why the script fails with CSV-Format?