Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat: object matrix add new fucntion (#6163)

wpxp12345615ae3e1f174c
diff --git a/packages/core/src/shared/object-matrix.ts b/packages/core/src/shared/object-matrix.ts
index 6d482c812b..cca9095f68 100644
--- a/packages/core/src/shared/object-matrix.ts
+++ b/packages/core/src/shared/object-matrix.ts
@@ -514,6 +514,25 @@ export class ObjectMatrix<T> {
return objectMatrix;
}
+ getSliceDataAndCellCountByRows(startRow: number, endRow: number): {
+ sliceData: ObjectMatrix<T>;
+ cellCount: number;
+ } {
+ const objectMatrix = new ObjectMatrix<T>();
+ let cellCount = 0;
+ for (let r = startRow; r <= endRow; r++) {
+ const row = this.getRow(r);
+ if (row) {
+ objectMatrix.setRow(r, row);
+ cellCount += Object.keys(row).length;
+ }
+ }
+ return {
+ sliceData: objectMatrix,
+ cellCount,
+ };
+ }
+
getSizeOf(): number {
const keys = Object.keys(this._matrix);
return keys.length;
@@ -545,6 +564,41 @@ export class ObjectMatrix<T> {
};
}
+ getRealRange(): IRange {
+ const rows = Object.keys(this._matrix);
+ const startRow = rows.length > 0 ? Number(rows[0]) : 0;
+ const endRow = rows.length > 0 ? Number(rows[rows.length - 1]) : 0;
+
+ let startColumn = 0;
+ let endColumn = 0;
+
+ for (const rowKey of rows) {
+ const row = this.getRow(Number(rowKey));
+ if (row) {
+ const columns = Object.keys(row);
+ if (columns.length > 0) {
+ const rowStartColumn = Number(columns[0]);
+ const rowEndColumn = Number(columns[columns.length - 1]);
+
+ if (startColumn === 0 || rowStartColumn < startColumn) {
+ startColumn = rowStartColumn;
+ }
+
+ if (rowEndColumn > endColumn) {
+ endColumn = rowEndColumn;
+ }
+ }
+ }
+ }
+
+ return {
+ startRow,
+ endRow,
+ startColumn,
+ endColumn,
+ };
+ }
+
toNativeArray(): T[] {
const native = new Array<T>();
this.forValue((row: number, col: number, value: T) => {
@@ -756,6 +810,14 @@ export class ObjectMatrix<T> {
});
}
+ concatRows(newObject: ObjectMatrix<T>) {
+ const newMatrix = newObject.getMatrix();
+ for (const rowKey in newMatrix) {
+ const rowIndex = Number(rowKey);
+ this.setRow(rowIndex, newMatrix[rowIndex]);
+ }
+ }
+
private _setOriginValue(matrix: IObjectMatrixPrimitiveType<T> = {}) {
this._matrix = matrix;
}