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

(-)a/.project (-1 / +1 lines)
Lines 1-6 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
2
<projectDescription>
3
	<name>ApachePOI</name>
3
	<name>local ApachePOI</name>
4
	<comment></comment>
4
	<comment></comment>
5
	<projects>
5
	<projects>
6
	</projects>
6
	</projects>
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (+18 lines)
Lines 47-52 import org.apache.poi.util.Beta; Link Here
47
import org.apache.poi.util.Internal;
47
import org.apache.poi.util.Internal;
48
import org.apache.poi.util.LocaleUtil;
48
import org.apache.poi.util.LocaleUtil;
49
import org.apache.poi.util.Removal;
49
import org.apache.poi.util.Removal;
50
import org.apache.poi.xssf.model.CalculationChain;
50
import org.apache.poi.xssf.model.SharedStringsTable;
51
import org.apache.poi.xssf.model.SharedStringsTable;
51
import org.apache.poi.xssf.model.StylesTable;
52
import org.apache.poi.xssf.model.StylesTable;
52
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
53
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
Lines 1327-1330 public final class XSSFCell implements Cell { Link Here
1327
                "You cannot change part of an array.";
1328
                "You cannot change part of an array.";
1328
        notifyArrayFormulaChanging(msg);
1329
        notifyArrayFormulaChanging(msg);
1329
    }
1330
    }
1331
    
1332
    /***
1333
     * Moved from XSSFRow.shift(). Not sure what is purpose. 
1334
     */
1335
    public void updateCellReferencesForShifting(String msg){
1336
        if(isPartOfArrayFormulaGroup())
1337
            notifyArrayFormulaChanging(msg);
1338
        CalculationChain calcChain = getSheet().getWorkbook().getCalculationChain();
1339
        int sheetId = (int)getSheet().sheet.getSheetId();
1340
    
1341
        //remove the reference in the calculation chain
1342
        if(calcChain != null) calcChain.removeItem(sheetId, getReference());
1343
    
1344
        CTCell ctCell = getCTCell();
1345
        String r = new CellReference(getRowIndex(), getColumnIndex()).formatAsString();
1346
        ctCell.setR(r);
1347
    }
1330
}
1348
}
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java (-14 / +2 lines)
Lines 575-597 public class XSSFRow implements Row, Comparable<XSSFRow> { Link Here
575
     */
575
     */
576
    protected void shift(int n) {
576
    protected void shift(int n) {
577
        int rownum = getRowNum() + n;
577
        int rownum = getRowNum() + n;
578
        CalculationChain calcChain = _sheet.getWorkbook().getCalculationChain();
579
        int sheetId = (int)_sheet.sheet.getSheetId();
580
        String msg = "Row[rownum="+getRowNum()+"] contains cell(s) included in a multi-cell array formula. " +
578
        String msg = "Row[rownum="+getRowNum()+"] contains cell(s) included in a multi-cell array formula. " +
581
                "You cannot change part of an array.";
579
                "You cannot change part of an array.";
582
        for(Cell c : this){
580
        for(Cell c : this){
583
            XSSFCell cell = (XSSFCell)c;
581
            ((XSSFCell)c).updateCellReferencesForShifting(msg);
584
            if(cell.isPartOfArrayFormulaGroup()){
582
          }
585
                cell.notifyArrayFormulaChanging(msg);
586
            }
587
588
            //remove the reference in the calculation chain
589
            if(calcChain != null) calcChain.removeItem(sheetId, cell.getReference());
590
591
            CTCell ctCell = cell.getCTCell();
592
            String r = new CellReference(rownum, cell.getColumnIndex()).formatAsString();
593
            ctCell.setR(r);
594
        }
595
        setRowNum(rownum);
583
        setRowNum(rownum);
596
    }
584
    }
597
    
585
    
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (-3 / +6 lines)
Lines 88-93 import org.apache.poi.xssf.model.CommentsTable; Link Here
88
import org.apache.poi.xssf.usermodel.XSSFPivotTable.PivotTableReferenceConfigurator;
88
import org.apache.poi.xssf.usermodel.XSSFPivotTable.PivotTableReferenceConfigurator;
89
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
89
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
90
import org.apache.poi.xssf.usermodel.helpers.XSSFColumnShifter;
90
import org.apache.poi.xssf.usermodel.helpers.XSSFColumnShifter;
91
import org.apache.poi.xssf.usermodel.helpers.XSSFFormulaShiftingManager;
91
import org.apache.poi.xssf.usermodel.helpers.XSSFIgnoredErrorHelper;
92
import org.apache.poi.xssf.usermodel.helpers.XSSFIgnoredErrorHelper;
92
import org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter;
93
import org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter;
93
import org.apache.xmlbeans.XmlCursor;
94
import org.apache.xmlbeans.XmlCursor;
Lines 2975-2987 public class XSSFSheet extends POIXMLDocumentPart implements Sheet { Link Here
2975
    public void shiftColumns(int startColumn, int endColumn, final int n) {
2976
    public void shiftColumns(int startColumn, int endColumn, final int n) {
2976
    	XSSFVMLDrawing vml = getVMLDrawing(false);
2977
    	XSSFVMLDrawing vml = getVMLDrawing(false);
2977
       // removeOverwritten(vml, startColumn, endColumn, n);
2978
       // removeOverwritten(vml, startColumn, endColumn, n);
2978
        //doShifting(vml, startColumn, endColumn, n, false); 
2979
       // doShifting(vml, startColumn, endColumn, n, false); 
2979
        
2980
        
2980
        FormulaShifter shifter = FormulaShifter.createForItemShift(this, false, startColumn, endColumn, n);
2981
        FormulaShifter shifter = FormulaShifter.createForItemShift(this, false, startColumn, endColumn, n);
2981
        XSSFColumnShifter columnShifter = new XSSFColumnShifter(this, shifter);
2982
        XSSFColumnShifter columnShifter = new XSSFColumnShifter(this, shifter);
2982
2983
        columnShifter.shiftColumns(startColumn, endColumn, n);
2984
        //XSSFFormulaShiftingManager shiftingManager = new XSSFFormulaShiftingManager(this, shifter);
2985
        //shiftingManager.updateFormulas();
2986
        
2983
        /*columnShifter.updateNamedRanges();
2987
        /*columnShifter.updateNamedRanges();
2984
        columnShifter.updateFormulas();
2985
        columnShifter.shiftMergedRegions(startColumn, startColumn, n);
2988
        columnShifter.shiftMergedRegions(startColumn, startColumn, n);
2986
        columnShifter.updateConditionalFormatting();
2989
        columnShifter.updateConditionalFormatting();
2987
        columnShifter.updateHyperlinks();*/
2990
        columnShifter.updateHyperlinks();*/
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFVMLDrawing.java (-1 / +1 lines)
Lines 265-271 public final class XSSFVMLDrawing extends POIXMLDocumentPart { Link Here
265
     *
265
     *
266
     * @return the comment shape or <code>null</code>
266
     * @return the comment shape or <code>null</code>
267
     */
267
     */
268
    protected CTShape findCommentShape(int row, int col){
268
    public CTShape findCommentShape(int row, int col){
269
        for(XmlObject itm : _items){
269
        for(XmlObject itm : _items){
270
            if(itm instanceof CTShape){
270
            if(itm instanceof CTShape){
271
                CTShape sh = (CTShape)itm;
271
                CTShape sh = (CTShape)itm;
(-)a/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifter.java (-14 / +82 lines)
Lines 1-13 Link Here
1
package org.apache.poi.xssf.usermodel.helpers;
1
package org.apache.poi.xssf.usermodel.helpers;
2
2
3
import java.util.Comparator;
4
import java.util.Iterator;
5
import java.util.Map;
6
import java.util.SortedMap;
7
import java.util.TreeMap;
8
3
import org.apache.poi.ss.formula.FormulaShifter;
9
import org.apache.poi.ss.formula.FormulaShifter;
4
import org.apache.poi.ss.usermodel.CellType;
10
import org.apache.poi.ss.usermodel.CellType;
5
import org.apache.poi.ss.usermodel.Row;
11
import org.apache.poi.ss.usermodel.Row;
6
import org.apache.poi.ss.usermodel.Sheet;
12
import org.apache.poi.ss.usermodel.Sheet;
7
import org.apache.poi.ss.usermodel.helpers.ColumnShifter;
13
import org.apache.poi.ss.usermodel.helpers.ColumnShifter;
14
import org.apache.poi.ss.util.CellReference;
8
import org.apache.poi.util.POILogFactory;
15
import org.apache.poi.util.POILogFactory;
9
import org.apache.poi.util.POILogger;
16
import org.apache.poi.util.POILogger;
17
import org.apache.poi.xssf.model.CommentsTable;
10
import org.apache.poi.xssf.usermodel.XSSFCell;
18
import org.apache.poi.xssf.usermodel.XSSFCell;
19
import org.apache.poi.xssf.usermodel.XSSFComment;
20
import org.apache.poi.xssf.usermodel.XSSFRow;
21
import org.apache.poi.xssf.usermodel.XSSFVMLDrawing;
22
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
23
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
11
24
12
public class XSSFColumnShifter extends ColumnShifter{
25
public class XSSFColumnShifter extends ColumnShifter{
13
	
26
	
Lines 31-36 public class XSSFColumnShifter extends ColumnShifter{ Link Here
31
			shiftColumnsRight();
44
			shiftColumnsRight();
32
		//else if(shiftStep < 0)
45
		//else if(shiftStep < 0)
33
			//shiftColumnsLeft();
46
			//shiftColumnsLeft();
47
	      formulaShiftingManager.updateFormulas();
34
	}
48
	}
35
	/**
49
	/**
36
	 * Inserts shiftStep empty columns at firstShiftColumnIndex-th position, and shifts rest columns to the right 
50
	 * Inserts shiftStep empty columns at firstShiftColumnIndex-th position, and shifts rest columns to the right 
Lines 45-53 public class XSSFColumnShifter extends ColumnShifter{ Link Here
45
		    	XSSFCell oldCell = (XSSFCell)row.getCell(columnIndex);
59
		    	XSSFCell oldCell = (XSSFCell)row.getCell(columnIndex);
46
		    	if(oldCell == null)
60
		    	if(oldCell == null)
47
		    		continue;
61
		    		continue;
48
	    		if(oldCell.getCellTypeEnum() == CellType.FORMULA) // recalculate formula
49
	    			formulaShiftingManager.updateCellFormula(row, oldCell);
50
51
	    		if(columnIndex >= firstShiftColumnIndex){ // shift existing cell 
62
	    		if(columnIndex >= firstShiftColumnIndex){ // shift existing cell 
52
			    	org.apache.poi.ss.usermodel.Cell newCell = null;
63
			    	org.apache.poi.ss.usermodel.Cell newCell = null;
53
		    		newCell = row.createCell(columnIndex + shiftStep, oldCell.getCellTypeEnum());
64
		    		newCell = row.createCell(columnIndex + shiftStep, oldCell.getCellTypeEnum());
Lines 59-72 public class XSSFColumnShifter extends ColumnShifter{ Link Here
59
		    	}
70
		    	}
60
    		}
71
    		}
61
		}
72
		}
62
		formulaShiftingManager.updateFormulas();
63
	}
73
	}
64
	/*private void shiftColumnsLeft(){
74
	private void shiftColumnsLeft(){
65
		for(int rowNo = 0; rowNo <= shiftingSheet.getLastRowNum(); rowNo++)
75
		for(int rowNo = 0; rowNo <= shiftingSheet.getLastRowNum(); rowNo++)
66
		{	
76
		{	
67
			Row row = shiftingSheet.getRow(rowNo);
77
		    XSSFRow row = (XSSFRow)shiftingSheet.getRow(rowNo);
68
		    for (int columnIndex = 0; columnIndex < row.getLastCellNum(); columnIndex++){ // process cells backwards, because of shifting 
78
		    for (int columnIndex = 0; columnIndex < row.getLastCellNum(); columnIndex++){ 
69
		    	org.apache.poi.ss.usermodel.Cell oldCell = row.getCell(columnIndex);
79
		        XSSFCell oldCell = (XSSFCell)row.getCell(columnIndex);
70
		    	if(columnIndex >= firstShiftColumnIndex + shiftStep && columnIndex < row.getLastCellNum() - shiftStep){ // shift existing cell 
80
		    	if(columnIndex >= firstShiftColumnIndex + shiftStep && columnIndex < row.getLastCellNum() - shiftStep){ // shift existing cell 
71
			    	org.apache.poi.ss.usermodel.Cell newCell = null;
81
			    	org.apache.poi.ss.usermodel.Cell newCell = null;
72
		    		newCell = row.getCell(columnIndex - shiftStep);
82
		    		newCell = row.getCell(columnIndex - shiftStep);
Lines 74-81 public class XSSFColumnShifter extends ColumnShifter{ Link Here
74
			    		if(newCell != null){
84
			    		if(newCell != null){
75
			    			oldCell.setCellType(newCell.getCellType());
85
			    			oldCell.setCellType(newCell.getCellType());
76
			    			cloneCellValue(newCell, oldCell);
86
			    			cloneCellValue(newCell, oldCell);
77
				    		if(oldCell.getCellTypeEnum() == CellType.FORMULA) // recalculate formula
78
				    			columnFormulaShifter.shiftFormula(oldCell);
79
			    		}
87
			    		}
80
			    		else {
88
			    		else {
81
			    			oldCell.setCellType(CellType.STRING);
89
			    			oldCell.setCellType(CellType.STRING);
Lines 87-94 public class XSSFColumnShifter extends ColumnShifter{ Link Here
87
			    		if(newCell != null){
95
			    		if(newCell != null){
88
			    			oldCell.setCellType(newCell.getCellType());
96
			    			oldCell.setCellType(newCell.getCellType());
89
			    			cloneCellValue(newCell, oldCell);
97
			    			cloneCellValue(newCell, oldCell);
90
				    		if(oldCell.getCellTypeEnum() == CellType.FORMULA) // recalculate formula
91
				    			columnFormulaShifter.shiftFormula(oldCell);
92
			    		}
98
			    		}
93
			    		else {
99
			    		else {
94
			    			oldCell.setCellType(CellType.STRING);
100
			    			oldCell.setCellType(CellType.STRING);
Lines 98-105 public class XSSFColumnShifter extends ColumnShifter{ Link Here
98
		    	}
104
		    	}
99
    		}
105
    		}
100
		}
106
		}
101
		columnFormulaShifter.processFormulasOnOtherSheets();
107
	}
102
	}*/
103
	
108
	
104
    public static void cloneCellValue(org.apache.poi.ss.usermodel.Cell oldCell, org.apache.poi.ss.usermodel.Cell newCell) {
109
    public static void cloneCellValue(org.apache.poi.ss.usermodel.Cell oldCell, org.apache.poi.ss.usermodel.Cell newCell) {
105
	    switch (oldCell.getCellTypeEnum()) {
110
	    switch (oldCell.getCellTypeEnum()) {
Lines 123-126 public class XSSFColumnShifter extends ColumnShifter{ Link Here
123
	    }
128
	    }
124
	}
129
	}
125
130
131
    private void processComments(CommentsTable sheetComments, XSSFVMLDrawing vml, int startRow, int endRow, final int n, boolean copyRowHeight){
132
        SortedMap<XSSFComment, Integer> commentsToShift = new TreeMap<XSSFComment, Integer>(new Comparator<XSSFComment>() {
133
            @Override
134
            public int compare(XSSFComment o1, XSSFComment o2) {
135
                int column1Index = o1.getColumn();
136
                int column2Index = o2.getColumn();
137
                
138
                if(column1Index == column2Index) 
139
                    return o1.hashCode() - o2.hashCode();
140
141
                if(n > 0) // when shifting right, sort higher column-values first 
142
                    return column1Index < column2Index ? 1 : -1;
143
                else     // sort lower-column values first when shifting left
144
                    return column1Index > column2Index ? 1 : -1;
145
            }
146
        });
147
        
148
        for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
149
            XSSFRow row = (XSSFRow)it.next();
150
            int rownum = row.getRowNum();
151
152
            if(sheetComments != null){
153
                // calculate the new rownum
154
                int newrownum = shiftedRowNum(startRow, endRow, n, rownum);
155
                
156
                // is there a change necessary for the current row?
157
                if(newrownum != rownum) {
158
                    CTCommentList lst = sheetComments.getCTComments().getCommentList();
159
                    for (CTComment comment : lst.getCommentArray()) {
160
                        String oldRef = comment.getRef();
161
                        CellReference ref = new CellReference(oldRef);
162
                        
163
                        // is this comment part of the current row?
164
                        if(ref.getRow() == rownum) {
165
                            XSSFComment xssfComment = new XSSFComment(sheetComments, comment,
166
                                    vml == null ? null : vml.findCommentShape(rownum, ref.getCol()));
167
                            
168
                            // we should not perform the shifting right here as we would then find
169
                            // already shifted comments and would shift them again...
170
                            commentsToShift.put(xssfComment, newrownum);
171
                        }
172
                    }
173
                }
174
            }
175
176
            if(rownum < startRow || rownum > endRow) {
177
                continue;
178
            }
179
            if (!copyRowHeight) {
180
                row.setHeight((short)-1);
181
            }
182
            row.shift(n);
183
        }
184
        
185
        // adjust all the affected comment-structures now
186
        // the Map is sorted and thus provides them in the order that we need here, 
187
        // i.e. from down to up if shifting down, vice-versa otherwise
188
        for(Map.Entry<XSSFComment, Integer> entry : commentsToShift.entrySet()) {
189
            entry.getKey().setRow(entry.getValue());
190
        }
191
        
192
    }
193
126
}
194
}
(-)a/src/testcases/org/apache/poi/xssf/usermodel/helpers/XSSFColumnShifterTest.java (-1 / +137 lines)
Line 0 Link Here
0
- 
1
package org.apache.poi.xssf.usermodel.helpers;
2
3
import static org.junit.Assert.assertEquals;
4
5
import org.apache.poi.ss.usermodel.*;
6
import org.apache.poi.xssf.usermodel.*;
7
import org.junit.Before;
8
import org.junit.Test;
9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
11
12
public class XSSFColumnShifterTest {
13
    
14
    private static Logger log = LoggerFactory.getLogger(XSSFColumnShifterTest.class+"_T");
15
    private XSSFSheet sheet1, sheet2;
16
    private Workbook wb07;
17
    
18
    @Before
19
    public void init(){
20
        wb07 = new XSSFWorkbook();
21
        sheet1 = (XSSFSheet)wb07.createSheet("sheet1");
22
        XSSFRow row = sheet1.createRow(0);
23
        row.createCell(0, CellType.NUMERIC).setCellValue(0);
24
        row.createCell(1, CellType.NUMERIC).setCellValue(1);
25
        XSSFCell c1 =row.createCell(2, CellType.NUMERIC); 
26
        c1.setCellValue(2);
27
        c1.setCellComment("this is c1");
28
        
29
        row = sheet1.createRow(1);
30
        row.createCell(0, CellType.NUMERIC).setCellValue(0.1);
31
        row.createCell(1, CellType.NUMERIC).setCellValue(1.1);
32
        row.createCell(2, CellType.NUMERIC).setCellValue(2.1);
33
        row = sheet1.createRow(2);
34
        row.createCell(0, CellType.NUMERIC).setCellValue(0.2);
35
        row.createCell(1, CellType.NUMERIC).setCellValue(1.2);
36
        row.createCell(2, CellType.NUMERIC).setCellValue(2.2);
37
        row = sheet1.createRow(3);
38
        row.createCell(0, CellType.FORMULA).setCellFormula("A2*B3");
39
        row.createCell(1, CellType.NUMERIC).setCellValue(1.3);
40
        row.createCell(2, CellType.FORMULA).setCellFormula("B1-B3");
41
        row = sheet1.createRow(4);
42
        row.createCell(0, CellType.FORMULA).setCellFormula("SUM(C1:C4)");
43
        row.createCell(1, CellType.FORMULA).setCellFormula("SUM(A3:C3)");
44
        row.createCell(2, CellType.FORMULA).setCellFormula("$C1+C$2");
45
        row = sheet1.createRow(5);
46
        row.createCell(1, CellType.NUMERIC).setCellValue(1.5);
47
/*
48
        sheet2 = (XSSFSheet)wb07.createSheet("sheet2");
49
        row = sheet2.createRow(0);
50
        row.createCell(0, CellType.NUMERIC).setCellValue(10);
51
        row.createCell(1, CellType.NUMERIC).setCellValue(11);
52
        row.createCell(2, CellType.FORMULA).setCellFormula("SUM(Sheet1!B3:C3)");
53
        row = sheet2.createRow(1);
54
        row.createCell(0, CellType.NUMERIC).setCellValue(21);
55
        row.createCell(1, CellType.NUMERIC).setCellValue(22);
56
        row.createCell(2, CellType.NUMERIC).setCellValue(23);
57
        row = sheet2.createRow(2);
58
        row.createCell(0, CellType.FORMULA).setCellFormula("Sheet1!A4+Sheet1!C2+A2");
59
        row.createCell(1, CellType.FORMULA).setCellFormula("SUM(Sheet1!A3:$C3)");
60
        row = sheet2.createRow(3);
61
        row.createCell(0, CellType.STRING).setCellValue("dummy");
62
        */
63
        writeSheetToLog(sheet1);
64
    }
65
    
66
    @Test
67
    public void testInsertRow() {
68
        sheet1.shiftRows(1, sheet1.getLastRowNum(), 1);
69
        writeSheetToLog(sheet1);
70
        String formulaA4 = sheet1.getRow(4).getCell(0).getCellFormula();
71
        assertEquals("A3*B4", formulaA4);
72
        String formulaC4 = sheet1.getRow(4).getCell(2).getCellFormula();
73
        assertEquals("B1-B4", formulaC4);
74
        String formulaB5 = sheet1.getRow(5).getCell(1).getCellFormula();
75
        assertEquals("SUM(A4:C4)", formulaB5);
76
        String formulaC6 = sheet1.getRow(5).getCell(2).getCellFormula();
77
        assertEquals("$C1+C$3", formulaC6);
78
    }
79
    
80
    @Test
81
    public void testInsertOneColumn() {
82
        sheet1.shiftColumns(1, 2, 1);
83
        writeSheetToLog(sheet1);
84
        String formulaA4 = sheet1.getRow(3).getCell(0).getCellFormula();
85
        assertEquals("A2*C3", formulaA4);
86
        String formulaC4 = sheet1.getRow(3).getCell(3).getCellFormula();
87
        assertEquals("C1-C3", formulaC4);
88
        String formulaB5 = sheet1.getRow(4).getCell(2).getCellFormula();
89
        assertEquals("SUM(A3:D3)", formulaB5);
90
        String formulaD5 = sheet1.getRow(4).getCell(3).getCellFormula(); //$C1+C$2
91
        assertEquals("$D1+D$2", formulaD5);
92
        
93
        String newb5Empty = sheet1.getRow(4).getCell(1).getStringCellValue();
94
        assertEquals(newb5Empty, "");
95
    }
96
    
97
    @Test
98
    public void testInsertTwoColumns(){
99
        sheet1.shiftColumns(1, 2, 2);
100
        String formulaA4 = sheet1.getRow(3).getCell(0).getCellFormula();
101
        assertEquals("A2*D3", formulaA4);
102
        String formulaD4 = sheet1.getRow(3).getCell(4).getCellFormula();
103
        assertEquals("D1-D3", formulaD4);
104
        String formulaD5 = sheet1.getRow(4).getCell(3).getCellFormula();
105
        assertEquals("SUM(A3:E3)", formulaD5);
106
        
107
        String b5Empty = sheet1.getRow(4).getCell(1).getStringCellValue();
108
        assertEquals(b5Empty, "");
109
        Object c6Null = sheet1.getRow(5).getCell(2); // null cell A5 is shifted for 2 columns, so now c5 should be null
110
        assertEquals(c6Null, null);
111
    }
112
    
113
    public static void writeSheetToLog(Sheet sheet){
114
        int rowIndex = sheet.getFirstRowNum();
115
        while(rowIndex <= sheet.getLastRowNum()){
116
            Row row = sheet.getRow(rowIndex);
117
            if(row == null)
118
                log.trace("null row!");
119
            else log.trace(String.format("%1$12s; %2$12s; %3$12s; %4$12s; %5$12s; %6$12s; %7$12s; %8$12s; %9$12s; %10$12s; %11$12s", 
120
                    row.getCell(0) != null ? row.getCell(0) : "null", 
121
                    row.getCell(1) != null ? row.getCell(1) : "null", 
122
                    row.getCell(2) != null ? row.getCell(2) : "null",
123
                    row.getCell(3) != null ? row.getCell(3) : "null",
124
                    row.getCell(4) != null ? row.getCell(4) : "null",
125
                    row.getCell(5) != null ? row.getCell(5) : "null",
126
                    row.getCell(6) != null ? row.getCell(6) : "null",
127
                    row.getCell(7) != null ? row.getCell(7) : "null",
128
                    row.getCell(8) != null ? row.getCell(8) : "null",
129
                    row.getCell(9) != null ? row.getCell(9) : "null",
130
                    row.getCell(10) != null ? row.getCell(10) : "null"
131
                        ));
132
            rowIndex++;
133
        }
134
        log.trace("");
135
    }
136
    
137
}

Return to bug 61474