iOfficeAI/OfficeCLI · error · CliException

unsupported_type

unsupported_type

Error message

HTML preview is only supported for .pptx, .xlsx, and .docx files.

What it means

HTML preview mode renders a document to HTML. It only works when the document's handler can produce HTML — PptxHandler, ExcelHandler, WordHandler, or a FormatHandlerProxy. This fires when the handler returned null HTML, i.e. the file format has no HTML renderer.

Source

Thrown at src/officecli/CommandBuilder.View.cs:199

                        if (browser)
                        {
                            try
                            {
                                var psi = new System.Diagnostics.ProcessStartInfo(htmlPath) { UseShellExecute = true };
                                System.Diagnostics.Process.Start(psi);
                            }
                            catch { /* silently ignore if browser can't be opened */ }
                        }
                    }
                    else
                    {
                        // Default: output HTML to stdout
                        Console.Write(html);
                    }
                }
                else
                {
                    throw new OfficeCli.Core.CliException("HTML preview is only supported for .pptx, .xlsx, and .docx files.")
                    {
                        Code = "unsupported_type",
                        Suggestion = "Use a .pptx, .xlsx, or .docx file, or use mode 'text' or 'annotated' for other formats.",
                        ValidValues = ["text", "annotated", "outline", "stats", "issues"]
                    };
                }
                return 0;
            }

            if (mode.ToLowerInvariant() is "screenshot" or "p")
            {
                // Screenshot mode: render the same HTML preview as `view html`, then
                // headless-screenshot the temp HTML to a PNG. Mirrors svg's pattern of
                // a dedicated mode that produces a file + prints the path.
                // --grid N tiles slides into an N-column thumbnail grid (pptx only).
                //
                // CONSISTENCY(screenshot-default-first-page): screenshot mode defaults
                // to a single bounded visual unit (pptx → slide 1, docx → page 1, xlsx

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Use a .pptx, .xlsx, or .docx file for html preview.
  2. For other formats, use mode text, annotated, outline, stats, or issues.

Example fix

// before
officecli view data.csv html
// after
officecli view data.docx html
# or for non-renderable formats:
officecli view data.csv text
Defensive patterns

Strategy: validation

Validate before calling

static readonly HashSet<string> HtmlCapable = new() { ".pptx", ".xlsx", ".docx" };
if (mode == "html" && !HtmlCapable.Contains(Path.GetExtension(file).ToLowerInvariant()))
    throw new ArgumentException("html preview needs .pptx/.xlsx/.docx; use 'text' otherwise.");

Type guard

static bool SupportsHtmlPreview(string f) =>
    Path.GetExtension(f).ToLowerInvariant() is ".pptx" or ".xlsx" or ".docx";

Prevention

When it happens

Trigger: 'officecli view <unsupported-format> html' where the format's handler cannot emit HTML (e.g. an exotic/foreign format loaded via a non-html-capable handler).

Common situations: Pointing 'view html' at a format officecli can read but not render to HTML; assuming html works for every supported format.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/bb9555604ae8f826. Report an issue: GitHub.