Skip to content

Commit e4e6911

Browse files
authored
Merge pull request #19 from zurmokeeper/feature/add_remove_note_func
Feature/add remove note func
2 parents 8393273 + a094ad1 commit e4e6911

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ worksheet.getColumn(5).outlineLevel = 1;
786786
expect(worksheet.getColumn(4).collapsed).to.equal(false);
787787
expect(worksheet.getColumn(5).collapsed).to.equal(true);
788788

789-
// Insert a page break below the column
789+
// Insert a page break after the column
790790
dobCol.addPageBreak();
791791

792792
// iterate over all current cells in this column
@@ -1258,6 +1258,9 @@ ws.getCell('B1').note = {
12581258
},
12591259
editAs: 'twoCells',
12601260
};
1261+
1262+
// remove note
1263+
ws.getCell('B1').removeNote()
12611264
```
12621265

12631266
### Cell Comments Properties[](#contents)<!-- Link generated with jump2header -->

README_zh.md

+3
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,9 @@ ws.getCell('B1').note = {
12041204
},
12051205
editAs: 'twoCells'
12061206
};
1207+
1208+
// 移除单元格注释
1209+
ws.getCell('B1').removeNote()
12071210
```
12081211

12091212
### 单元格批注属性[](#目录)<!-- Link generated with jump2header -->

index.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@ export interface Cell extends Style, Address {
504504
unmerge(): void;
505505
isMergedTo(master: Cell): boolean;
506506
toString(): string;
507+
508+
/**
509+
* Remove comment of the cell
510+
*/
511+
removeNote(): void;
507512
}
508513

509514
export interface RowModel {

lib/doc/cell.js

+6
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ class Cell {
229229
this._comment = new Note(note);
230230
}
231231

232+
removeNote() {
233+
delete this._comment;
234+
}
235+
232236
get text() {
233237
return this._value.toString();
234238
}
@@ -331,6 +335,8 @@ class Cell {
331335
model.style = this.style;
332336
if (this._comment) {
333337
model.comment = this._comment.model;
338+
} else {
339+
delete model.comment;
334340
}
335341
return model;
336342
}

spec/unit/doc/cell.spec.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,28 @@ describe('Cell', () => {
369369
expect(a1.model.comment.note).to.deep.equal(comment);
370370
});
371371

372+
it('can remove comment', () => {
373+
const a1 = sheetMock.getCell('A1');
374+
375+
expect(a1.note).to.be.undefined();
376+
377+
a1.note = 'Some note';
378+
expect(a1.model.comment.note.texts[0].text).to.be.eq('Some note');
379+
380+
a1.removeNote();
381+
expect(a1.model.comment).to.be.undefined();
382+
});
383+
384+
it('fails to remove comment by assigning empty object', () => {
385+
const a1 = sheetMock.getCell('A1');
386+
a1.note = 'Some note';
387+
388+
expect(a1.model.comment.note.texts[0].text).to.be.eq('Some note');
389+
390+
a1.note = {};
391+
expect(a1.model.comment).to.exist();
392+
});
393+
372394
it('Cell comments supports setting margins, protection, and position properties', () => {
373395
const a1 = sheetMock.getCell('A1');
374396

@@ -399,10 +421,7 @@ describe('Cell', () => {
399421
expect(a1.model.comment.note.protection).to.deep.equal(comment.protection);
400422
expect(a1.model.comment.note.margins.insetmode).to.equal('auto');
401423
expect(a1.model.comment.note.margins.inset).to.deep.equal([
402-
0.13,
403-
0.13,
404-
0.25,
405-
0.25,
424+
0.13, 0.13, 0.25, 0.25,
406425
]);
407426
expect(a1.model.comment.note.editAs).to.equal('absolute');
408427
});

0 commit comments

Comments
 (0)