---
title: "reconstruct_original"
---

[< Back to Reference](../reference.qmd) | [View source](https://codeberg.org/usrbinr/tidychain/src/branch/main/R/build_timeline.R#L268)

# `reconstruct_original()`

Reconstruct Original Layout

## Usage

```r
reconstruct_original(xlsx, sheet = NULL)
```

## Arguments

| Argument | Description |
|----------|-------------|
| `xlsx` | An xlsx_workbook object from `parse_xlsx()`, or a file path. |
| `sheet` | Optional sheet name to reconstruct. If NULL (default), reconstructs all sheets. |

## Value

A tibble showing cells reordered by creation sequence:

- `original_row`: The inferred original row position (based on creation order)

- `current_row`: The current row position in the spreadsheet

- `cell_ref`: Cell reference

- `formula`: The Excel formula

- `was_moved`: TRUE if current position differs from inferred original

- `movement`: Description of how the cell moved ("inserted", "moved up N rows", etc.)

## Description

Attempts to reconstruct what the spreadsheet might have looked like before
rows were moved or inserted, by reordering formula cells according to their
creation order in calcChain.xml.

## Details

This function infers the "original" layout by assuming formulas were created
top-to-bottom. It assigns row positions based on creation order, then compares
to current positions to show what changed.

Important Limitations

- Only tracks **formula cells** (constants are not in calcChain.xml)

- Cannot know the absolute original row numbers, only relative order

- Assumes formulas were originally created in row order (top to bottom)

- Multiple editing sessions may complicate the picture

This is a **best guess**, not a perfect reconstruction.

## Examples

```r
## Not run: 
# Reconstruct original layout
xlsx  dplyr::filter(was_moved)

## End(Not run)
```

