Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qsv excel only works with Little Endian? #609

Closed
ondohotola opened this issue Nov 22, 2022 · 14 comments
Closed

qsv excel only works with Little Endian? #609

ondohotola opened this issue Nov 22, 2022 · 14 comments

Comments

@ondohotola
Copy link

I have a number of spreadsheets written by the Perl module Spreadsheet::WriteExcel.

When I extract with qsv excel I get something like ^@ for every character and further processing such as search becomes impossible.

When I look at the spreadsheets with file I get something like

a.xls: CDFV2 Microsoft Excel

whereas the "normal" files (which extract properly) look like

b.xls: Composite Document File V2 Document, Little Endian...

Desktop (please complete the following information):

  • OS: Mac Ventura
  • qsv 0.72.0-standard-apply;fetch;foreach;generate;luau;self_update-8-8 (x86_64-apple-darwin compiled with Rust 1.65) prebuilt
@ondohotola
Copy link
Author

In the interim I can pipe through

tr -d '\000'

@jqnatividad
Copy link
Owner

@ondohotola thanks for the report.

Can you attach some sample Excel files generated by Spreadsheet::WriteExcel to help me reproduce the error?

@ondohotola
Copy link
Author

ondohotola commented Nov 24, 2022 via email

@jqnatividad
Copy link
Owner

Hi @ondohotola ,
Thanks for the detailed follow-up... can you also provide some sample files for the scenario above?

I'm particularly interested in the file generated by Spreadsheet::WriteExcel.

@ondohotola
Copy link
Author

ondohotola commented Nov 28, 2022 via email

@jqnatividad
Copy link
Owner

@ondohotola ,
You should just be able to drag them on top of the text field right here on GitHub issues - if you look at the bottom of the comment box it says - "Attach files by dragging & dropping, selecting or pasting them."

https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/attaching-files

And yes, its OK to sometimes Read the Fine Manual... 😉

@ondohotola
Copy link
Author

ondohotola commented Nov 28, 2022

testforqsv.ods
testforqsv.xls
testforqsvnew.xls

#!/usr/bin/env perl
use Spreadsheet::WriteExcel;    # To write the XLS
$workbook  = Spreadsheet::WriteExcel->new("testforqsv.xls");
$worksheet = $workbook->add_worksheet();
#
# set it up
#
$bc = $workbook->add_format();
$bc->set_bold();
$bc->set_color('black');
$bc->set_align('center');

$left = $workbook->add_format();
$left->set_align('left');

$right = $workbook->add_format();
$right->set_align('left');

$dollar = $workbook->add_format();
$dollar->set_num_format('0.00');
$dollar->set_align('right');

$format[0] = $right;
$format[1] = $left;
$format[2] = $left;
$format[3] = $right;
$format[4] = $dollar;
$format[5] = $left;
$format[6] = $left;
$format[7] = $left;
$format[8] = $left;

$worksheet->set_column( 0, 0, 14 );
$worksheet->set_column( 1, 1, 25 );
$worksheet->set_column( 2, 3, 14 );
$worksheet->set_column( 4, 4, 9 );
$worksheet->set_column( 5, 5, 20 );
$worksheet->set_column( 6, 8, 30 );

$worksheet->write ( 0, 0, "Account Number",   $bc );
$worksheet->write ( 0, 1, "Account Name",     $bc );
$worksheet->write ( 0, 2, "Transaction Date", $bc );
$worksheet->write ( 0, 3, "Transaction ID",   $bc );
$worksheet->write ( 0, 4, "Amount",           $bc );
$worksheet->write ( 0, 5, "Reference",        $bc );
$worksheet->write ( 0, 6, "Description",      $bc );
$worksheet->write ( 0, 7, "Notes",            $bc );
$worksheet->write ( 0, 8, "Memo",             $bc );

for ( $i = 1; $i <= 3; $i++ ) {
    for ( $j = 0; $j <= 8; $j++ ) {
        $worksheet->write( $i, $j, "Test-$i:$j", $format[$j] );
    }
}
$workbook->close () or die "Error closing file: $!";

Could be shorter, maybe, but that does produce the uploaded file, which causes the issue.

Thanks, el

@jqnatividad
Copy link
Owner

jqnatividad commented Dec 3, 2022

Hi @ondohotola ,
Have you tried using Excel::Writer::XLSX instead which was written by the same author of Spreadsheet::WriteExcel?

The author himself recommends Excel::Writer::XLSX as a drop-in replacement for WriteExcel which is in maintenance only mode.

Also, qsv uses the calamine crate to read Excel files, and it has more robust support of the XLSX file format in general.

@ondohotola
Copy link
Author

ondohotola commented Dec 3, 2022 via email

@ondohotola
Copy link
Author

ondohotola commented Dec 3, 2022 via email

@jqnatividad
Copy link
Owner

jqnatividad commented Dec 6, 2022

Hi @ondohotola ,
I'm glad you find qsv useful!

As for your workaround, perhaps you can add an entry into the Cookbook? 😉

As for CSVIEW, have you tried csvlens? It's written in Rust and uses the same csv library qsv uses...

Best,
Joel

@ondohotola
Copy link
Author

ondohotola commented Dec 6, 2022 via email

@ondohotola
Copy link
Author

Done

@ondohotola
Copy link
Author

There was an issue #20 preventing piping to csvlens which has now been fixed.

[...]

As for CSVIEW, have you tried csvlens? It's written in Rust and
uses the same csv library qsv uses...
[...]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants