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

(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java (+88 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;
18
19
import org.apache.poi.ss.usermodel.Comment;
20
import org.apache.poi.ss.usermodel.RichTextString;
21
import org.apache.poi.xssf.usermodel.extensions.XSSFSheetComments;
22
import org.apache.poi.xssf.util.CellReference;
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
24
25
public class XSSFComment implements Comment {
26
	
27
	private CTComment comment;
28
	private XSSFSheetComments sheetComments;
29
30
	public XSSFComment(XSSFSheetComments sheetComments, CTComment comment) {
31
		this.comment = comment;
32
		this.sheetComments = sheetComments;
33
	}
34
35
	public XSSFComment(XSSFSheetComments sheetComments) {
36
		this(sheetComments, CTComment.Factory.newInstance());
37
	}
38
39
	public String getAuthor() {
40
		return sheetComments.getAuthor(comment.getAuthorId());
41
	}
42
43
	public short getColumn() {
44
		return (new CellReference(comment.getRef())).getCol();
45
	}
46
47
	public int getRow() {
48
		return (new CellReference(comment.getRef())).getRow();
49
	}
50
51
	public boolean isVisible() {
52
		// TODO Auto-generated method stub
53
		return false;
54
	}
55
56
	public void setAuthor(String author) {
57
		sheetComments.findAuthor(author);
58
	}
59
60
	public void setColumn(short col) {
61
		initializeRef();
62
		String newRef = (new CellReference(comment.getRef())).convertRowColToString((short) getRow(), col);
63
		comment.setRef(newRef);
64
	}
65
66
	private void initializeRef() {
67
		if (comment.getRef() == null) {
68
			comment.setRef("A1");
69
		}
70
	}
71
72
	public void setRow(int row) {
73
		initializeRef();
74
		String newRef = (new CellReference(comment.getRef())).convertRowColToString((short) row, getColumn());
75
		comment.setRef(newRef);
76
	}
77
78
	public void setString(RichTextString string) {
79
		// TODO Auto-generated method stub
80
81
	}
82
83
	public void setVisible(boolean visible) {
84
		// TODO Auto-generated method stub
85
86
	}
87
88
}
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (-4 / +30 lines)
Lines 34-39 Link Here
34
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
34
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
35
import org.apache.poi.xssf.util.CellReference;
35
import org.apache.poi.xssf.util.CellReference;
36
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBreak;
36
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBreak;
37
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
37
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
38
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
38
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
39
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
39
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
40
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
Lines 55-60 Link Here
55
    protected CTSheet sheet;
56
    protected CTSheet sheet;
56
    protected CTWorksheet worksheet;
57
    protected CTWorksheet worksheet;
57
    protected CTDialogsheet dialogsheet;
58
    protected CTDialogsheet dialogsheet;
59
    protected CTComment comment;
58
    protected List<Row> rows;
60
    protected List<Row> rows;
59
    protected ColumnHelper columnHelper;
61
    protected ColumnHelper columnHelper;
60
    protected XSSFWorkbook workbook;
62
    protected XSSFWorkbook workbook;
Lines 761-774 Link Here
761
    }
763
    }
762
764
763
    public void shiftRows(int startRow, int endRow, int n) {
765
    public void shiftRows(int startRow, int endRow, int n) {
764
        // TODO Auto-generated method stub
766
    	shiftRows(startRow, endRow, n, false, false);
765
766
    }
767
    }
767
768
768
    public void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight) {
769
    public void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight) {
769
        // TODO Auto-generated method stub
770
        for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
770
771
        	Row row = it.next();
772
        	if (!copyRowHeight) {
773
        		row.setHeight((short)0);
774
        	}
775
        	if (resetOriginalRowHeight && getDefaultRowHeight() >= 0) {
776
        		row.setHeight(getDefaultRowHeight());
777
        	}
778
        	if (removeRow(startRow, endRow, n, row.getRowNum())) {
779
        		it.remove();
780
        	}
781
        	else if (row.getRowNum() >= startRow && row.getRowNum() <= endRow) {
782
        		row.setRowNum(row.getRowNum() + n);
783
        	}
784
        }
771
    }
785
    }
786
    
787
    private boolean removeRow(int startRow, int endRow, int n, int rownum) {
788
    	if (rownum >= (startRow + n) && rownum <= (endRow + n)) {
789
    		if (n > 0 && rownum > endRow) {
790
    			return true;
791
    		}
792
    		else if (n < 0 && rownum < startRow) {
793
    			return true;
794
    		}
795
    	}
796
    	return false;
797
    }
772
798
773
    public void showInPane(short toprow, short leftcol) {
799
    public void showInPane(short toprow, short leftcol) {
774
    	CellReference cellReference = new CellReference();
800
    	CellReference cellReference = new CellReference();
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFSheetComments.java (+60 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.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/XSSFDialogsheet.java (-1 lines)
Lines 23-29 Link Here
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
24
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
24
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
26
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetUpPr;
27
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPrintOptions;
26
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPrintOptions;
28
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
27
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
29
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
28
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFHeaderFooter.java (-50 lines)
Lines 1-50 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;
19
20
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
21
22
import junit.framework.TestCase;
23
24
25
public class TestXSSFHeaderFooter extends TestCase {
26
    
27
    public void testGetSetCenterLeftRight() {
28
        
29
        XSSFOddFooter footer = new XSSFOddFooter(CTHeaderFooter.Factory.newInstance());
30
        assertEquals("", footer.getCenter());
31
        footer.setCenter("My first center section");
32
        assertEquals("My first center section", footer.getCenter());
33
        footer.setCenter("No, let's update the center section");
34
        assertEquals("No, let's update the center section", footer.getCenter());
35
        footer.setLeft("And add a left one");
36
        footer.setRight("Finally the right section is added");
37
        assertEquals("And add a left one", footer.getLeft());
38
        assertEquals("Finally the right section is added", footer.getRight());
39
        
40
        // Test changing the three sections value
41
        footer.setCenter("Second center version");
42
        footer.setLeft("Second left version");
43
        footer.setRight("Second right version");
44
        assertEquals("Second center version", footer.getCenter());
45
        assertEquals("Second left version", footer.getLeft());
46
        assertEquals("Second right version", footer.getRight());
47
        
48
    }
49
    
50
}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFSheetComments.java (+39 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.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/TestXSSFHeaderFooter.java (+51 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.XSSFOddFooter;
21
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
22
23
import junit.framework.TestCase;
24
25
26
public class TestXSSFHeaderFooter extends TestCase {
27
    
28
    public void testGetSetCenterLeftRight() {
29
        
30
        XSSFOddFooter footer = new XSSFOddFooter(CTHeaderFooter.Factory.newInstance());
31
        assertEquals("", footer.getCenter());
32
        footer.setCenter("My first center section");
33
        assertEquals("My first center section", footer.getCenter());
34
        footer.setCenter("No, let's update the center section");
35
        assertEquals("No, let's update the center section", footer.getCenter());
36
        footer.setLeft("And add a left one");
37
        footer.setRight("Finally the right section is added");
38
        assertEquals("And add a left one", footer.getLeft());
39
        assertEquals("Finally the right section is added", footer.getRight());
40
        
41
        // Test changing the three sections value
42
        footer.setCenter("Second center version");
43
        footer.setLeft("Second left version");
44
        footer.setRight("Second right version");
45
        assertEquals("Second center version", footer.getCenter());
46
        assertEquals("Second left version", footer.getLeft());
47
        assertEquals("Second right version", footer.getRight());
48
        
49
    }
50
    
51
}
0
  + text/plain
52
  + text/plain
1
  + Date Revision Author HeadURL Id
53
  + Date Revision Author HeadURL Id
2
  + native
54
  + native
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFComment.java (+112 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;
19
20
import org.apache.poi.xssf.usermodel.extensions.XSSFSheetComments;
21
import org.apache.poi.xssf.util.CellReference;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAuthors;
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
24
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
25
26
import junit.framework.TestCase;
27
28
29
public class TestXSSFComment extends TestCase {
30
    
31
	private static final String TEST_AUTHOR = "test_author";
32
33
	public void testConstructors() {
34
		XSSFSheetComments sheetComments = new XSSFSheetComments();
35
		XSSFComment comment = new XSSFComment(sheetComments);
36
		assertNotNull(comment);
37
		
38
		CTComment ctComment = CTComment.Factory.newInstance();
39
		XSSFComment comment2 = new XSSFComment(sheetComments, ctComment);
40
		assertNotNull(comment2);
41
	}
42
	
43
	public void testGetColumn() {
44
		XSSFSheetComments sheetComments = new XSSFSheetComments();
45
		CTComment ctComment = CTComment.Factory.newInstance();
46
		ctComment.setRef("A1");
47
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
48
		assertNotNull(comment);
49
		assertEquals(0, comment.getColumn());
50
		ctComment.setRef("C10");
51
		assertEquals(2, comment.getColumn());
52
	}
53
	
54
	public void testGetRow() {
55
		XSSFSheetComments sheetComments = new XSSFSheetComments();
56
		CTComment ctComment = CTComment.Factory.newInstance();
57
		ctComment.setRef("A1");
58
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
59
		assertNotNull(comment);
60
		assertEquals(0, comment.getRow());
61
		ctComment.setRef("C10");
62
		assertEquals(9, comment.getRow());
63
	}
64
	
65
	public void testGetAuthor() {
66
		CTComments ctComments = CTComments.Factory.newInstance();
67
		CTComment ctComment = ctComments.addNewCommentList().addNewComment();
68
		CTAuthors ctAuthors = ctComments.addNewAuthors();
69
		ctAuthors.insertAuthor(0, TEST_AUTHOR);
70
		ctComment.setAuthorId(0);
71
72
		XSSFSheetComments sheetComments = new XSSFSheetComments(ctComments);
73
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
74
		assertNotNull(comment);
75
		assertEquals(TEST_AUTHOR, comment.getAuthor());
76
	}
77
	
78
	public void testSetColumn() {
79
		XSSFSheetComments sheetComments = new XSSFSheetComments();
80
		CTComment ctComment = CTComment.Factory.newInstance();
81
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
82
		comment.setColumn((short)3);
83
		assertEquals(3, comment.getColumn());
84
		assertEquals(3, (new CellReference(ctComment.getRef()).getCol()));
85
		assertEquals("D1", ctComment.getRef());
86
87
		comment.setColumn((short)13);
88
		assertEquals(13, comment.getColumn());
89
	}
90
	
91
	public void testSetRow() {
92
		XSSFSheetComments sheetComments = new XSSFSheetComments();
93
		CTComment ctComment = CTComment.Factory.newInstance();
94
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
95
		comment.setRow(20);
96
		assertEquals(20, comment.getRow());
97
		assertEquals(20, (new CellReference(ctComment.getRef()).getRow()));
98
		assertEquals("A21", ctComment.getRef());
99
100
		comment.setRow(19);
101
		assertEquals(19, comment.getRow());
102
	}
103
	
104
	public void testSetAuthor() {
105
		XSSFSheetComments sheetComments = new XSSFSheetComments();
106
		CTComment ctComment = CTComment.Factory.newInstance();
107
		XSSFComment comment = new XSSFComment(sheetComments, ctComment);
108
		comment.setAuthor(TEST_AUTHOR);
109
		assertEquals(TEST_AUTHOR, comment.getAuthor());
110
	}
111
    
112
}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (-3 / +92 lines)
Lines 26-34 Link Here
26
import org.apache.poi.ss.usermodel.Sheet;
26
import org.apache.poi.ss.usermodel.Sheet;
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.CTDialogsheet;
30
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
31
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
32
29
33
30
34
public class TestXSSFSheet extends TestCase {
31
public class TestXSSFSheet extends TestCase {
Lines 115-120 Link Here
115
        // Set a new default row height in twips and test getting the value in points
112
        // Set a new default row height in twips and test getting the value in points
116
        sheet.setDefaultRowHeight((short) 360);
113
        sheet.setDefaultRowHeight((short) 360);
117
        assertEquals((float) 18, sheet.getDefaultRowHeightInPoints());
114
        assertEquals((float) 18, sheet.getDefaultRowHeightInPoints());
115
        // Test that defaultRowHeight is a truncated short: E.G. 360inPoints -> 18; 361inPoints -> 18
116
        sheet.setDefaultRowHeight((short) 361);
117
        assertEquals((float) 18, sheet.getDefaultRowHeightInPoints());
118
        // Set a new default row height in points and test getting the value in twips
118
        // Set a new default row height in points and test getting the value in twips
119
        sheet.setDefaultRowHeightInPoints((short) 17);
119
        sheet.setDefaultRowHeightInPoints((short) 17);
120
        assertEquals((short) 340, sheet.getDefaultRowHeight());
120
        assertEquals((short) 340, sheet.getDefaultRowHeight());
Lines 416-419 Link Here
416
        assertEquals((short) 2, sheet.getTopRow());
416
        assertEquals((short) 2, sheet.getTopRow());
417
        assertEquals((short) 26, sheet.getLeftCol());
417
        assertEquals((short) 26, sheet.getLeftCol());
418
    }
418
    }
419
    
420
    public void testShiftRows() {
421
        XSSFWorkbook workbook = new XSSFWorkbook();
422
        
423
        XSSFSheet sheet = (XSSFSheet) createSheet(workbook, "Sheet 1");
424
    	sheet.shiftRows(1, 2, 4, true, false);
425
    	assertEquals((short) 1, sheet.getRow(5).getHeight());
426
    	assertEquals((short) 2, sheet.getRow(6).getHeight());
427
    	assertNull(sheet.getRow(1));
428
    	assertNull(sheet.getRow(2));
429
    	assertEquals(8, sheet.getPhysicalNumberOfRows());
430
431
        XSSFSheet sheet2 = (XSSFSheet) createSheet(workbook, "Sheet 2");
432
    	sheet2.shiftRows(1, 5, 3, true, false);
433
    	assertEquals((short) 1, sheet2.getRow(4).getHeight());
434
    	assertEquals((short) 2, sheet2.getRow(5).getHeight());
435
    	assertEquals((short) 3, sheet2.getRow(6).getHeight());
436
    	assertEquals((short) 4, sheet2.getRow(7).getHeight());
437
    	assertEquals((short) 5, sheet2.getRow(8).getHeight());
438
    	assertNull(sheet2.getRow(1));
439
    	assertNull(sheet2.getRow(2));
440
    	assertNull(sheet2.getRow(3));
441
    	assertEquals(7, sheet2.getPhysicalNumberOfRows());
442
443
        XSSFSheet sheet3 = (XSSFSheet) createSheet(workbook, "Sheet 3");
444
    	sheet3.shiftRows(5, 7, -3, true, false);
445
    	assertEquals(5, sheet3.getRow(2).getHeight());
446
    	assertEquals(6, sheet3.getRow(3).getHeight());
447
    	assertEquals(7, sheet3.getRow(4).getHeight());
448
    	assertNull(sheet3.getRow(5));
449
    	assertNull(sheet3.getRow(6));
450
    	assertNull(sheet3.getRow(7));
451
    	assertEquals(7, sheet3.getPhysicalNumberOfRows());
452
453
        XSSFSheet sheet4 = (XSSFSheet) createSheet(workbook, "Sheet 4");
454
    	sheet4.shiftRows(5, 7, -2, true, false);
455
    	assertEquals(5, sheet4.getRow(3).getHeight());
456
    	assertEquals(6, sheet4.getRow(4).getHeight());
457
    	assertEquals(7, sheet4.getRow(5).getHeight());
458
    	assertNull(sheet4.getRow(6));
459
    	assertNull(sheet4.getRow(7));
460
    	assertEquals(8, sheet4.getPhysicalNumberOfRows());
461
462
    	// Test without copying rowHeight
463
        XSSFSheet sheet5 = (XSSFSheet) createSheet(workbook, "Sheet 5");
464
    	sheet5.shiftRows(5, 7, -2, false, false);
465
    	assertEquals(-1, sheet5.getRow(3).getHeight());
466
    	assertEquals(-1, sheet5.getRow(4).getHeight());
467
    	assertEquals(-1, sheet5.getRow(5).getHeight());
468
    	assertNull(sheet5.getRow(6));
469
    	assertNull(sheet5.getRow(7));
470
    	assertEquals(8, sheet5.getPhysicalNumberOfRows());
471
472
    	// Test without copying rowHeight and resetting to default height
473
        XSSFSheet sheet6 = (XSSFSheet) createSheet(workbook, "Sheet 6");
474
        sheet6.setDefaultRowHeight((short) 200);
475
    	sheet6.shiftRows(5, 7, -2, false, true);
476
    	assertEquals(200, sheet6.getRow(3).getHeight());
477
    	assertEquals(200, sheet6.getRow(4).getHeight());
478
    	assertEquals(200, sheet6.getRow(5).getHeight());
479
    	assertNull(sheet6.getRow(6));
480
    	assertNull(sheet6.getRow(7));
481
    	assertEquals(8, sheet6.getPhysicalNumberOfRows());
482
    }
483
484
	private XSSFSheet createSheet(XSSFWorkbook workbook, String name) {
485
        XSSFSheet sheet = (XSSFSheet) workbook.createSheet(name);
486
    	Row row0 = sheet.createRow(0);
487
    	row0.setHeight((short) 1);
488
    	Row row1 = sheet.createRow(1);
489
    	row1.setHeight((short) 1);
490
    	Row row2 = sheet.createRow(2);
491
    	row2.setHeight((short) 2);
492
    	Row row3 = sheet.createRow(3);
493
    	row3.setHeight((short) 3);
494
    	Row row4 = sheet.createRow(4);
495
    	row4.setHeight((short) 4);
496
    	Row row5 = sheet.createRow(5);
497
    	row5.setHeight((short) 5);
498
    	Row row6 = sheet.createRow(6);
499
    	row6.setHeight((short) 6);
500
    	Row row7 = sheet.createRow(7);
501
    	row7.setHeight((short) 7);
502
    	Row row8 = sheet.createRow(8);
503
    	row8.setHeight((short) 8);
504
    	Row row9 = sheet.createRow(9);
505
    	row9.setHeight((short) 9);
506
    	return sheet;
507
	}
419
}
508
}

Return to bug 44535