I want to convert an csv file on unix (which is generated by a ETL application) to a formatted excel sheet like .I have roughly like 28 columns
1)All numbers need to be stored as numbers with leading zeros-like format as text for this column to preserve leading zeroes e.g '0012'
2)All Amounts should be formatted as numbers with 2 decimals and separator e.g '123.45'
3)All dates to be formatted as MM/DD/YYYY
My users are totally business and they want this unix csv file totally formatted so that they can use it readily..
I have read forums where people suggested using perl script ..Any initial help to start with is greatly appreciated.
Why not format up your sheet in excel how you want it then save as "XML Spreadsheet 2003".
You can then edit this file and cut out the unnecessary stuff like (<DocumentProperties> <OfficeDocumentSettings> etc.), just play around by editing the file and checking it can still be loaded by excel.
As an example this is a nice 2 column sheet with leading zero format on the first column, it's a fairly simple exercise to then transform a flat csv file into this type of .xml document.
Or course there are perl CPAN modules that can assist in producing this output (Spreadsheet-WriteExcelXML comes to mind), and you may find dealing with these easier.
I need this done on a daily basis like an automated things so hence I cant format it manually..
second thing is I am looking for a shell script/perl script which will take the csv on unix and give me a formatted xls with all the requirements I specified..
Then an awk program could output the HEADER block, and for each csv line replace all the %%FIELD#nn%% values in the ROW block and finally output the FOOTER block.
---------- Post updated at 08:37 AM ---------- Previous update was at 08:13 AM ----------
The code to produce your file could be as simple as this:
However, if your csv has quoted fields with possible escaped characters and the like, you will need something a little smarter, like a proper csv parser.
Fortunately I have already posted one in this forum and we could use most of the code from that: