csv2excel/docs/architecture.md

26 lines
1.2 KiB
Markdown
Raw Permalink Normal View History

# Architecture
## Overview
Single-file tool — entire application logic lives in `main.go`.
- **`main()`**: Parses flags (`-sep`, `-enc`, `-o`), iterates over input CSV files, creates one Excel sheet per file using the filename (without extension) as the sheet name, writes all rows, saves the output `.xlsx`.
- **`detectDelimiter()`**: Auto-detects the CSV delimiter by counting `;`, `,`, and `\t` occurrences in the first line. Falls back to `;` on error.
Key behaviors:
- Sheet names are truncated to 31 characters (Excel limit)
- Encoding `windows1252` wraps the file reader with a Windows-1252 decoder
- `csvReader.LazyQuotes = true` for tolerance with malformed CSV files
- The first sheet renames "Sheet1"; subsequent sheets are created fresh
## Version Injection
Version info is injected at build time via ldflags from git tags:
- `internal/version.Version` — from `git describe --tags --always`
- `internal/version.Commit` — from `git rev-parse --short HEAD`
- `internal/version.BuildDate` — from `date -u`
## Dependencies
- `github.com/xuri/excelize/v2` — Excel file creation/manipulation
- `golang.org/x/text` — Character encoding (Windows-1252 support)