-
-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(formula): get rich text data stream as content (#1305)
* fix(formula): get rich text data stream as content * fix(formula): get datastream number when insert function
- Loading branch information
Showing
5 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/engine-formula/src/engine/utils/__tests__/cell.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright 2023-present DreamNum Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { describe, expect, it } from 'vitest'; | ||
|
||
import type { ICellData } from '@univerjs/core'; | ||
import { getCellValue } from '../cell'; | ||
|
||
describe('Test cell', () => { | ||
it('Function getCellValue', () => { | ||
const cell1: ICellData = { | ||
p: { | ||
id: 'p', | ||
body: { | ||
dataStream: 'test\r\n', | ||
}, | ||
documentStyle: {}, | ||
}, | ||
}; | ||
|
||
const cell2 = { | ||
v: 2, | ||
}; | ||
|
||
const cell3 = { | ||
f: '', | ||
}; | ||
|
||
expect(getCellValue(cell1)).toBe('test'); | ||
expect(getCellValue(cell2)).toBe(2); | ||
expect(getCellValue(cell3)).toBe(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright 2023-present DreamNum Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { DEFAULT_EMPTY_DOCUMENT_VALUE } from '@univerjs/core'; | ||
import type { ICellData, Nullable } from '@univerjs/core'; | ||
|
||
export function getCellValue(cell: Nullable<ICellData>) { | ||
if (cell === null) { | ||
return 0; | ||
} | ||
|
||
if (cell?.p) { | ||
const body = cell?.p.body; | ||
|
||
if (body == null) { | ||
return 0; | ||
} | ||
|
||
const data = body.dataStream; | ||
const lastString = data.substring(data.length - 2, data.length); | ||
const newDataStream = lastString === DEFAULT_EMPTY_DOCUMENT_VALUE ? data.substring(0, data.length - 2) : data; | ||
|
||
return newDataStream; | ||
} | ||
|
||
return cell?.v || 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters