@syncfusion/ej2-spreadsheet
Version:
Feature-rich JavaScript Spreadsheet (Excel) control with built-in support for selection, editing, formatting, importing and exporting to Excel
81 lines (63 loc) • 2.66 kB
Markdown
# AutoFill Module data flow
## What It Does
AutoFill automatically fills cells using pattern recognition, series generation, and copying. Two-layer architecture: **AutoFill (UI)** handles user interactions, **WorkbookAutoFill (Core)** executes filling logic.
## Entry Points
**AutoFill (UI Layer)**
- `performAutoFill()` - Triggered by drag handle interaction
- `getAutoFillRange()` - Calculates fill range from drag position
**WorkbookAutoFill (Core Layer)**
- `autoFill()` - Main coordinator routing to fillSeries() or copyCells()
- `getFillInfo()` - Analyzes data and returns fillType + disabled menu items
- Event listener on `setAutoFill` notification
## Core Logic Flow
```
User Drag → performAutoFill() → getAutoFillRange() → setAutoFill Notification
↓
WorkbookAutoFill.autoFill()
↓
getFillInfo()
↓
(fillType = numeric? → fillSeries() : copyCells())
```
## Operations Handled
1. **fillSeries()** - Detects pattern (number/date/formula/string/time) and generates next values using:
- `getDataPattern()` - Identifies value types and format
- `getPattern()` - Generates predictions via linear regression
- `getPredictionValue()` - Calculates a, b coefficients for trend line
2. **copyCells()** - Simple duplication:
- Copies all cell properties cyclically across target range
- Optional: preserve original values (FillFormattingOnly)
- Handles read-only/validation/notes removal
3. **Pattern Types**:
- Numbers: Linear/geometric progression (1,2,3 or 2,4,6)
- Dates: Calendar-aware increments (1/1, 1/2, 1/3)
- Formulas: Updates references (A1→A2, $A$1→$A$1, mixed)
- Strings: Month/day sequences
- Time: Duration patterns (1:00, 1:15, 1:30)
## Fill Types
| Type | Behavior |
|------|----------|
| CopyCells | Repeat values + formatting |
| FillSeries | Calculate series + formatting |
| FillFormattingOnly | Copy format, keep values |
| FillWithoutFormatting | Calculate series, no format |
## Validation & Safety
- **Read-only cells**: Alert + stop
- **Protected sheets**: Check locked cells, prevent fill
- **Merged cells**: Handle with adjusted ranges
- **Hidden rows/cols**: Skip silently
- **Conditional formats**: Refresh after fill
- **Hyperlinks**: Preserve/remove per fillType
## Desired Outputs
**User-Facing:**
- Autofill handle at selection corner
- Dropdown menu with 4 fill options
- Smart series/duplication based on source
- Expandable selection on drag
**System-Level:**
- Updated cells with calculated/copied values
- Formatting applied per fillType
- Validation rules preserved
- Row heights adjusted
- Undo/redo recorded
- Events: beginAction, completeAction