iOfficeAI/OfficeCLI · error · CliException
invalid_value
invalid_value
Error message
Unknown format: {format}. Use 'csv' or 'tsv' What it means
The --format flag only accepts 'csv' (comma) or 'tsv' (tab). Any other value (e.g. 'json', 'xlsx') is rejected here with the valid set surfaced via ValidValues.
Source
Thrown at src/officecli/CommandBuilder.Import.cs:98
}
else
{
throw new CliException("Either --file or --stdin must be specified")
{
Code = "missing_argument",
Suggestion = "Use --file <path> to specify a CSV/TSV file, or --stdin to read from standard input"
};
}
// Determine delimiter: --format flag > file extension > default csv
char delimiter = ',';
if (!string.IsNullOrEmpty(format))
{
delimiter = format.ToLowerInvariant() switch
{
"tsv" => '\t',
"csv" => ',',
_ => throw new CliException($"Unknown format: {format}. Use 'csv' or 'tsv'")
{
Code = "invalid_value",
ValidValues = ["csv", "tsv"]
}
};
}
else if (source != null)
{
var sourceExt = Path.GetExtension(source.FullName).ToLowerInvariant();
if (sourceExt == ".tsv" || sourceExt == ".tab")
delimiter = '\t';
}
// Release any running resident's file lock before direct-open (import bypasses resident)
ResidentClient.SendClose(file.FullName);
using var handler = new OfficeCli.Handlers.ExcelHandler(file.FullName, editable: true);
var msg = handler.Import(parentPath, csvContent, delimiter, header, startCell);
if (json)View on GitHub (pinned to 1ced45e900)
Solutions
- Use --format csv or --format tsv.
- If omitted, format is inferred from the source extension (.tsv/.tab -> tab, else comma).
Example fix
// before officecli import out.xlsx --file data.csv --format json // after officecli import out.xlsx --file data.csv --format csv
Defensive patterns
Strategy: validation
Validate before calling
static readonly HashSet<string> ImportFormats = new(StringComparer.OrdinalIgnoreCase) { "csv", "tsv" };
if (format is not null && !ImportFormats.Contains(format))
throw new ArgumentException($"--format must be csv or tsv, got '{format}'."); Type guard
static bool IsValidImportFormat(string? f) =>
f is null || f.Equals("csv", StringComparison.OrdinalIgnoreCase)
|| f.Equals("tsv", StringComparison.OrdinalIgnoreCase); Prevention
- --format names the delimiter, not the data schema.
- Let the source extension infer when unsure (.tsv/.tab -> tab).
When it happens
Trigger: 'officecli import out.xlsx --file data.csv --format json' or any --format value outside {csv, tsv}.
Common situations: Confusing the source file format with the target workbook format; passing the data's logical type instead of the delimiter name.
Related errors
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/0d195906b2554e77.
Report an issue: GitHub.