# excel

> Exports a specified Excel/ODS sheet to a CSV file.

**[Table of Contents](TableOfContents.md)** | **Source: [src/cmd/excel.rs](https://github.com/dathere/qsv/blob/master/src/cmd/excel.rs)** | [🚀](TableOfContents.md#legend "multithreaded even without an index.")

<a name="nav"></a>
[Description](#description) | [Examples](#examples) | [Usage](#usage) | [Arguments](#arguments) | [Excel Options](#excel-options) | [Common Options](#common-options)

<a name="description"></a>

## Description [↩](#nav)

Exports a specified Excel/ODS sheet to a CSV file.
The first non-empty row of a sheet is assumed to be the header row.


<a name="examples"></a>

## Examples [↩](#nav)

> Export the first sheet of an Excel file to a CSV file:

```console
qsv excel input.xlsx --output output.csv
```

> Export the first sheet of an ODS file to a CSV file:

```console
qsv excel input.ods -o output.csv
```

> Export the first sheet of an Excel file to a CSV file with a custom delimiter:

```console
qsv excel input.xlsx -d ";" > output.csv
```

> Export a sheet by name (case-insensitive):

```console
qsv excel --sheet "Sheet 3" input.xlsx
```

> Export a sheet by index:
> this exports the 3rd sheet (0-based index)

```console
qsv excel -s 2 input.xlsx
```

> Export the last sheet (negative index):

```console
qsv excel -s -1 input.xlsx
```

> Export the second to last sheet:

```console
qsv excel -s -2 input.xls
```

> Export a table named "Table1" in an XLSX file. Note that --sheet is not required
> as the table definition includes the sheet.

```console
qsv excel --table "Table1" input.xlsx
```

> Export a range of cells in the first sheet:

```console
qsv excel --range C3:T25 input.xlsx
```

> Export a named range in the workbook. Note that --sheet is not required
> as named ranges include the sheet.

```console
qsv excel --range MyRange input.xlsx
```

> Export a range of cells in the second sheet:

```console
qsv excel --range C3:T25 -s 1 input.xlsx
```

> Export a range of cells in a sheet by name.
> Note the range name must be enclosed in single quotes in certain shells
> as it may contain special characters like ! and $:

```console
qsv excel --range 'Sheet2!C3:T25' input.xlsx
```

> Export the cell C3 in the first sheet:

```console
qsv excel --cell C3 input.xlsx
```

> Export a single cell from a specific sheet:

```console
qsv excel --cell 'Sheet2!C3' input.xlsx
```

> Export metadata for all sheets in CSV format:

```console
qsv excel --metadata csv input.xlsx
```

> Export metadata in short CSV mode which is much faster
> but doesn't contain as much metadata

```console
qsv excel --metadata short input.xlsx
```

> Export metadata for all sheets in JSON format:

```console
qsv excel --metadata json input.xlsx
```

> Export metadata to pretty-printed JSON - first letter is capital J

```console
qsv excel --metadata JSON input.xlsx
```

> Export metadata in short, minified JSON mode - first letter is capital S

```console
qsv excel --metadata Short input.xlsx
```

For more examples, see [tests](https://github.com/dathere/qsv/blob/master/tests/test_excel.rs).

See also <https://github.com/dathere/qsv/wiki/Conversion-and-IO#excel>

<a name="usage"></a>

## Usage [↩](#nav)

```console
qsv excel [options] [<input>]
qsv excel --help
```

<a name="arguments"></a>

## Arguments [↩](#nav)

| Argument&nbsp; | Description |
|----------|-------------|
| &nbsp;`<input>`&nbsp; | The spreadsheet file to read. Use "-" to read from stdin. Supported formats: xls, xlsx, xlsm, xlsb, ods. |

<a name="excel-options"></a>

## Excel Options [↩](#nav)

| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Option&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Type | Description | Default |
|--------|------|-------------|--------|
| &nbsp;`‑s,`<br>`‑‑sheet`&nbsp; | string | Name (case-insensitive) or zero-based index of sheet to export. Negative indices start from the end (-1 = last sheet). If the sheet cannot be found, qsv will read the first sheet. | `0` |
| &nbsp;`‑‑header‑row`&nbsp; | integer | The header row. Set if other than the first non-empty row of the sheet. |  |
| &nbsp;`‑‑metadata`&nbsp; | string | Outputs workbook metadata in CSV or JSON format: index, sheet_name, type, visible, headers, column_count, row_count, safe_headers, safe_headers_count, unsafe_headers, unsafe_headers_count and duplicate_headers_count, names, name_count, tables, table_count. headers is a list of the first row which is presumed to be the header row. type is the sheet type (WorkSheet, DialogSheet, MacroSheet, ChartSheet, Vba). visible is the sheet visibility (Visible, Hidden, VeryHidden). row_count includes all rows, including the first row. safe_headers is a list of headers with "safe"(PostgreSQL-ready) names. unsafe_headers is a list of headers with "unsafe" names. duplicate_headers_count is a count of duplicate header names. names is a list of defined names in the workbook, with the associated formula. name_count is the number of defined names in the workbook. tables is a list of tables in the workbook, along with the sheet where the table is found, the columns and the column_count.  (XLSX only) table_count is the number of tables in the workbook.  (XLSX only) | `none` |
| &nbsp;`‑‑table`&nbsp; | string | An Excel table (case-insensitive) to extract to a CSV. Only valid for XLSX files. The --sheet option is ignored as a table could be in any sheet. Overrides --range option. |  |
| &nbsp;`‑‑range`&nbsp; | string | An Excel format range - like RangeName, C:T, C3:T25 or 'Sheet1!C3:T25' to extract to the CSV. If the specified range contains the required sheet, the --sheet option is ignored. If the range is not found, qsv will exit with an error. |  |
| &nbsp;`‑‑cell`&nbsp; | string | A single cell reference - like C3 or 'Sheet1!C3' to extract. This is a convenience option equivalent to --range C3:C3. If both --cell and --range are specified, --cell takes precedence. |  |
| &nbsp;`‑‑error‑format`&nbsp; | string | The format to use when formatting error cells. There are 3 formats:<ul><li>"code": return the error code. (#DIV/0!; #N/A; #NAME?; #NULL!; #NUM!; #REF!; #VALUE!; #DATA!)</li><li>"formula": return the formula, prefixed with '#'. (e.g. #=A1/B1 where B1 is 0; #=100/0)</li><li>"both": return both error code and the formula. (e.g. #DIV/0!: =A1/B1)</li></ul> | `code` |
| &nbsp;`‑‑flexible`&nbsp; | flag | Continue even if the number of columns is different from row to row. |  |
| &nbsp;`‑‑trim`&nbsp; | flag | Trim all fields so that leading & trailing whitespaces are removed. Also removes embedded linebreaks. |  |
| &nbsp;`‑‑date‑format`&nbsp; | string | Optional date format to use when formatting dates. See <https://docs.rs/chrono/latest/chrono/format/strftime/index.html> for the full list of supported format specifiers. Note that if a date format is invalid, qsv will fall back and return the date as if no date-format was specified. |  |
| &nbsp;`‑‑keep‑zero‑time`&nbsp; | flag | Keep the time part of a date-time field if it is 00:00:00. By default, qsv will remove the time part if it is 00:00:00. |  |
| &nbsp;`‑j,`<br>`‑‑jobs`&nbsp; | integer | The number of jobs to run in parallel. When not set, the number of jobs is set to the number of CPUs detected. |  |

<a name="common-options"></a>

## Common Options [↩](#nav)

| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Option&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Type | Description | Default |
|--------|------|-------------|--------|
| &nbsp;`‑h,`<br>`‑‑help`&nbsp; | flag | Display this message |  |
| &nbsp;`‑o,`<br>`‑‑output`&nbsp; | string | Write output to <file> instead of stdout. |  |
| &nbsp;`‑d,`<br>`‑‑delimiter`&nbsp; | string | The delimiter to use when writing CSV data. Must be a single character. | `,` |
| &nbsp;`‑q,`<br>`‑‑quiet`&nbsp; | flag | Do not display export summary message. |  |

---
**Source:** [`src/cmd/excel.rs`](https://github.com/dathere/qsv/blob/master/src/cmd/excel.rs)
| **[Table of Contents](TableOfContents.md)** | **[README](../../README.md)**
