Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

CSV to Excel

by raj8 (Sexton)
on Jun 08, 2010 at 18:40 UTC ( #843721=perlquestion: print w/replies, xml ) Need Help??

raj8 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

After receiving some data within a CSV file, how would I take CSV file with a few thousand lines of unique data and create an Excel file with the 31 fields such as F1, F2 etc. As always, any insight would be appreciated.

__DATA__ 3,8,ADSM,08/03/2000,16:26:37,node1,,AIX,1,Tcp/Ip,0,254,1713,0,0,47,147 +6,0,0,3316,960,27,5,1,4,0,0,0,0,7,2

Replies are listed 'Best First'.
Re: CSV to Excel
by toolic (Bishop) on Jun 08, 2010 at 18:54 UTC
Re: CSV to Excel
by Generoso (Prior) on Jun 08, 2010 at 19:39 UTC

    Have you tried to open it directly on excel? Excel can open CVS files directly and save it as excel.

      I would rather automate the process.

        I find it ironic that you say you want to automate the process but you haven't presented any code saying what you have tried. Perhaps you should make an effort to write something and I am sure someone would be willing to help from there.

        You are asking how to convert a csv file to an excel file. The point that is being made is that a csv file is an excel file. MS Excel opens CSV files with no intermediate processing needed.

Re: CSV to Excel
by Tux (Canon) on Jun 09, 2010 at 06:19 UTC

    Text::CSV_XS comes with csv2xls in the examples folder. I use that in production code for customers on an almost daily basis.

    Others suggest to open CSV with Excel directly. This might work, but more likely is very error-prone. Excel converts many "things" is the imported data based on various outside settings, like locale and local list-separator characters. That means that your numbers might turn into dates, and your (ISO)dates YYYYMMDD suddenly become dates in braindead US format (MM/DD/YY), even if the CSV data was quoted!

    For that last problem, csv2xls has the -D option, in which you can specify what columns represent dates and a -d option to specify the required date format.

    Enjoy, Have FUN! H.Merijn
Re: CSV to Excel
by bluescreen (Friar) on Jun 09, 2010 at 00:01 UTC

    Hi, I'd use Spreadsheet::WriteExcel

    I've used that and it rocks. The API can be overwhelming at first, but read the synopsis and you'll get it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://843721]
Approved by toolic
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2021-04-15 11:55 GMT
Find Nodes?
    Voting Booth?

    No recent polls found