Giter VIP home page Giter VIP logo

xlsx2csv.rs's Introduction

xlsx2csv - An Excel-like spreadsheet to CSV coverter writen in Rust.

USAGE:
    xlsx2csv [FLAGS] [OPTIONS] <xlsx> [output]...

FLAGS:
    -h, --help               Prints help information
    -i, --ignore-case        Rgex case insensitivedly
    -l, --list               List sheet names by id
    -u, --use-sheet-names    Use sheet names as output filename prefix (in current dir or --workdir)
    -V, --version            Prints version information

OPTIONS:
    -d, --delimiter <delimiter>    Delimiter for output [default: ,]
    -X, --exclude <exclude>        A regex pattern for matching sheetnames to exclude, used with '-u'
    -I, --include <include>        A regex pattern for matching sheetnames to include, used with '-u'
    -s, --select <select>          Select sheet by name or id in output, only used when output to stdout
    -w, --workdir <workdir>        Output files location if `--use-sheet-names` setted

ARGS:
    <xlsx>         Input Excel-like files, supports: .xls .xlsx .xlsb .xlsm .ods
    <output>...    Output each sheet to sperated file

Install

cargo install xlsx2csv

Advanced Usage

output sheets one-by-one

Simple usage is similar to ssconvert syntax, like this:

xlsx2csv input.xlsx sheet1.csv sheet2.csv

This will output the first to sheet1.csv, the second to sheet2.csv, and ignore other sheets.

pipe output

If no output position args setted, eg. xlsx2csv input.xlsx, it'll write first sheet to stdout. So the two commands are equal:

  • xlsx2csv input.xlsx sheet1.csv
  • xlsx2csv input.xlsx > sheet1.csv.

If you want to select specific sheet to stdout, use -s/--select <id or name> (id is 0-based):

xlsx2csv input.xlsx -s 1

In previous command, it'll output the second(0-based 1 is the second) sheet to stdout.

list sheetnames

Use --list/-l it will just print all the sheetnames by id.

xlsx2csv --list
xlsx2csv -l

multiple sheets without filename setted

If there's many sheets that you don't wanna set filename for each, use -u/--use-sheet-names to write with sheetnames.

xlsx2csv input.xlsx -u

If you want to write to directory other than ., use -w/--workdir along with -u option.

xlsx2csv input.xlsx -u -w test/

The filename extension is detemined by delimiter, , to .csv, \t to .tsv, others will treat as ','.

multiple sheets matching or not matching a regex pattern

By default, it will output all sheets, but if you want to select by sheet names with regex match, use -I/--include to include only matching, and -X/--exclude to exclude matching. You could also combine these two option with include-first-exclude-after order:

xlsx2csv input.xlsx -I 'a\d+'
xlsx2csv input.xlsx -X '\s'
xlsx2csv input.xlsx -I '\S{3,}' -X 'Sheet'

The last command line will first include all sheet with pattern '\S{3,}' matched and then exclude that match Sheet.

Detailed options

The following is printed by xlsx2csv --help

USAGE:
    xlsx2csv [FLAGS] [OPTIONS] <xlsx> [output]...

FLAGS:
    -h, --help               
            Prints help information

    -i, --ignore-case        
            Regex case insensitivedly.
            
            When this flag is provided, the include and exclude patterns will be searched case insensitively. used with
            '-u'.
    -l, --list               
            List sheet names by id

    -u, --use-sheet-names    
            Use sheet names as output filename prefix (in current dir or --workdir)

    -V, --version            
            Prints version information


OPTIONS:
    -d, --delimiter <delimiter>    
            Delimiter for output.
            
            If `use-sheet-names` setted, it will control the output filename extension: , -> csv, \t -> tsv [default: ,]
    -X, --exclude <exclude>        
            A regex pattern for matching sheetnames to exclude, used with '-u'

    -I, --include <include>        
            A regex pattern for matching sheetnames to include, used with '-u'

    -s, --select <select>          
            Select sheet by name or id in output, only used when output to stdout

    -w, --workdir <workdir>        
            Output files location if `--use-sheet-names` setted


ARGS:
    <xlsx>         
            Input Excel-like files, supports: .xls .xlsx .xlsb .xlsm .ods

    <output>...    
            Output each sheet to seprated file.
            
            If not setted, output first sheet to stdout.

License

MIT OR Apache-2.0

xlsx2csv.rs's People

Contributors

alexwennerberg avatar zitsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

xlsx2csv.rs's Issues

attempt to calculate the remainder with a divisor of zero

When trying to convert a file i get:
thread 'main' panicked at 'attempt to calculate the remainder with a divisor of zero', /home/dev/.cargo/registry/src/github.com-1ecc6299db9ec823/xlsx2csv-0.1.0/src/main.rs:126:16
It seems the offending line is:
if i % (size.0 / 100) == 0 {
So size.0 has to be 0 at some point. I'm not good enough with Rust to debug further.

Argument syntax leads to unpredictable output

Hi
I really like this tool, its way faster than ssconvert from gnumeric but it has a big drawback I think should be fixed.

When invoking there does not seem to be a way to specify the output file. Thats a bug.

I suggest changing to follow the syntax of ssconvert.
xlsx2csv input.xlsx output.csv
WDYT?

ooxml issue

When I try to parse my XLSX sheet, I get the following error:

[/Users/awennerb/.cargo/registry/src/github.com-1ecc6299db9ec823/ooxml-0.2.4/src/document/spreadsheet/mod.rs:269] raw = "20210929154340"
[/Users/awennerb/.cargo/registry/src/github.com-1ecc6299db9ec823/ooxml-0.2.4/src/document/spreadsheet/mod.rs:269] style_id = 1
[/Users/awennerb/.cargo/registry/src/github.com-1ecc6299db9ec823/ooxml-0.2.4/src/document/spreadsheet/mod.rs:269] raw = "20211028074817"
[/Users/awennerb/.cargo/registry/src/github.com-1ecc6299db9ec823/ooxml-0.2.4/src/document/spreadsheet/mod.rs:269] style_id = 1
thread 'main' panicked at 'not implemented: cell type not supported: str', /Users/awennerb/.cargo/registry/src/github.com-1ecc6299db9ec823/ooxml-0.2.4/src/document/spreadsheet/worksheet.rs:173:22

Reverting to the version before ooxml was a dependency resolves this issue. Any idea what the source could be?

missing field activeCell

I get this error when running.

thread 'main' panicked at 'parse worksheet error: XmlDeError(Custom("missing field `activeCell`"))', /.../ooxml-0.2.5/src/document/spreadsheet/mod.rs:124:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Convert datetimes

Right now, the program does not properly handle datetime objects. I think ideally it should convert these to a datetime string.

Usage and Installation under Windows

Hello,
A question really and not a bug report.
I have been using this software for a while on my linux platform and it is brilliant!
I know next to nothing about rust and cargo, but my question is if xlsx2csv would work also on a windows platform so that I can recommend it to other users.
Many thanks.

`use-header` & `use-sheet-name` are using the same flag `-u`

OPTIONS:
    -d, --delimiter <DELIMITER>    Delimiter for output [default: ,]
    -h, --help                     Print help information
    -i, --ignore-case              Regex case insensitivedly
    -I, --include <INCLUDE>        A regex pattern for matching sheetnames to include, used with
                                   '-u'
    -l, --list                     List sheet names by id
    -s, --select <SELECT>          Select sheet by name or id in output, only used when output to
                                   stdout
    -u, --use-header               Use first line as header, which means use first line to select
                                   columns
    -u, --use-sheet-names          Use sheet names as output filename prefix (in current dir or
                                   --workdir)
    -w, --workdir <WORKDIR>        Output files location if `--use-sheet-names` setted
    -X, --exclude <EXCLUDE>        A regex pattern for matching sheetnames to exclude, used with

Panick with ods file

Using the precompiled binary on Ubuntu 20.04.
doing

xlsx2csv test.ods

results in

thread 'main' panicked at 'open xlsx file: PackageContentTypeError', src/main.rs:206:69

The same document, when converted to xslx, can be converted flawlessly.

The test.ods file can be found in the attached test.zip

test.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.