Skip to main content

Overview

The Excel API uses consistent data models for spreadsheet generation, template population, and data extraction. All operations follow an asynchronous job-based workflow with intelligent layout resolution.

ExcelJobRequest

Request schema for creating Excel generation jobs.
interface ExcelJobRequest {
  operation: "create_spreadsheet" | "populate_template" | "extract_data";
  workbook_name?: string;
  sheets?: SheetDefinition[];
  template_file?: string;      // Base64-encoded .xlsx template
  data_mappings?: Record<string, any>;
}

SheetDefinition

Definition for a single worksheet.
interface SheetDefinition {
  name: string;
  blocks: ContentBlock[];
}

ContentBlock

Logical content blocks for building spreadsheets.
type ContentBlock = HeaderBlock | DataTableBlock | FormulaBlock | ChartBlock;

HeaderBlock

interface HeaderBlock {
  type: "header";
  content: string;
  style?: "title" | "heading" | "normal";
}
Example:
{
  "type": "header",
  "content": "Project Summary Report",
  "style": "title"
}

DataTableBlock

interface DataTableBlock {
  type: "data_table";
  name?: string;               // Named reference for formulas
  headers: string[];
  rows: any[][];
  formatting?: TableFormatting;
}
Example:
{
  "type": "data_table",
  "name": "QUANTITIES",
  "headers": ["Item", "Quantity", "Unit Price", "Total"],
  "rows": [
    ["Concrete", 100, 150, "=B2*C2"],
    ["Rebar", 5000, 1.2, "=B3*C3"]
  ],
  "formatting": {
    "header_bold": true,
    "zebra_stripes": true
  }
}

FormulaBlock

interface FormulaBlock {
  type: "formula";
  label: string;
  expression: string;          // Excel formula with named references
  format?: "currency" | "number" | "percentage";
}
Example:
{
  "type": "formula",
  "label": "Grand Total",
  "expression": "=SUM(QUANTITIES[Total])",
  "format": "currency"
}

ChartBlock

interface ChartBlock {
  type: "chart";
  chart_type: "bar" | "line" | "pie" | "scatter";
  title: string;
  data_range: string;          // Named table reference
  x_axis?: string;
  y_axis?: string;
}
Example:
{
  "type": "chart",
  "chart_type": "bar",
  "title": "Cost Breakdown",
  "data_range": "QUANTITIES",
  "x_axis": "Item",
  "y_axis": "Total"
}

ExcelJobResponse

Response when a spreadsheet generation job completes.
interface ExcelJobResponse {
  job_id: string;
  status: "completed";
  created_at: string;
  completed_at: string;
  results: {
    file_url: string;
    file_type: "xlsx";
    expires_at: string;
  }
}
Example:
{
  "job_id": "job_xls_abc123",
  "status": "completed",
  "created_at": "2025-10-17T10:30:00Z",
  "completed_at": "2025-10-17T10:30:08.123Z",
  "results": {
    "file_url": "https://storage.stru.ai/temp/summary.xlsx?signature=...",
    "file_type": "xlsx",
    "expires_at": "2025-10-18T10:30:08.123Z"
  }
}

Complete Example

{
  "operation": "create_spreadsheet",
  "workbook_name": "Project Cost Summary",
  "sheets": [
    {
      "name": "Materials",
      "blocks": [
        {
          "type": "header",
          "content": "Material Quantities and Costs",
          "style": "title"
        },
        {
          "type": "data_table",
          "name": "MATERIALS",
          "headers": ["Material", "Quantity", "Unit", "Unit Price", "Total Cost"],
          "rows": [
            ["Concrete", 150, "CY", 175, "=B2*D2"],
            ["Rebar #5", 8000, "LF", 1.25, "=B3*D3"],
            ["Formwork", 2500, "SF", 8.5, "=B4*D4"]
          ],
          "formatting": {
            "header_bold": true,
            "zebra_stripes": true
          }
        },
        {
          "type": "formula",
          "label": "Total Material Cost",
          "expression": "=SUM(MATERIALS[Total Cost])",
          "format": "currency"
        },
        {
          "type": "chart",
          "chart_type": "pie",
          "title": "Cost Distribution",
          "data_range": "MATERIALS",
          "x_axis": "Material",
          "y_axis": "Total Cost"
        }
      ]
    }
  ]
}