LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   while converting CSV to XLS in Perl, want to do some formatting (https://www.linuxquestions.org/questions/programming-9/while-converting-csv-to-xls-in-perl-want-to-do-some-formatting-4175717827/)

hyattdj 10-16-2022 12:33 PM

while converting CSV to XLS in Perl, want to do some formatting
 
Been a long time since I did serious Perl programming.
We have successfully converted CSV to xls but have a couple of bugs we want to correct before presenting to the customer.

We want to select column width. As the "dates" in the header column show up as XXXX and the users want to see the date.

Also, we are putting in a variable (date) into a cell. But the value does not look like any date format I know. But when we go into excel and define that cell as a date. The date is correct (looks too few digits to be linux start date).

The documentation I have looked at seems to be very narrow. Is there any documentation on how to do extensive formatting of XLS files from the command line/program which modules or what in the modules can do this formatting from a CSV file to an XLS file.
We would also like to use a broader range of colors and other formatting.
Thanks in advance

Guttorm 10-17-2022 08:17 AM

What library are you using?

I did it a long time ago with Perl. I can't remember what I used, but it was something like this:

https://metacpan.org/pod/Excel::Writer::XLSX

It has lots of documentation and formats. Dates are a bit special.

https://metacpan.org/pod/Excel::Writer::XLSX#write_date_time(-$row,-$col,-$date_string,-$format-)

boughtonp 10-17-2022 08:31 AM


 
If you want formatted tabular data, easiest is to generate HTML tables.

If the client insists on Microsoft Excel, still use HTML, but with "mso-number-format" styling and saved as .xls extension.

Here's an example: https://dev.to/michrodz/styling-excel-cells-with-mso-number-format-css-attribute-updated-j6i


TB0ne 10-17-2022 09:31 AM

Quote:

Originally Posted by hyattdj (Post 6386723)
Been a long time since I did serious Perl programming. We have successfully converted CSV to xls but have a couple of bugs we want to correct before presenting to the customer.

We want to select column width. As the "dates" in the header column show up as XXXX and the users want to see the date.

Also, we are putting in a variable (date) into a cell. But the value does not look like any date format I know. But when we go into excel and define that cell as a date. The date is correct (looks too few digits to be linux start date).

The documentation I have looked at seems to be very narrow. Is there any documentation on how to do extensive formatting of XLS files from the command line/program which modules or what in the modules can do this formatting from a CSV file to an XLS file. We would also like to use a broader range of colors and other formatting.

Not a lot to go on...you don't provide any samples of the input data, or any samples of your code that tell us what you're currently using or how. The Excel::Writer::XLSX
library, as Guttorm suggested:
https://metacpan.org/pod/Excel::Writer::XLSX

...has extensive documentation. Dates in Excel are numbers, followed by formatting.
https://metacpan.org/pod/Excel::Writ...-plus-a-format


All times are GMT -5. The time now is 09:53 AM.