Config
- Perl 5.20.1 on Redhad Enterprise Linux 5.5.56.
- Using modules:
- use Text::Iconv; # Required by Spreadsheet::XLSX
- use Spreadsheet::XLSX::Reader::LibXML; # For reading XLSX
- use Excel::Writer::XLSX;
- Input XLSX file is 100,000 lines long. I need to read the XLSX file, process it, and write out another XLSX file.
- I will get a new XLSX file about every 2-3 weeks for years to come so manual intervention should be minimized.
The problem
I tried using Spreadsheet::XLSX::Reader::LibXML to read the spreadsheet, but it takes 2.5 hours to read the whole thing. So I decided to manually convert the XLSX file to a tab separated file (TSV) and read the TSV instead. It's faster reading the TSV but this also doesn't work because some cells contain embedded carriage returns (which Excel allows) but which messes up the TSV file. So a single row in the XLSX file appears as multiple rows in the TSV file. Like this:
col1<tab>col2<tab>col3 with
embedded returns<tab>col4<tab>col5
So when I read the CSV file I read it directly into an array like this:
# Open file here
@csv=<$CSVFILE>;
chomp(@csv);
I simply don't have time to go through 100,000 lines each time I get a new XLSX file to fix broken lines with embedded CRLF.
Questions
- Is there a way to speed up reading the XLSX file directly?
- Or is there a Linux util that can convert an XLSX file to a TSV while removing embedded carriage returns from each cell?
- When reading the XLSX file I'm currently reading each row cell by cell using $cell=$worksheet->get_cell($row,$col). I didn't see a method to return a whole row at at time.
- I'm currently researching how to replace all chr(10) and chr(13) in Excel with blanks. Then I'll convert the XLSX to TSV.
Thank you!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.