Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added mapping policies to the exports: `AlwaysDense`, `AlwaysSparse`, `DenseSparseChooseBasedOnThreshold`. (#747)
- Added `#SPILL!` error type. (#708)
- Added large tests for CRUD interactions. (#755)
- Added a flag to `getFillRangeData` to support different types of offsetting. (#767)

### Fixed
- Fixed an issue with arrays and cruds. (#651)
Expand Down
7 changes: 4 additions & 3 deletions src/HyperFormula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,7 @@ export class HyperFormula implements TypedEmitter {
*
* @param {SimpleCellRange} source of data
* @param {SimpleCellRange} target range where data is intended to be put
* @param {boolean} offsetsFromTarget if true, offsets are computed from target corner, otherwise from source corner
*
* @throws [[SheetsNotEqual]] if both ranges are not from the same sheet
* @throws [[EvaluationSuspendedError]] when the evaluation is suspended
Expand All @@ -2414,7 +2415,7 @@ export class HyperFormula implements TypedEmitter {
*
* @category Ranges
*/
public getFillRangeData(source: SimpleCellRange, target: SimpleCellRange): RawCellContent[][] {
public getFillRangeData(source: SimpleCellRange, target: SimpleCellRange, offsetsFromTarget: boolean = false): RawCellContent[][] {
if (!isSimpleCellRange(source)) {
throw new ExpectedValueOfTypeError('SimpleCellRange', 'source')
}
Expand All @@ -2430,8 +2431,8 @@ export class HyperFormula implements TypedEmitter {
return targetRange.arrayOfAddressesInRange().map(
(subarray) => subarray.map(
(address) => {
const row = ((address.row - source.start.row) % sourceRange.height() + sourceRange.height()) % sourceRange.height() + source.start.row
const col = ((address.col - source.start.col) % sourceRange.width() + sourceRange.width()) % sourceRange.width() + source.start.col
const row = ((address.row - (offsetsFromTarget ? target : source).start.row) % sourceRange.height() + sourceRange.height()) % sourceRange.height() + source.start.row
const col = ((address.col - (offsetsFromTarget ? target : source).start.col) % sourceRange.width() + sourceRange.width()) % sourceRange.width() + source.start.col
return this._serialization.getCellSerialized({row, col, sheet: targetRange.sheet}, address)
}
)
Expand Down
25 changes: 24 additions & 1 deletion test/engine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ describe('Graph dependency topological ordering module', () => {
})
})

describe('#getFillRangeData', () => {
describe('#getFillRangeData from corner source', () => {
it('should properly apply wrap-around #1', () => {
const engine = HyperFormula.buildFromArray([[], [undefined, 1, '=A1'], [undefined, '=$A$1', '2']])

Expand All @@ -806,3 +806,26 @@ describe('#getFillRangeData', () => {
).toEqual([['2', '=$A$1', '2'], ['=#REF!', 1, '=A1'], ['2', '=$A$1', '2'] ])
})
})

describe('#getFillRangeData from target source', () => {
it('should properly apply wrap-around #1', () => {
const engine = HyperFormula.buildFromArray([[], [undefined, 1, '=A1'], [undefined, '=$A$1', '2']])

expect(engine.getFillRangeData(AbsoluteCellRange.spanFrom(adr('B2'), 2, 2), AbsoluteCellRange.spanFrom(adr('C3'), 3, 3), true)
).toEqual([[1, '=B2', 1], ['=$A$1', '2', '=$A$1'], [1, '=B4', 1]])
})

it('should properly apply wrap-around #2', () => {
const engine = HyperFormula.buildFromArray([[], [undefined, 1, '=A1'], [undefined, '=$A$1', '2']])

expect(engine.getFillRangeData(AbsoluteCellRange.spanFrom(adr('B2'), 2, 2), AbsoluteCellRange.spanFrom(adr('B2'), 3, 3), true)
).toEqual([[1, '=A1', 1], ['=$A$1', '2', '=$A$1'], [1, '=A3', 1]])
})

it('should properly apply wrap-around #3', () => {
const engine = HyperFormula.buildFromArray([[], [undefined, 1, '=A1'], [undefined, '=$A$1', '2']])

expect(engine.getFillRangeData(AbsoluteCellRange.spanFrom(adr('B2'), 2, 2), AbsoluteCellRange.spanFrom(adr('A1'), 3, 3), true)
).toEqual([[1, '=#REF!', 1], ['=$A$1', '2', '=$A$1'], [1, '=#REF!', 1]])
})
})