A PartialGrid represents a detached rectangular block of cells β€” including data, styles, and borders β€” that can be extracted from or applied to a worksheet. It is the underlying mechanism for clipboard operations, the SetPartialGridAction, and pattern-repeating fills.

Namespace

using unvell.ReoGrid;

Creating a PartialGrid

Constructors

ConstructorDescription
PartialGrid()Create an empty partial grid
PartialGrid(int rows, int cols)Create an empty partial grid with the specified capacity
PartialGrid(object[,] data)Create a partial grid filled with data from a 2D array
// From a 2D array
var grid = new PartialGrid(new object[,] {
    { "Name", "Price", "Qty" },
    { "Apple", 1.20, 50 },
    { "Banana", 0.80, 30 },
});

Properties

PropertyTypeDescription
RowsintNumber of rows in the partial grid
ColumnsintNumber of columns in the partial grid

Extracting from a Worksheet

Use GetPartialGrid to copy a block of cells from the worksheet. The returned PartialGrid contains data, styles, and borders.

GetPartialGrid Overloads

SignatureDescription
GetPartialGrid(string addressOrName)Get by address or named range
GetPartialGrid(int row, int col, int rows, int cols)Get by position and size
GetPartialGrid(RangePosition range)Get by range position
GetPartialGrid(int[] columns, int[] rows)Get non-contiguous columns and rows
// Copy a block from A1:C3
PartialGrid block = sheet.GetPartialGrid("A1:C3");

// Copy by position
PartialGrid block = sheet.GetPartialGrid(0, 0, 3, 3);

// Copy specific columns and rows (non-contiguous)
PartialGrid block = sheet.GetPartialGrid(
    new int[] { 0, 2, 4 },   // columns A, C, E
    new int[] { 0, 1, 2 });   // rows 1, 2, 3

Applying to a Worksheet

Use SetPartialGrid to paste a partial grid into the worksheet at a target position. This overwrites the target range with the partial grid’s data, styles, and borders.

SetPartialGrid Overloads

SignatureReturnDescription
SetPartialGrid(string addressOrName, PartialGrid data)RangePositionPaste at the address or named range
SetPartialGrid(RangePosition toRange, PartialGrid data)RangePositionPaste at the range position
// Copy from one location to another
var block = sheet.GetPartialGrid("A1:C3");
sheet.SetPartialGrid("E1", block);

The returned RangePosition is the actual range that was filled.

Repeating a Pattern

Use SetPartialGridRepeatly to tile a partial grid across a larger range. The partial grid is repeated to fill the target range.

SetPartialGridRepeatly Overloads

SignatureReturnDescription
SetPartialGridRepeatly(string addressOrName, PartialGrid grid, PartialGridCopyFlag flags)RangePositionRepeat at address
SetPartialGridRepeatly(RangePosition range, PartialGrid grid, PartialGridCopyFlag flags)RangePositionRepeat at range
// Create a 2-row pattern
var pattern = new PartialGrid(new object[,] {
    { "A", "B", "C" },
    { "D", "E", "F" },
});

// Tile the pattern across a 10-row range
sheet.SetPartialGridRepeatly("A1:C10", pattern);

PartialGridCopyFlag

The PartialGridCopyFlag enum controls which elements of the partial grid are copied.

Individual Flags

ValueHexDescription
CellData0x1Cell data values
CellFormula0x2Cell formulas
CellFormat0x4Data format settings
CellStyle0x8Cell styles
HBorder0x10Horizontal borders
VBorder0x20Vertical borders

Composite Flags

ValueCombinesDescription
CellPropertiesCellData | CellFormula | CellFormat | CellStyleAll cell properties
BordersHBorder | VBorderAll borders
AllCellProperties | BordersEverything (default)
// Copy only data and formulas (no styles or borders)
sheet.SetPartialGridRepeatly("A1:C10", pattern,
    PartialGridCopyFlag.CellData | PartialGridCopyFlag.CellFormula);

Using with Actions

The SetPartialGridAction provides undo/redo support for pasting partial grids:

using unvell.ReoGrid.Actions;

var block = sheet.GetPartialGrid("A1:C3");
sheet.DoAction(new SetPartialGridAction(
    new RangePosition("E1:G3"), block, PartialGridCopyFlag.All));

// Undo the paste
grid.Undo();

Comparing Partial Grids

bool isEqual = grid1.Equals(grid2, PartialGridCopyFlag.All);
bool dataOnly = grid1.Equals(grid2, PartialGridCopyFlag.CellData);

Examples

Copy and Paste a Block

// Copy header row with styles
var header = sheet.GetPartialGrid("A1:F1");

// Paste into another worksheet
var sheet2 = grid.Worksheets[1];
sheet2.SetPartialGrid("A1", header);

Create a Repeating Template

// Define a styled template row
var template = sheet.GetPartialGrid("A1:D2");

// Apply it across 20 rows
sheet.SetPartialGridRepeatly("A3:D22", template);

Selective Copy

// Copy only styles (no data)
sheet.SetPartialGridRepeatly("A1:D10", template,
    PartialGridCopyFlag.CellStyle | PartialGridCopyFlag.Borders);
Was this article helpful?