View | Details | Raw Unified | Return to bug 44566
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java (-10 / +21 lines)
Lines 18-43 Link Here
18
18
19
import org.apache.poi.ss.usermodel.Comment;
19
import org.apache.poi.ss.usermodel.Comment;
20
import org.apache.poi.ss.usermodel.RichTextString;
20
import org.apache.poi.ss.usermodel.RichTextString;
21
import org.apache.poi.xssf.usermodel.extensions.XSSFSheetComments;
21
import org.apache.poi.xssf.usermodel.extensions.XSSFComments;
22
import org.apache.poi.xssf.usermodel.helpers.RichTextStringHelper;
22
import org.apache.poi.xssf.util.CellReference;
23
import org.apache.poi.xssf.util.CellReference;
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
24
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
24
26
25
public class XSSFComment implements Comment {
27
public class XSSFComment implements Comment {
26
	
28
	
27
	private CTComment comment;
29
	private CTComment comment;
28
	private XSSFSheetComments sheetComments;
30
	private XSSFComments comments;
29
31
30
	public XSSFComment(XSSFSheetComments sheetComments, CTComment comment) {
32
	public XSSFComment(XSSFComments comments, CTComment comment) {
31
		this.comment = comment;
33
		this.comment = comment;
32
		this.sheetComments = sheetComments;
34
		this.comments = comments;
33
	}
35
	}
34
36
35
	public XSSFComment(XSSFSheetComments sheetComments) {
37
	public XSSFComment(XSSFComments sheetComments) {
36
		this(sheetComments, CTComment.Factory.newInstance());
38
		this(sheetComments, CTComment.Factory.newInstance());
37
	}
39
	}
38
40
39
	public String getAuthor() {
41
	public String getAuthor() {
40
		return sheetComments.getAuthor(comment.getAuthorId());
42
		return comments.getAuthor(comment.getAuthorId());
41
	}
43
	}
42
44
43
	public short getColumn() {
45
	public short getColumn() {
Lines 50-60 Link Here
50
52
51
	public boolean isVisible() {
53
	public boolean isVisible() {
52
		// TODO Auto-generated method stub
54
		// TODO Auto-generated method stub
53
		return false;
55
		return true;
54
	}
56
	}
55
57
56
	public void setAuthor(String author) {
58
	public void setAuthor(String author) {
57
		sheetComments.findAuthor(author);
59
		comments.findAuthor(author);
58
	}
60
	}
59
61
60
	public void setColumn(short col) {
62
	public void setColumn(short col) {
Lines 76-88 Link Here
76
	}
78
	}
77
79
78
	public void setString(RichTextString string) {
80
	public void setString(RichTextString string) {
79
		// TODO Auto-generated method stub
81
		CTRst text = comment.addNewText();
80
82
		RichTextStringHelper.convertToRst(string, text);
81
	}
83
	}
84
	
85
	public void setString(String string) {
86
		RichTextString richTextString = new XSSFRichTextString(string);
87
		setString(richTextString);
88
	}
82
89
83
	public void setVisible(boolean visible) {
90
	public void setVisible(boolean visible) {
84
		// TODO Auto-generated method stub
91
		// TODO Auto-generated method stub
85
92
86
	}
93
	}
94
	
95
	public String getString() {
96
		return comment.getText().getT().toString();
97
	}
87
98
88
}
99
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (-4 / +44 lines)
Lines 31-40 Link Here
31
import org.apache.poi.ss.usermodel.PrintSetup;
31
import org.apache.poi.ss.usermodel.PrintSetup;
32
import org.apache.poi.ss.usermodel.Row;
32
import org.apache.poi.ss.usermodel.Row;
33
import org.apache.poi.ss.usermodel.Sheet;
33
import org.apache.poi.ss.usermodel.Sheet;
34
import org.apache.poi.xssf.usermodel.extensions.XSSFComments;
34
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
35
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
35
import org.apache.poi.xssf.util.CellReference;
36
import org.apache.poi.xssf.util.CellReference;
36
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBreak;
37
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBreak;
37
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
38
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
38
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
39
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
39
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
40
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
40
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
41
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
Lines 42-47 Link Here
42
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetUpPr;
43
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetUpPr;
43
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPrintOptions;
44
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPrintOptions;
44
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
45
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
46
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSelection;
45
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
47
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
46
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
48
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
47
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr;
49
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr;
Lines 56-65 Link Here
56
    protected CTSheet sheet;
58
    protected CTSheet sheet;
57
    protected CTWorksheet worksheet;
59
    protected CTWorksheet worksheet;
58
    protected CTDialogsheet dialogsheet;
60
    protected CTDialogsheet dialogsheet;
59
    protected CTComment comment;
61
    protected CTComments comments;
60
    protected List<Row> rows;
62
    protected List<Row> rows;
61
    protected ColumnHelper columnHelper;
63
    protected ColumnHelper columnHelper;
62
    protected XSSFWorkbook workbook;
64
    protected XSSFWorkbook workbook;
65
    protected XSSFComments sheetComments;
63
66
64
    public static final short LeftMargin = 0;
67
    public static final short LeftMargin = 0;
65
    public static final short RightMargin = 1;
68
    public static final short RightMargin = 1;
Lines 68-73 Link Here
68
    public static final short HeaderMargin = 4;
71
    public static final short HeaderMargin = 4;
69
    public static final short FooterMargin = 5;
72
    public static final short FooterMargin = 5;
70
73
74
	public XSSFSheet(CTSheet sheet, CTWorksheet worksheet, XSSFWorkbook workbook, XSSFComments sheetComments) {
75
		this(sheet, worksheet, workbook);
76
		this.sheetComments = sheetComments;
77
	}
78
71
	public XSSFSheet(CTSheet sheet, CTWorksheet worksheet, XSSFWorkbook workbook) {
79
	public XSSFSheet(CTSheet sheet, CTWorksheet worksheet, XSSFWorkbook workbook) {
72
        this.workbook = workbook;
80
        this.workbook = workbook;
73
        this.sheet = sheet;
81
        this.sheet = sheet;
Lines 204-211 Link Here
204
	}
212
	}
205
213
206
    public Comment getCellComment(int row, int column) {
214
    public Comment getCellComment(int row, int column) {
207
        // TODO Auto-generated method stub
215
    	return getComments().findCellComment(row, column);
208
        return null;
209
    }
216
    }
210
217
211
    public short[] getColumnBreaks() {
218
    public short[] getColumnBreaks() {
Lines 831-837 Link Here
831
        CTSheetView view = getDefaultSheetView();
838
        CTSheetView view = getDefaultSheetView();
832
        return view != null && view.getTabSelected();
839
        return view != null && view.getTabSelected();
833
    }
840
    }
841
    
842
    public void setCellComment(String cellRef, XSSFComment comment) {
843
    	getComments().setCellComment(cellRef, comment);
844
    }
845
    
846
    public String getActiveCell() {
847
    	return getSheetTypeSelection().getActiveCell();
848
    }
834
849
850
	public void setActiveCell(String cellRef) {
851
		getSheetTypeSelection().setActiveCell(cellRef);
852
	}
853
854
	private CTSelection getSheetTypeSelection() {
855
		if (getSheetTypeSheetView().sizeOfSelectionArray() == 0) {
856
			getSheetTypeSheetView().insertNewSelection(0);
857
		}
858
		return getSheetTypeSheetView().getSelectionArray(0);
859
	}
860
835
    /**
861
    /**
836
     * Return the default sheet view. This is the last one if the sheet's views, according to sec. 3.3.1.83
862
     * Return the default sheet view. This is the last one if the sheet's views, according to sec. 3.3.1.83
837
     * of the OOXML spec: "A single sheet view definition. When more than 1 sheet view is defined in the file,
863
     * of the OOXML spec: "A single sheet view definition. When more than 1 sheet view is defined in the file,
Lines 858-862 Link Here
858
	private void setSheet(CTSheet sheet) {
884
	private void setSheet(CTSheet sheet) {
859
		this.sheet = sheet;
885
		this.sheet = sheet;
860
	}
886
	}
887
	
888
	private XSSFComments getComments() {
889
		if (sheetComments == null) {
890
			sheetComments = new XSSFComments(getCTComments());
891
		}
892
		return sheetComments;
893
	}
861
894
895
	private CTComments getCTComments() {
896
		if (comments == null) {
897
			comments = CTComments.Factory.newInstance();
898
		}
899
		return comments;
900
	}
901
862
}
902
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFSheetComments.java (-60 lines)
Lines 1-60 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
package org.apache.poi.xssf.usermodel.extensions;
18
19
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAuthors;
20
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
21
22
public class XSSFSheetComments {
23
	
24
	private CTComments comments;
25
26
	public XSSFSheetComments() {
27
		this(CTComments.Factory.newInstance());
28
	}
29
30
	public XSSFSheetComments(CTComments comments) {
31
		this.comments = comments;
32
	}
33
34
	public String getAuthor(long authorId) {
35
		return getCommentsAuthors().getAuthorArray((int)authorId);
36
	}
37
	
38
	public int findAuthor(String author) {
39
		for (int i = 0 ; i < getCommentsAuthors().sizeOfAuthorArray() ; i++) {
40
			if (getCommentsAuthors().getAuthorArray(i).equals(author)) {
41
				return i;
42
			}
43
		}
44
		return addNewAuthor(author);
45
	}
46
47
	private CTAuthors getCommentsAuthors() {
48
		if (comments.getAuthors() == null) {
49
			comments.addNewAuthors();
50
		}
51
		return comments.getAuthors();
52
	}
53
	
54
	private int addNewAuthor(String author) {
55
		int index = getCommentsAuthors().sizeOfAuthorArray();
56
		getCommentsAuthors().insertAuthor(index, author);
57
		return index;
58
	}
59
60
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFComments.java (+103 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
package org.apache.poi.xssf.usermodel.extensions;
18
19
import org.apache.poi.xssf.usermodel.XSSFComment;
20
import org.apache.poi.xssf.util.CellReference;
21
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAuthors;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
24
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
25
26
public class XSSFComments {
27
	
28
	private CTComments comments;
29
30
	public XSSFComments() {
31
		this(CTComments.Factory.newInstance());
32
	}
33
34
	public XSSFComments(CTComments comments) {
35
		this.comments = comments;
36
	}
37
38
	public String getAuthor(long authorId) {
39
		return getCommentsAuthors().getAuthorArray((int)authorId);
40
	}
41
	
42
	public int findAuthor(String author) {
43
		for (int i = 0 ; i < getCommentsAuthors().sizeOfAuthorArray() ; i++) {
44
			if (getCommentsAuthors().getAuthorArray(i).equals(author)) {
45
				return i;
46
			}
47
		}
48
		return addNewAuthor(author);
49
	}
50
	
51
	public XSSFComment findCellComment(int row, int column) {
52
		return findCellComment(new CellReference().convertRowColToString((short)row, (short)column));
53
	}
54
	
55
	public XSSFComment findCellComment(String cellRef) {
56
		for (CTComment comment : getCommentsList().getCommentArray()) {
57
			if (cellRef.equals(comment.getRef())) {
58
				return new XSSFComment(this, comment);
59
			}
60
		}
61
		return null;
62
	}
63
	
64
	public void setCellComment (int row, int column, XSSFComment comment) {
65
		XSSFComment current = findCellComment(row, column);
66
		if (current == null) {
67
			current = addComment();
68
		}
69
		current = comment;
70
		current.setRow(row);
71
		current.setColumn((short) column);
72
	}
73
	
74
	public void setCellComment (String cellRef, XSSFComment comment) {
75
		CellReference cellReference = new CellReference(cellRef);
76
		setCellComment(cellReference.getRow(), cellReference.getCol(), comment);
77
	}
78
79
	public XSSFComment addComment() {
80
		return new XSSFComment(this, getCommentsList().addNewComment());
81
	}
82
83
	private CTCommentList getCommentsList() {
84
		if (comments.getCommentList() == null) {
85
			comments.addNewCommentList();
86
		}
87
		return comments.getCommentList();
88
	}
89
90
	private CTAuthors getCommentsAuthors() {
91
		if (comments.getAuthors() == null) {
92
			comments.addNewAuthors();
93
		}
94
		return comments.getAuthors();
95
	}
96
	
97
	private int addNewAuthor(String author) {
98
		int index = getCommentsAuthors().sizeOfAuthorArray();
99
		getCommentsAuthors().insertAuthor(index, author);
100
		return index;
101
	}
102
103
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorksheet.java (-1 lines)
Lines 18-24 Link Here
18
package org.apache.poi.xssf.usermodel;
18
package org.apache.poi.xssf.usermodel;
19
19
20
import org.apache.poi.ss.usermodel.Sheet;
20
import org.apache.poi.ss.usermodel.Sheet;
21
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
21
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
24
23
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/RichTextStringHelper.java (+29 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
package org.apache.poi.xssf.usermodel.helpers;
18
19
import org.apache.poi.ss.usermodel.RichTextString;
20
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
21
22
public class RichTextStringHelper {
23
24
	public static void convertToRst(RichTextString string, CTRst text) {
25
		// TODO: implement RichTextString to Rst conversion
26
		text.setT(string.getString());
27
	}
28
29
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (-6 / +5 lines)
Lines 26-31 Link Here
26
import org.apache.poi.ss.usermodel.Comment;
26
import org.apache.poi.ss.usermodel.Comment;
27
import org.apache.poi.ss.usermodel.RichTextString;
27
import org.apache.poi.ss.usermodel.RichTextString;
28
import org.apache.poi.ss.usermodel.SharedStringSource;
28
import org.apache.poi.ss.usermodel.SharedStringSource;
29
import org.apache.poi.xssf.util.CellReference;
29
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
30
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
30
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
31
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
31
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
32
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
Lines 73-80 Link Here
73
    }
74
    }
74
75
75
    public Comment getCellComment() {
76
    public Comment getCellComment() {
76
        // TODO Auto-generated method stub
77
    	return row.getSheet().getCellComment(row.getRowNum(), getCellNum());
77
        return null;
78
    }
78
    }
79
79
80
    public String getCellFormula() {
80
    public String getCellFormula() {
Lines 164-176 Link Here
164
    }
164
    }
165
165
166
    public void setAsActiveCell() {
166
    public void setAsActiveCell() {
167
        // TODO Auto-generated method stub
167
    	row.getSheet().setActiveCell(cell.getR());
168
169
    }
168
    }
170
169
171
    public void setCellComment(Comment comment) {
170
    public void setCellComment(Comment comment) {
172
        // TODO Auto-generated method stub
171
    	String cellRef = new CellReference().convertRowColToString((short) row.getRowNum(), getCellNum());
173
172
		row.getSheet().setCellComment(cellRef, (XSSFComment)comment);
174
    }
173
    }
175
174
176
    public void setCellErrorValue(byte value) {
175
    public void setCellErrorValue(byte value) {
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFSheetComments.java (-39 lines)
Lines 1-39 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.xssf.usermodel.extensions;
19
20
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
21
22
import junit.framework.TestCase;
23
24
25
public class TestXSSFSheetComments extends TestCase {
26
	
27
	private static final String TEST_AUTHOR = "test author";
28
29
	public void testfindAuthor() {
30
		CTComments comments = CTComments.Factory.newInstance();
31
		XSSFSheetComments sheetComments = new XSSFSheetComments(comments);
32
33
		assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR));
34
		assertEquals(1, sheetComments.findAuthor("another author"));
35
		assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR));
36
37
	}
38
    
39
}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFComments.java (+84 lines)
Line 0 Link Here
1
/* ====================================================================
2
   Licensed to the Apache Software Foundation (ASF) under one or more
3
   contributor license agreements.  See the NOTICE file distributed with
4
   this work for additional information regarding copyright ownership.
5
   The ASF licenses this file to You under the Apache License, Version 2.0
6
   (the "License"); you may not use this file except in compliance with
7
   the License.  You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
==================================================================== */
17
18
package org.apache.poi.xssf.usermodel.extensions;
19
20
import org.apache.poi.xssf.usermodel.XSSFComment;
21
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
24
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
25
26
import junit.framework.TestCase;
27
28
29
public class TestXSSFComments extends TestCase {
30
	
31
	private static final String TEST_A2_TEXT = "test A2 text";
32
	private static final String TEST_A1_TEXT = "test A1 text";
33
	private static final String TEST_AUTHOR = "test author";
34
35
	public void testfindAuthor() {
36
		CTComments comments = CTComments.Factory.newInstance();
37
		XSSFComments sheetComments = new XSSFComments(comments);
38
39
		assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR));
40
		assertEquals(1, sheetComments.findAuthor("another author"));
41
		assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR));
42
	}
43
	
44
	public void testGetCellComment() {
45
		CTComments comments = CTComments.Factory.newInstance();
46
		XSSFComments sheetComments = new XSSFComments(comments);
47
		CTCommentList commentList = comments.addNewCommentList();
48
		
49
		// Create 2 comments for A1 and A" cells
50
		CTComment comment0 = commentList.insertNewComment(0);
51
		comment0.setRef("A1");
52
		CTRst ctrst0 = CTRst.Factory.newInstance();
53
		ctrst0.setT(TEST_A1_TEXT);
54
		comment0.setText(ctrst0);
55
		CTComment comment1 = commentList.insertNewComment(0);
56
		comment1.setRef("A2");
57
		CTRst ctrst1 = CTRst.Factory.newInstance();
58
		ctrst1.setT(TEST_A2_TEXT);
59
		comment1.setText(ctrst1);
60
		
61
		// test finding the right comment for a cell
62
		assertEquals(TEST_A1_TEXT, sheetComments.findCellComment("A1").getString());
63
		assertEquals(TEST_A1_TEXT, sheetComments.findCellComment(0, 0).getString());
64
		assertEquals(TEST_A2_TEXT, sheetComments.findCellComment("A2").getString());
65
		assertEquals(TEST_A2_TEXT, sheetComments.findCellComment(1, 0).getString());
66
		assertNull(sheetComments.findCellComment("A3"));
67
		assertNull(sheetComments.findCellComment(2, 0));
68
	}
69
	
70
	public void testSetCellComment() {
71
		CTComments comments = CTComments.Factory.newInstance();
72
		XSSFComments sheetComments = new XSSFComments(comments);
73
		CTCommentList commentList = comments.addNewCommentList();
74
		assertEquals(0, commentList.sizeOfCommentArray());
75
		XSSFComment comment = new XSSFComment(sheetComments);
76
		comment.setAuthor("test A1 author");
77
		
78
		sheetComments.setCellComment("A1", comment);
79
		assertEquals(1, commentList.sizeOfCommentArray());
80
		assertEquals("test A1 author", sheetComments.getAuthor(commentList.getCommentArray(0).getAuthorId()));
81
		
82
	}
83
    
84
}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestHeaderFooterHelper.java (-1 lines)
Lines 20-26 Link Here
20
import junit.framework.TestCase;
20
import junit.framework.TestCase;
21
21
22
import org.apache.poi.xssf.usermodel.helpers.HeaderFooterHelper;
22
import org.apache.poi.xssf.usermodel.helpers.HeaderFooterHelper;
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
24
23
25
24
26
public class TestHeaderFooterHelper extends TestCase {
25
public class TestHeaderFooterHelper extends TestCase {
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java (-9 / +84 lines)
Lines 24-37 Link Here
24
import junit.framework.TestCase;
24
import junit.framework.TestCase;
25
25
26
import org.apache.poi.ss.usermodel.Cell;
26
import org.apache.poi.ss.usermodel.Cell;
27
import org.apache.poi.ss.usermodel.Comment;
28
import org.apache.poi.ss.usermodel.Row;
27
import org.apache.poi.ss.usermodel.SharedStringSource;
29
import org.apache.poi.ss.usermodel.SharedStringSource;
30
import org.apache.poi.ss.usermodel.Workbook;
31
import org.apache.poi.xssf.usermodel.extensions.XSSFComments;
28
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
32
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
33
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
34
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
35
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
36
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
29
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
37
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
30
38
31
39
32
public class TestXSSFCell extends TestCase {
40
public class TestXSSFCell extends TestCase {
33
    
41
    
34
    /**
42
    private static final String TEST_C10_AUTHOR = "test C10 author";
43
44
	/**
35
     * Test setting and getting boolean values.
45
     * Test setting and getting boolean values.
36
     */
46
     */
37
    public void testSetGetBoolean() throws Exception {
47
    public void testSetGetBoolean() throws Exception {
Lines 191-204 Link Here
191
        row.setRowNum(32767);
201
        row.setRowNum(32767);
192
        assertEquals("IV32768", cell.formatPosition());
202
        assertEquals("IV32768", cell.formatPosition());
193
    }
203
    }
194
195
    private XSSFRow createParentObjects() {
196
        XSSFWorkbook wb = new XSSFWorkbook();
197
        wb.setSharedStringSource(new DummySharedStringSource());
198
        XSSFSheet sheet = new XSSFSheet(wb);
199
        XSSFRow row = new XSSFRow(sheet);
200
        return row;
201
    }
202
    
204
    
203
    public static class DummySharedStringSource implements SharedStringSource {
205
    public static class DummySharedStringSource implements SharedStringSource {
204
        ArrayList<String> strs = new ArrayList<String>();
206
        ArrayList<String> strs = new ArrayList<String>();
Lines 214-217 Link Here
214
            return strs.size() - 1;
216
            return strs.size() - 1;
215
        }
217
        }
216
    }
218
    }
219
    
220
    public void testGetCellComment() {
221
        XSSFWorkbook workbook = new XSSFWorkbook();
222
        CTSheet ctSheet = CTSheet.Factory.newInstance();
223
        CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
224
        CTComments ctComments = CTComments.Factory.newInstance();
225
        XSSFComments sheetComments = new XSSFComments(ctComments);
226
        XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook, sheetComments);
227
        assertNotNull(sheet);
228
        
229
        // Create C10 cell
230
        Row row = sheet.createRow(9);
231
        Cell cell = row.createCell((short)2);
232
        Cell cell3 = row.createCell((short)3);
233
        
234
        
235
        // Set a comment for C10 cell
236
        CTComment ctComment = ctComments.addNewCommentList().insertNewComment(0);
237
        ctComment.setRef("C10");
238
        ctComment.setAuthorId(sheetComments.findAuthor(TEST_C10_AUTHOR));
239
        
240
        assertNotNull(sheet.getRow(9).getCell((short)2));
241
        assertNotNull(sheet.getRow(9).getCell((short)2).getCellComment());
242
        assertEquals(TEST_C10_AUTHOR, sheet.getRow(9).getCell((short)2).getCellComment().getAuthor());
243
        assertNull(sheet.getRow(9).getCell((short)3).getCellComment());
244
    }
245
    
246
    public void testSetCellComment() {
247
        XSSFWorkbook workbook = new XSSFWorkbook();
248
        CTSheet ctSheet = CTSheet.Factory.newInstance();
249
        CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
250
        CTComments ctComments = CTComments.Factory.newInstance();
251
        XSSFComments comments = new XSSFComments(ctComments);
252
        XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook, comments);
253
        assertNotNull(sheet);
254
        
255
        // Create C10 cell
256
        Row row = sheet.createRow(9);
257
        Cell cell = row.createCell((short)2);
258
        Cell cell3 = row.createCell((short)3);
259
        
260
        // Create a comment
261
        Comment comment = comments.addComment();
262
        comment.setAuthor(TEST_C10_AUTHOR);
263
        
264
        // Set a comment for C10 cell
265
        cell.setCellComment(comment);
266
        
267
        CTCell ctCell = ctWorksheet.getSheetData().getRowArray(0).getCArray(0);
268
		assertNotNull(ctCell);
269
		assertEquals("C10", ctCell.getR());
270
		long authorId = ctComments.getCommentList().getCommentArray(0).getAuthorId();
271
		assertEquals(TEST_C10_AUTHOR, comments.getAuthor(authorId));
272
    }
273
    
274
    public void testSetAsActiveCell() {
275
    	Workbook workbook = new XSSFWorkbook();
276
    	CTSheet ctSheet = CTSheet.Factory.newInstance();
277
    	CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
278
    	XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
279
    	Cell cell = sheet.createRow(0).createCell((short)0);
280
    	cell.setAsActiveCell();
281
    	
282
    	assertEquals("A1", ctWorksheet.getSheetViews().getSheetViewArray(0).getSelectionArray(0).getActiveCell());
283
    }
284
285
    private XSSFRow createParentObjects() {
286
        XSSFWorkbook wb = new XSSFWorkbook();
287
        wb.setSharedStringSource(new DummySharedStringSource());
288
        XSSFSheet sheet = new XSSFSheet(wb);
289
        XSSFRow row = new XSSFRow(sheet);
290
        return row;
291
    }
217
}
292
}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java (-8 / +20 lines)
Lines 17-23 Link Here
17
17
18
package org.apache.poi.xssf.usermodel;
18
package org.apache.poi.xssf.usermodel;
19
19
20
import org.apache.poi.xssf.usermodel.extensions.XSSFSheetComments;
20
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
21
import org.apache.poi.ss.usermodel.RichTextString;
22
import org.apache.poi.xssf.usermodel.extensions.XSSFComments;
21
import org.apache.poi.xssf.util.CellReference;
23
import org.apache.poi.xssf.util.CellReference;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAuthors;
24
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAuthors;
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
Lines 28-37 Link Here
28
30
29
public class TestXSSFComment extends TestCase {
31
public class TestXSSFComment extends TestCase {
30
    
32
    
33
	private static final String TEST_RICHTEXTSTRING = "test richtextstring";
31
	private static final String TEST_AUTHOR = "test_author";
34
	private static final String TEST_AUTHOR = "test_author";
32
35
33
	public void testConstructors() {
36
	public void testConstructors() {
34
		XSSFSheetComments sheetComments = new XSSFSheetComments();
37
		XSSFComments sheetComments = new XSSFComments();
35
		XSSFComment comment = new XSSFComment(sheetComments);
38
		XSSFComment comment = new XSSFComment(sheetComments);
36
		assertNotNull(comment);
39
		assertNotNull(comment);
37
		
40
		
Lines 41-47 Link Here
41
	}
44
	}
42
	
45
	
43
	public void testGetColumn() {
46
	public void testGetColumn() {
44
		XSSFSheetComments sheetComments = new XSSFSheetComments();
47
		XSSFComments sheetComments = new XSSFComments();
45
		CTComment ctComment = CTComment.Factory.newInstance();
48
		CTComment ctComment = CTComment.Factory.newInstance();
46
		ctComment.setRef("A1");
49
		ctComment.setRef("A1");
47
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
50
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
Lines 52-58 Link Here
52
	}
55
	}
53
	
56
	
54
	public void testGetRow() {
57
	public void testGetRow() {
55
		XSSFSheetComments sheetComments = new XSSFSheetComments();
58
		XSSFComments sheetComments = new XSSFComments();
56
		CTComment ctComment = CTComment.Factory.newInstance();
59
		CTComment ctComment = CTComment.Factory.newInstance();
57
		ctComment.setRef("A1");
60
		ctComment.setRef("A1");
58
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
61
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
Lines 69-82 Link Here
69
		ctAuthors.insertAuthor(0, TEST_AUTHOR);
72
		ctAuthors.insertAuthor(0, TEST_AUTHOR);
70
		ctComment.setAuthorId(0);
73
		ctComment.setAuthorId(0);
71
74
72
		XSSFSheetComments sheetComments = new XSSFSheetComments(ctComments);
75
		XSSFComments sheetComments = new XSSFComments(ctComments);
73
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
76
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
74
		assertNotNull(comment);
77
		assertNotNull(comment);
75
		assertEquals(TEST_AUTHOR, comment.getAuthor());
78
		assertEquals(TEST_AUTHOR, comment.getAuthor());
76
	}
79
	}
77
	
80
	
78
	public void testSetColumn() {
81
	public void testSetColumn() {
79
		XSSFSheetComments sheetComments = new XSSFSheetComments();
82
		XSSFComments sheetComments = new XSSFComments();
80
		CTComment ctComment = CTComment.Factory.newInstance();
83
		CTComment ctComment = CTComment.Factory.newInstance();
81
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
84
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
82
		comment.setColumn((short)3);
85
		comment.setColumn((short)3);
Lines 89-95 Link Here
89
	}
92
	}
90
	
93
	
91
	public void testSetRow() {
94
	public void testSetRow() {
92
		XSSFSheetComments sheetComments = new XSSFSheetComments();
95
		XSSFComments sheetComments = new XSSFComments();
93
		CTComment ctComment = CTComment.Factory.newInstance();
96
		CTComment ctComment = CTComment.Factory.newInstance();
94
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
97
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
95
		comment.setRow(20);
98
		comment.setRow(20);
Lines 102-112 Link Here
102
	}
105
	}
103
	
106
	
104
	public void testSetAuthor() {
107
	public void testSetAuthor() {
105
		XSSFSheetComments sheetComments = new XSSFSheetComments();
108
		XSSFComments sheetComments = new XSSFComments();
106
		CTComment ctComment = CTComment.Factory.newInstance();
109
		CTComment ctComment = CTComment.Factory.newInstance();
107
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
110
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
108
		comment.setAuthor(TEST_AUTHOR);
111
		comment.setAuthor(TEST_AUTHOR);
109
		assertEquals(TEST_AUTHOR, comment.getAuthor());
112
		assertEquals(TEST_AUTHOR, comment.getAuthor());
110
	}
113
	}
114
	
115
	public void testSetString() {
116
		XSSFComments sheetComments = new XSSFComments();
117
		CTComment ctComment = CTComment.Factory.newInstance();
118
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
119
		RichTextString richTextString = new HSSFRichTextString(TEST_RICHTEXTSTRING);
120
		comment.setString(richTextString);
121
		assertEquals(TEST_RICHTEXTSTRING, ctComment.getText().getT());
122
	}
111
    
123
    
112
}
124
}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (-2 / +51 lines)
Lines 18-31 Link Here
18
package org.apache.poi.xssf.usermodel;
18
package org.apache.poi.xssf.usermodel;
19
19
20
import java.util.Iterator;
20
import java.util.Iterator;
21
22
import junit.framework.TestCase;
21
import junit.framework.TestCase;
23
24
import org.apache.poi.ss.usermodel.Cell;
22
import org.apache.poi.ss.usermodel.Cell;
25
import org.apache.poi.ss.usermodel.Row;
23
import org.apache.poi.ss.usermodel.Row;
26
import org.apache.poi.ss.usermodel.Sheet;
24
import org.apache.poi.ss.usermodel.Sheet;
25
import org.apache.poi.ss.usermodel.Workbook;
26
import org.apache.poi.xssf.usermodel.extensions.XSSFComments;
27
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
27
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
28
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
28
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
29
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
30
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
31
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
32
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
29
33
30
34
31
public class TestXSSFSheet extends TestCase {
35
public class TestXSSFSheet extends TestCase {
Lines 480-485 Link Here
480
    	assertNull(sheet6.getRow(7));
484
    	assertNull(sheet6.getRow(7));
481
    	assertEquals(8, sheet6.getPhysicalNumberOfRows());
485
    	assertEquals(8, sheet6.getPhysicalNumberOfRows());
482
    }
486
    }
487
    
488
    public void testGetCellComment() {
489
        XSSFWorkbook workbook = new XSSFWorkbook();
490
        CTSheet ctSheet = CTSheet.Factory.newInstance();
491
        CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
492
        CTComments ctComments = CTComments.Factory.newInstance();
493
        XSSFComments sheetComments = new XSSFComments(ctComments);
494
        XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook, sheetComments);
495
        assertNotNull(sheet);
496
        
497
        CTComment ctComment = ctComments.addNewCommentList().insertNewComment(0);
498
        ctComment.setRef("C10");
499
        ctComment.setAuthorId(sheetComments.findAuthor("test C10 author"));
500
        
501
        assertNotNull(sheet.getCellComment(9, 2));
502
        assertEquals("test C10 author", sheet.getCellComment(9, 2).getAuthor());
503
    }
504
    
505
    public void testSetCellComment() {
506
        XSSFWorkbook workbook = new XSSFWorkbook();
507
        CTSheet ctSheet = CTSheet.Factory.newInstance();
508
        CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
509
        XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook);
510
        Cell cell = sheet.createRow(0).createCell((short)0);
511
        CTComments ctComments = CTComments.Factory.newInstance();
512
        XSSFComments comments = new XSSFComments(ctComments);
513
        XSSFComment comment = comments.addComment();
514
        
515
        sheet.setCellComment("A1", comment);
516
        assertEquals("A1", ctComments.getCommentList().getCommentArray(0).getRef());
517
        comment.setAuthor("test A1 author");
518
        assertEquals("test A1 author", comments.getAuthor(ctComments.getCommentList().getCommentArray(0).getAuthorId()));
519
    }
520
    
521
    public void testGetActiveCell() {
522
    	Workbook workbook = new XSSFWorkbook();
523
    	CTSheet ctSheet = CTSheet.Factory.newInstance();
524
    	CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
525
    	XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
526
    	ctWorksheet.addNewSheetViews().addNewSheetView().addNewSelection().setActiveCell("R5");
527
    	
528
    	assertEquals("R5", sheet.getActiveCell());
529
    	
530
    }
531
    
483
532
484
	private XSSFSheet createSheet(XSSFWorkbook workbook, String name) {
533
	private XSSFSheet createSheet(XSSFWorkbook workbook, String name) {
485
        XSSFSheet sheet = (XSSFSheet) workbook.createSheet(name);
534
        XSSFSheet sheet = (XSSFSheet) workbook.createSheet(name);

Return to bug 44566