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
12 changes: 12 additions & 0 deletions src/AbsoluteCellRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ export class AbsoluteCellRange {
return false
}

public arrayOfAddressesInRange(): SimpleCellAddress[][] {
const result: SimpleCellAddress[][] = []
for (let y = 0; y < this.height(); ++y) {
result[y] = []
for (let x = 0; x < this.width(); ++x) {
const value = simpleCellAddress(this.sheet, this.start.col + x, this.start.row + y)
result[y].push(value)
}
}
return result
}

public containsRange(range: AbsoluteCellRange): boolean {
return this.addressInRange(range.start) && this.addressInRange(range.end)
}
Expand Down
14 changes: 0 additions & 14 deletions src/DependencyGraph/DependencyGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,20 +536,6 @@ export class DependencyGraph {
return this.rangeMapping.getRange(start, end)
}

public getValuesInRange(range: AbsoluteCellRange): InternalCellValue[][] {
const result: InternalCellValue[][] = []

for (let y = 0; y < range.height(); ++y) {
result[y] = []
for (let x = 0; x < range.width(); ++x) {
const value = this.getCellValue(simpleCellAddress(range.sheet, range.start.col + x, range.start.row + y))
result[y].push(value)
}
}

return result
}

public topSortWithScc(): TopSortResult<Vertex> {
return this.graph.topSortWithScc()
}
Expand Down
53 changes: 39 additions & 14 deletions src/HyperFormula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
CellValueType,
getCellType,
getCellValueType,
InternalCellValue,
simpleCellAddress,
SimpleCellAddress,
} from './Cell'
Expand Down Expand Up @@ -232,7 +231,7 @@ export class HyperFormula {
* Returns map containing dimensions of all sheets.
*
*/
public getSheetsDimensions(): Record<string, { width: number, height: number }> {
public getAllSheetsDimensions(): Record<string, { width: number, height: number }> {
return this.genericAllGetter((...args) => this.getSheetDimensions(...args))
}

Expand All @@ -252,23 +251,23 @@ export class HyperFormula {
* Returns map containing values of all sheets.
*
*/
public getSheetsValues(): Record<string, CellValue[][]> {
public getAllSheetsValues(): Record<string, CellValue[][]> {
return this.genericAllGetter((...args) => this.getSheetValues(...args))
}

/**
* Returns map containing formulas of all sheets.
*
*/
public getSheetsFormulas(): Record<string, Maybe<string>[][]> {
public getAllSheetsFormulas(): Record<string, Maybe<string>[][]> {
return this.genericAllGetter((...args) => this.getSheetFormulas(...args))
}

/**
* Returns map containing formulas or values of all sheets.
*
*/
public getSheetsSerialized(): Record<string, CellValue[][]> {
public getAllSheetsSerialized(): Record<string, CellValue[][]> {
return this.genericAllGetter((...args) => this.getSheetSerialized(...args))
}

Expand Down Expand Up @@ -569,9 +568,9 @@ export class HyperFormula {
* @param width - width of the cell block being copied
* @param height - height of the cell block being copied
* */
public copy(sourceLeftCorner: SimpleCellAddress, width: number, height: number): InternalCellValue[][] {
public copy(sourceLeftCorner: SimpleCellAddress, width: number, height: number): CellValue[][] {
this.crudOperations.copy(sourceLeftCorner, width, height)
return this.getValuesInRange(AbsoluteCellRange.spanFrom(sourceLeftCorner, width, height))
return this.getRangeValues(AbsoluteCellRange.spanFrom(sourceLeftCorner, width, height))
}

/**
Expand All @@ -584,9 +583,9 @@ export class HyperFormula {
* @param width - width of the cell block being copied
* @param height - height of the cell block being copied
* */
public cut(sourceLeftCorner: SimpleCellAddress, width: number, height: number): InternalCellValue[][] {
public cut(sourceLeftCorner: SimpleCellAddress, width: number, height: number): CellValue[][] {
this.crudOperations.cut(sourceLeftCorner, width, height)
return this.getValuesInRange(AbsoluteCellRange.spanFrom(sourceLeftCorner, width, height))
return this.getRangeValues(AbsoluteCellRange.spanFrom(sourceLeftCorner, width, height))
}

/**
Expand All @@ -613,11 +612,37 @@ export class HyperFormula {
*
* @param range
*/
public getValuesInRange(range: AbsoluteCellRange): InternalCellValue[][] {
return this.dependencyGraph.getValuesInRange(range).map(
(subarray: InternalCellValue[]) => subarray.map(
(arg) => this.exporter.exportValue(arg),
),
public getRangeValues(range: AbsoluteCellRange): CellValue[][] {
return range.arrayOfAddressesInRange().map(
(subarray) => subarray.map(
(address) => this.getCellValue(address)
)
)
}

/**
* Returns cell formulas in given range
*
* @param range
*/
public getRangeFormulas(range: AbsoluteCellRange): Maybe<string>[][] {
return range.arrayOfAddressesInRange().map(
(subarray) => subarray.map(
(address) => this.getCellFormula(address)
)
)
}

/**
* Returns serialized cell in given range
*
* @param range
*/
public getRangeSerialized(range: AbsoluteCellRange): CellValue[][] {
return range.arrayOfAddressesInRange().map(
(subarray) => subarray.map(
(address) => this.getCellSerialized(address)
)
)
}

Expand Down
2 changes: 1 addition & 1 deletion test/build-engine-from-arrays.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ describe('Building engine from arrays', () => {
const config = new Config()
const engine = HyperFormula.buildFromArray([], config)

expect(engine.getSheetsDimensions()).toEqual({'Sheet1': {'height': 0, 'width': 0}})
expect(engine.getAllSheetsDimensions()).toEqual({'Sheet1': {'height': 0, 'width': 0}})
})
})
6 changes: 3 additions & 3 deletions test/engine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Integration', () => {
Foo: [[1]],
})

expect(engine.getSheetsValues()).toEqual({'Foo': [[1]], 'Sheet1': []})
expect(engine.getAllSheetsValues()).toEqual({'Foo': [[1]], 'Sheet1': []})
})

it('getAllFormulas', () => {
Expand All @@ -50,7 +50,7 @@ describe('Integration', () => {
Foo: [[1]],
})

expect(engine.getSheetsFormulas()).toEqual({'Foo': [[undefined]], 'Sheet1': [['=A()']]})
expect(engine.getAllSheetsFormulas()).toEqual({'Foo': [[undefined]], 'Sheet1': [['=A()']]})
})

it('getAllSerialized', () => {
Expand All @@ -59,7 +59,7 @@ describe('Integration', () => {
Foo: [[1]],
})

expect(engine.getSheetsSerialized()).toEqual({'Foo': [[1]], 'Sheet1': [['=A()']]})
expect(engine.getAllSheetsSerialized()).toEqual({'Foo': [[1]], 'Sheet1': [['=A()']]})
})

it('handle different input types', () => {
Expand Down