Skip to content

Commit

Permalink
Set number format (#133)
Browse files Browse the repository at this point in the history
* numberFormat

* initializeMatrixSameSize

* initializeMatrixSameSize

* initializeMatrixSameSize
  • Loading branch information
MakotoE authored Sep 6, 2024
1 parent c58ad7d commit 04a9c88
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions excel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,23 @@ export function _resize(a: string[][], maxLength: number): void {
}
}

// Creates matrix with the same size as input. Each string is initialized to '@'.
function initializeMatrixSameSize(input: string[][]): string[][] {
if (input.length === 0) {
return [];
}

return new Array(input.length).fill(new Array(input[0].length).fill('@'));
}

export function setChunk(worksheet: Excel.Worksheet, row: number, chunk: string[][]): void {
// New range values must have the same shape as range
const maxLength = _maxLength(chunk);
_resize(chunk, maxLength);
// getRangeByIndexes() throws error if rowCount or columnCount is 0
if (chunk.length > 0 && maxLength > 0) {
const range = worksheet.getRangeByIndexes(row, 0, chunk.length, maxLength);
range.numberFormat = initializeMatrixSameSize(chunk);
range.values = chunk;
range.untrack();
}
Expand Down

0 comments on commit 04a9c88

Please sign in to comment.