excel-to-sql

Export Command

Export data from SQLite to Excel

Usage

Export data from your SQLite database back to Excel files. You can export entire tables or run custom SQL queries to create filtered reports.

excel-to-sql export --table TABLE --output FILE

Options

Choose between exporting an entire table or running a custom SQL query. The output path is always required.

--table TEXT      Export entire table
--query TEXT      Custom SQL query
--output, -o TEXT  Output Excel file path (required)

Examples

Export Entire Table

Export all rows and columns from a table to an Excel file.

excel-to-sql export --table products --output products_export.xlsx

Export Query Results

Run a SQL query and export only the filtered results.

excel-to-sql export --query "SELECT * FROM products WHERE price > 100" --output expensive_products.xlsx

Export with Full Path

Specify an absolute path to save the file in a specific directory.

excel-to-sql export --table customers --output /path/to/export/customers.xlsx

Export Complex Query

Join multiple tables and export a consolidated report with specific columns.

excel-to-sql export --query "
  SELECT
    p.name,
    c.name as customer,
    o.order_date
  FROM orders o
  JOIN products p ON o.product_id = p.id
  JOIN customers c ON o.customer_id = c.id
  WHERE o.order_date >= '2025-01-01'
" --output recent_orders.xlsx

Output Location

You can specify relative or absolute paths. Relative paths are resolved from your current working directory.

Files are saved to the specified path. Common locations:

# Export to exports directory
excel-to-sql export --table products --output exports/products.xlsx

# Export to custom location
excel-to-sql export --table products --output /path/to/reports/products.xlsx

Multi-Sheet Export (Python SDK)

The CLI only exports single-sheet files. For multi-sheet workbooks, use the Python SDK which can create multiple sheets in one file.

For multi-sheet export, use the Python SDK:

from excel_to_sql import ExcelToSqlite

sdk = ExcelToSqlite()
sdk.export_to_excel(
    output="report.xlsx",
    sheet_mapping={
        "Products": "products",
        "Customers": "customers",
        "Orders": "SELECT * FROM orders WHERE status = 'complete'"
    }
)

Output Format

Exported files use standard Excel format with proper encoding and type preservation.

  • Format: Excel (.xlsx)
  • Encoding: UTF-8
  • Dates: ISO 8601 format (YYYY-MM-DD HH:MM:SS)
  • Numbers: Preserved as-is from database

Large Exports

For very large datasets, consider limiting results with SQL queries to improve performance and avoid memory issues.

For large datasets:

# Export query with LIMIT
excel-to-sql export --query "SELECT * FROM large_table LIMIT 10000" --output sample.xlsx

Common Use Cases

Backup Data

Create timestamped backups of your data for safekeeping and disaster recovery.

excel-to-sql export --table products --output backups/products_$(date +%Y%m%d).xlsx

Generate Reports

Create analytical reports by aggregating and summarizing data with SQL queries.

excel-to-sql export --query "
  SELECT
    category,
    COUNT(*) as count,
    AVG(price) as avg_price
  FROM products
  GROUP BY category
" --output category_report.xlsx

Share with Stakeholders

Export data in Excel format for easy sharing with business users who prefer spreadsheets over databases.

excel-to-sql export --table inventory --output reports/inventory_snapshot.xlsx

See Also

On this page