# How to Use the Import Command for CSV/TSV Data into Excel Sheets in OfficeCLI

> Easily import CSV TSV data into Excel sheets with OfficeCLI. Use the import command with file or stdin options for seamless data integration.

- Repository: [OfficeAI/OfficeCLI](https://github.com/iofficeai/OfficeCLI)
- Tags: how-to-guide
- Published: 2026-08-03

---

**To import CSV or TSV data into an Excel sheet using OfficeCLI, run `officecli import` with `--file` and optionally `--header` for frozen header rows and autofilters, or `--stdin` for piped data.**

The `import` command is the fastest way to populate Excel workbooks with structured data. This guide covers the complete workflow from source preparation to post-import formatting, based on the official OfficeCLI implementation.

## Prerequisites: Create the Target Workbook and Sheet

Before importing, ensure your workbook and destination sheet exist. Use the `add` command with `--type sheet` to create a named worksheet.

```bash

# Create a new workbook

officecli create budget.xlsx

# Add a sheet to receive the data

officecli add budget.xlsx / --type sheet --prop name="Q1 Data"

```

According to the README at lines 92-95, this pattern—create workbook, add sheet, then import—is the documented standard workflow.

## Import CSV Data into an Excel Sheet

For standard comma-separated files, the `import` command requires the workbook path, sheet path, and source file. The `--header` flag treats the first row as column names and applies an **autofilter** plus **freeze-pane** automatically.

```bash
officecli import budget.xlsx "/Q1 Data" --file sales.csv --header

```

The CLI parses the file in a single pass, infers data types (numbers, dates, strings), and writes values while preserving row order. This avoids the performance penalty of individual `set` calls per cell.

## Import TSV Data with the Correct Format Flag

Tab-separated values require explicit format specification. Use `--format tsv` to ensure proper delimiter handling.

```bash
officecli import budget.xlsx "/Q1 Data" --file sales.tsv --format tsv --header

```

The `--format` flag accepts `csv` (default) or `tsv` as documented in the XLSX skill file at lines 152-159.

## Import from Stdin and Control Start Position

For dynamically generated data, pipe through stdin and optionally specify a starting cell with `--start-cell`.

```bash

# Pipe data from another process

cat sales.csv | officecli import budget.xlsx "/Q1 Data" --stdin --start-cell B2

```

This streams data starting at cell **B2**, skipping row 1 and column A. Useful when prepending summary rows or aligning with existing template structures.

## Post-Import Formatting and Cleanup

Raw imports may need column width adjustment and number formatting. Apply these with targeted `set` commands.

```bash

# Auto-size columns (manual width specification)

officecli set budget.xlsx "/Q1 Data/col[A]" --prop width=20
officecli set budget.xlsx "/Q1 Data/col[B]" --prop width=15

# Apply currency format to numeric column

officecli set budget.xlsx "/Q1 Data/col[B]" --prop numFmt='$#,##0'

```

These adjustments are optional but recommended for presentation-ready spreadsheets.

## Why Use `import` Instead of Manual `set` Loops

| Approach | Drawback |
|----------|----------|
| Manual `set` loops | One API call per cell; prohibitively slow for large datasets |
| Raw paste | Loses type information; everything becomes strings |

The `import` command solves both problems through **single-pass parsing**, **automatic type inference**, and **native delimiter handling**. The header automation alone eliminates multiple follow-up commands.

## Summary

- **Create target structure first**: Use `add --type sheet` to prepare the destination worksheet.
- **Use `officecli import` with `--file`**: Point to CSV/TSV and specify `--header` for frozen headers and autofilters.
- **Specify `--format tsv`** for tab-delimited data instead of the default CSV.
- **Pipe via `--stdin`** for streaming data and use `--start-cell` to control placement.
- **Post-process with `set`**: Adjust column widths and number formats after import completes.

## Frequently Asked Questions

### Can I import multiple CSV files into the same sheet?

Yes, run `import` multiple times with different `--start-cell` values to place each dataset at specific locations. No automatic merge exists—you must specify non-overlapping ranges.

### Does OfficeCLI preserve date formats from the source file?

OfficeCLI infers dates from source strings but applies standard Excel date serialization. For custom formatting, use `set --prop numFmt=` on the relevant column after import.

### What happens if I don't use `--header`?

The first row imports as regular data with no autofilter or freeze-pane. Use this flag only when your source truly contains headers to avoid misaligned formatting.

### Is there a row or column limit for imported data?

The `import` command streams data and is constrained by Excel's native limits (1,048,576 rows by 16,384 columns in XLSX format). Memory usage scales with file size due to single-pass parsing.