> ## Documentation Index
> Fetch the complete documentation index at: https://docs.retab.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Reconstruct Split

> Reconstruct each named subdocument of a stored spreadsheet into an enriched, partition-ready table: one flat complete header, the key carried on every row, section banners promoted to a column, and wide size-matrices melted. Returns the enriched tables (header + rows + clean CSV) for hand-off to extraction.

Reconstruct each named subdocument of a stored spreadsheet into an enriched, partition-ready table: one flat complete header, the key carried on every row, section banners promoted to a column, and wide size-matrices melted. Returns the enriched tables (header + rows + clean CSV) for hand-off to extraction.

<RequestExample>
  ```python Python theme={null}
  from retab import Retab

  client = Retab()

  result = client.splits.create_reconstruct(
      document={
          "id": "doc_01G34H8J2K",
          "filename": "orders_workbook.xlsx",
          "mime_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
      },
      subdocuments=[
          {
              "name": "orders",
              "regions": [
                  {
                      "sheet_name": "Orders",
                      "sheet_index": 0,
                      "row_start": 2,
                      "row_end": 148,
                      "header_rows": [1],
                  }
              ],
              "partition_key": "order_number",
          }
      ],
  )

  for table in result.tables:
      print(f"{table.label}: {len(table.rows)} rows")
  ```

  ```typescript TypeScript theme={null}
  import { Retab } from "@retab/node";

  const client = new Retab({ apiKey: process.env.RETAB_API_KEY });

  const result = await client.splits.create_reconstruct(
    {
      id: "doc_01G34H8J2K",
      filename: "orders_workbook.xlsx",
      mime_type:
        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    },
    [
      {
        name: "orders",
        regions: [
          {
            sheet_name: "Orders",
            sheet_index: 0,
            row_start: 2,
            row_end: 148,
            header_rows: [1],
          },
        ],
        partition_key: "order_number",
      },
    ],
  );

  result.tables.forEach((table) => {
    console.log(`${table.label}: ${table.rows.length} rows`);
  });
  ```

  ```go Go theme={null}
  package main

  import (
  	"context"
  	"fmt"
  	"log"

  	retab "github.com/retab-dev/retab/clients/go"
  )

  func ptr[T any](v T) *T { return &v }

  func main() {
  	client, err := retab.NewClient("")
  	if err != nil {
  		log.Fatal(err)
  	}

  	result, err := client.Splits.CreateReconstruct(context.Background(), &retab.SplitsCreateReconstructParams{
  		Document: retab.ReconstructDocumentRef{
  			ID:       "doc_01G34H8J2K",
  			Filename: "orders_workbook.xlsx",
  			MIMEType: ptr("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
  		},
  		Subdocuments: []*retab.ReconstructSubdocument{
  			{
  				Name: "orders",
  				Regions: []*retab.SheetRegion{
  					{
  						SheetName:  "Orders",
  						SheetIndex: 0,
  						RowStart:   2,
  						RowEnd:     148,
  						HeaderRows: []int{1},
  					},
  				},
  				PartitionKey: ptr("order_number"),
  			},
  		},
  	})
  	if err != nil {
  		log.Fatal(err)
  	}

  	for _, table := range result.Tables {
  		fmt.Printf("%s: %d rows\n", table.Label, len(table.Rows))
  	}
  }
  ```

  ```java Java theme={null}
  import com.retab.RetabClient;
  import com.retab.models.ReconstructDocumentRef;
  import com.retab.models.ReconstructRequest;
  import com.retab.models.ReconstructSubdocument;
  import com.retab.models.SheetRegion;
  import java.util.List;

  public final class Example {
    public static void main(String[] args) throws Exception {
      RetabClient client = new RetabClient(System.getenv("RETAB_API_KEY"));

      var document =
          new ReconstructDocumentRef(
              "orders_workbook.xlsx",
              "doc_01G34H8J2K",
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
      var region = new SheetRegion(null, null, List.of(1L), 148L, 2L, 0L, "Orders");
      var subdocument =
          new ReconstructSubdocument(null, "orders", "order_number", List.of(region));

      var result =
          client.splits().createReconstruct(new ReconstructRequest(document, List.of(subdocument)));
      result.getTables().forEach(t -> System.out.println(t.getLabel()));
    }
  }
  ```

  ```ruby Ruby theme={null}
  require 'retab'

  client = Retab::Client.new(api_key: ENV['RETAB_API_KEY'])

  result = client.splits.create_reconstruct(
    document: {
      id: 'doc_01G34H8J2K',
      filename: 'orders_workbook.xlsx',
      mime_type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    },
    subdocuments: [
      {
        name: 'orders',
        regions: [
          {
            sheet_name: 'Orders',
            sheet_index: 0,
            row_start: 2,
            row_end: 148,
            header_rows: [1]
          }
        ],
        partition_key: 'order_number'
      }
    ]
  )

  result.tables.each { |table| puts table.label }
  ```

  ```rust Rust theme={null}
  use retab::Retab;

  #[tokio::main]
  async fn main() -> Result<(), Box<dyn std::error::Error>> {
      let client = Retab::new(std::env::var("RETAB_API_KEY")?);

      let result = client
          .splits()
          .create_reconstruct(retab::resources::splits::CreateReconstructParams {
              document: retab::resources::splits::ReconstructDocumentRef {
                  id: "doc_01G34H8J2K".into(),
                  filename: "orders_workbook.xlsx".into(),
                  mime_type: Some(
                      "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".into(),
                  ),
              },
              subdocuments: vec![retab::resources::splits::ReconstructSubdocument {
                  name: "orders".into(),
                  regions: vec![retab::resources::splits::SheetRegion {
                      sheet_name: "Orders".into(),
                      sheet_index: 0,
                      row_start: 2,
                      row_end: 148,
                      col_start: None,
                      col_end: None,
                      header_rows: Some(vec![1]),
                  }],
                  partition_key: Some("order_number".into()),
                  enrichment: None,
              }],
          })
          .await?;

      for table in result.tables {
          println!("{}", table.label);
      }
      Ok(())
  }
  ```

  ```php PHP theme={null}
  <?php
  require 'vendor/autoload.php';

  use Retab\Client;

  $client = new Client(apiKey: getenv('RETAB_API_KEY'));

  $result = $client->splits()->createReconstruct(
      document: [
          'id' => 'doc_01G34H8J2K',
          'filename' => 'orders_workbook.xlsx',
          'mime_type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      ],
      subdocuments: [
          [
              'name' => 'orders',
              'regions' => [
                  [
                      'sheet_name' => 'Orders',
                      'sheet_index' => 0,
                      'row_start' => 2,
                      'row_end' => 148,
                      'header_rows' => [1],
                  ],
              ],
              'partition_key' => 'order_number',
          ],
      ],
  );

  foreach ($result->tables as $table) {
      echo $table->label . PHP_EOL;
  }
  ```

  ```csharp C# theme={null}
  using System.Collections.Generic;
  using Retab;
  using Retab.Models;
  using RetabClient = Retab.Retab;

  var apiKey = Environment.GetEnvironmentVariable("RETAB_API_KEY")!;
  var client = new RetabClient(apiKey);

  var document = new ReconstructDocumentRef(
      filename: "orders_workbook.xlsx",
      id: "doc_01G34H8J2K",
      mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
  var region = new SheetRegion(
      colEnd: null, colStart: null, headerRows: new List<long> { 1 },
      rowEnd: 148, rowStart: 2, sheetIndex: 0, sheetName: "Orders");
  var subdocument = new ReconstructSubdocument(
      enrichment: null, name: "orders", partitionKey: "order_number",
      regions: new List<SheetRegion> { region });

  var result = await client.Splits.CreateReconstructAsync(
      new ReconstructRequest(document, new List<ReconstructSubdocument> { subdocument }));
  foreach (var table in result.Tables)
  {
      Console.WriteLine(table.Label);
  }
  ```

  ```curl cURL theme={null}
  curl -X POST \
    'https://api.retab.com/v1/splits/reconstruct' \
    -H "Authorization: Bearer $RETAB_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "document": {
        "id": "doc_01G34H8J2K",
        "filename": "orders_workbook.xlsx",
        "mime_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
      },
      "subdocuments": [
        {
          "name": "orders",
          "regions": [
            {
              "sheet_name": "Orders",
              "sheet_index": 0,
              "row_start": 2,
              "row_end": 148,
              "header_rows": [1]
            }
          ],
          "partition_key": "order_number"
        }
      ]
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "tables": [
      {
        "label": "orders",
        "header": ["order_number", "sku", "quantity", "unit_price"],
        "rows": [
          { "cells": ["SO-1001", "WIDGET-A", "12", "4.50"] },
          { "cells": ["SO-1001", "WIDGET-B", "3", "17.00"] }
        ],
        "csv": "order_number,sku,quantity,unit_price\nSO-1001,WIDGET-A,12,4.50\nSO-1001,WIDGET-B,3,17.00\n"
      }
    ]
  }
  ```

  ```json 404 theme={null}
  {
    "detail": "document 'doc_01G34H8J2K' not found"
  }
  ```
</ResponseExample>


## OpenAPI

````yaml POST /v1/splits/reconstruct
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.retab.com
security: []
paths:
  /v1/splits/reconstruct:
    post:
      tags:
        - Splits
      summary: Reconstruct Split
      description: >-
        Reconstruct each named subdocument of a stored spreadsheet into an
        enriched, partition-ready table: one flat complete header, the key
        carried on every row, section banners promoted to a column, and wide
        size-matrices melted. Returns the enriched tables (header + rows + clean
        CSV) for hand-off to extraction.
      operationId: reconstruct_split
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReconstructRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReconstructResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    ReconstructRequest:
      properties:
        document:
          $ref: '#/components/schemas/ReconstructDocumentRef'
        subdocuments:
          items:
            $ref: '#/components/schemas/ReconstructSubdocument'
          type: array
          title: Subdocuments
      type: object
      required:
        - document
        - subdocuments
      title: ReconstructRequest
    ReconstructResponse:
      properties:
        tables:
          items:
            $ref: '#/components/schemas/ReconstructEnrichedTable'
          type: array
          title: Tables
      type: object
      required:
        - tables
      title: ReconstructResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
          default: []
      type: object
      title: HTTPValidationError
    ReconstructDocumentRef:
      properties:
        filename:
          type: string
          title: Filename
        id:
          type: string
          title: Id
        mime_type:
          type: string
          title: Mime Type
      type: object
      required:
        - filename
        - id
      title: ReconstructDocumentRef
    ReconstructSubdocument:
      properties:
        enrichment:
          $ref: '#/components/schemas/ReconstructEnrichmentOptions'
        name:
          type: string
          title: Name
        partition_key:
          anyOf:
            - type: string
            - type: 'null'
          title: Partition Key
        regions:
          items:
            $ref: '#/components/schemas/SheetRegion'
          type: array
          title: Regions
      type: object
      required:
        - name
        - regions
      title: ReconstructSubdocument
    ReconstructEnrichedTable:
      properties:
        csv:
          type: string
          title: Csv
        header:
          items:
            type: string
          type: array
          title: Header
        label:
          type: string
          title: Label
        rows:
          items:
            $ref: '#/components/schemas/ReconstructEnrichedRow'
          type: array
          title: Rows
      type: object
      required:
        - csv
        - header
        - label
        - rows
      title: ReconstructEnrichedTable
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
          default: null
        ctx:
          type: object
          title: Context
          default: {}
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    ReconstructEnrichmentOptions:
      properties:
        fill_key_spans:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Fill Key Spans
        flatten_header:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Flatten Header
        promote_sections:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Promote Sections
      type: object
      title: ReconstructEnrichmentOptions
    SheetRegion:
      properties:
        col_end:
          anyOf:
            - type: integer
            - type: 'null'
          title: Col End
        col_start:
          anyOf:
            - type: integer
            - type: 'null'
          title: Col Start
        header_rows:
          items:
            type: integer
          type: array
          title: Header Rows
          default: []
        row_end:
          type: integer
          title: Row End
        row_start:
          type: integer
          title: Row Start
        sheet_index:
          type: integer
          title: Sheet Index
        sheet_name:
          type: string
          title: Sheet Name
      type: object
      required:
        - row_end
        - row_start
        - sheet_index
        - sheet_name
      title: SheetRegion
    ReconstructEnrichedRow:
      properties:
        cells:
          items:
            type: string
          type: array
          title: Cells
      type: object
      required:
        - cells
      title: ReconstructEnrichedRow
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````