How to Create a New Excel Document with OfficeCLI: A Complete Guide
Run officecli create filename.xlsx to generate a blank .xlsx workbook with a default Sheet1 in seconds, no Microsoft Office installation required.
OfficeCLI is an open-source command-line tool that manipulates Microsoft Office documents without requiring the desktop suite. Whether you are automating reports on Linux servers or generating templates on macOS, you can create new Excel documents programmatically using simple terminal commands. This guide walks through the exact command syntax and the underlying implementation in the iOfficeAI/OfficeCLI repository.
Installation and Prerequisites
OfficeCLI distributes as a self-contained binary that works across Linux, macOS, and Windows. You do not need a local Microsoft Office installation to generate or edit files.
Installing the OfficeCLI Binary
Fetch and execute the official install script to place the officecli command on your $PATH:
curl -fsSL https://raw.githubusercontent.com/iOfficeAI/OfficeCLI/main/install.sh | bash
After installation, verify the binary is accessible:
officecli --version
Creating an Excel Workbook with the create Command
The create verb instantiates a new file with a minimal valid Office Open XML structure. You only need to specify the target filename with the correct extension.
Basic Syntax and File Extension Detection
Execute the following pattern to generate your workbook:
officecli create report.xlsx
In CommandBuilder.cs, the parser inspects the file extension to route the request. When it detects .xlsx, it delegates execution to the Excel handler defined in ExcelHandler.cs.
What Happens Under the Hood
Inside ExcelHandler.cs, the handler constructs a new package using DocumentFormat.OpenXml. It writes a bare-minimum workbook containing one worksheet named Sheet1 and persists the stream to disk. This implementation relies purely on the Open XML SDK, ensuring the output file is fully compatible with Excel, Google Sheets, and LibreOffice Calc.
The entire operation completes without registry lookups or COM objects, making it suitable for CI/CD pipelines and containerized environments.
Verifying and Populating Your New Workbook
Once created, you can inspect and modify the workbook through additional OfficeCLI commands.
Inspecting Workbook Structure
Confirm the file was created with the default sheet using the view command:
officecli view report.xlsx outline
Expected output:
→ Sheet1
This validates that the internal XML parts were written correctly by ExcelHandler.cs.
Adding Data to Cells
Populate the blank workbook using the set verb. The following sequence creates a basic header row:
officecli set report.xlsx /Sheet1/A1 --prop value="Month" --prop bold=true
officecli set report.xlsx /Sheet1/B1 --prop value="Revenue" --prop bold=true
officecli set report.xlsx /Sheet1/A2 --prop value="Jan"
officecli set report.xlsx /Sheet1/B2 --prop value=42000 --prop numFmt='$#,##0'
Each set invocation targets a specific cell address and accepts properties for value, styling, and number formatting.
Cross-Platform Compatibility
Because OfficeCLI uses the .NET-based Open XML SDK rather than Office Interop, the create command runs identically on Ubuntu, macOS, and Windows. The resulting .xlsx file conforms to the ISO/IEC 29500 standard, ensuring interoperability across spreadsheet applications.
Summary
- Run
officecli create <filename.xlsx>to generate a blank workbook instantly via the terminal. - The command routes through
CommandBuilder.csand executes inExcelHandler.csusing DocumentFormat.OpenXml. - The default output contains a single worksheet named Sheet1.
- No Microsoft Office installation is required on Linux, macOS, or Windows.
- Use
officecli viewto inspect structure andofficecli setto populate cells immediately after creation.
Frequently Asked Questions
Do I need Microsoft Office installed to use OfficeCLI?
No. OfficeCLI relies entirely on the open-source DocumentFormat.OpenXml library to construct Excel packages. The tool operates independently of the Microsoft Office desktop suite and functions in headless environments such as Docker containers and remote servers.
What is the default sheet name when creating a new Excel file?
OfficeCLI creates a single worksheet named Sheet1 by default. This behavior is hardcoded in ExcelHandler.cs to provide immediate usability while maintaining a minimal file footprint.
Can I create Excel files with specific formatting during the create command?
The create command generates a blank, unformatted workbook. To apply formatting, run subsequent officecli set commands targeting specific cells with flags like --prop bold=true or --prop numFmt='$#,##0'. Advanced templates should be built by chaining set operations or modifying an existing template file.
How does OfficeCLI handle file extension resolution?
In CommandBuilder.cs, the argument parser inspects the extension of the filename provided to the create verb. It maps .xlsx to ExcelHandler.cs, .docx to WordHandler.cs, and .pptx to PowerPointHandler.cs. Providing an unsupported extension results in an error before any file write occurs.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →