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

(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (-2 / +2 lines)
Lines 348-354 Link Here
348
    public short getSelectedTab() {
348
    public short getSelectedTab() {
349
        short i = 0;
349
        short i = 0;
350
        for (XSSFSheet sheet : this.sheets) {
350
        for (XSSFSheet sheet : this.sheets) {
351
            if (sheet.isTabSelected()) {
351
            if (sheet.isSelected()) {
352
                return i;
352
                return i;
353
            }
353
            }
354
            ++i;
354
            ++i;
Lines 444-450 Link Here
444
    public void setSelectedTab(short index) {
444
    public void setSelectedTab(short index) {
445
        for (int i = 0 ; i < this.sheets.size() ; ++i) {
445
        for (int i = 0 ; i < this.sheets.size() ; ++i) {
446
            XSSFSheet sheet = this.sheets.get(i);
446
            XSSFSheet sheet = this.sheets.get(i);
447
            sheet.setTabSelected(i == index);
447
            sheet.setSelected(i == index);
448
        }
448
        }
449
    }
449
    }
450
450
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (-17 / +37 lines)
Lines 44-49 Link Here
44
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
44
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
45
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
45
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
46
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr;
46
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr;
47
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection;
47
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetView;
48
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetView;
48
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews;
49
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews;
49
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
50
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
Lines 337-343 Link Here
337
    }
338
    }
338
339
339
    public short getLeftCol() {
340
    public short getLeftCol() {
340
    	// TODO no test for this method at the moment.
341
    	String cellRef = worksheet.getSheetViews().getSheetViewArray(0).getTopLeftCell();
341
    	String cellRef = worksheet.getSheetViews().getSheetViewArray(0).getTopLeftCell();
342
    	CellReference cellReference = new CellReference(cellRef);
342
    	CellReference cellReference = new CellReference(cellRef);
343
        return cellReference.getCol();
343
        return cellReference.getCol();
Lines 457-476 Link Here
457
    }
457
    }
458
458
459
    public boolean getScenarioProtect() {
459
    public boolean getScenarioProtect() {
460
        // TODO Auto-generated method stub
460
    	return getSheetTypeProtection().getScenarios();
461
        return false;
462
    }
461
    }
463
462
463
	protected CTSheetProtection getSheetTypeProtection() {
464
		if (worksheet.getSheetProtection() == null) {
465
			worksheet.setSheetProtection(CTSheetProtection.Factory.newInstance());
466
		}
467
		return worksheet.getSheetProtection();
468
	}
469
464
    public short getTopRow() {
470
    public short getTopRow() {
465
    	// TODO no test for this method at the moment.
471
    	String cellRef = getSheetTypeSheetView().getTopLeftCell();
466
    	String cellRef = worksheet.getSheetViews().getSheetViewArray(0).getTopLeftCell();
467
    	CellReference cellReference = new CellReference(cellRef);
472
    	CellReference cellReference = new CellReference(cellRef);
468
        return (short) cellReference.getRow();
473
        return (short) cellReference.getRow();
469
    }
474
    }
470
475
476
    // Right signature method. Remove the wrong one when it will be removed in HSSFSheet (and interface)
477
    public boolean getVerticallyCenter() {
478
    	return getVerticallyCenter(true);
479
    }
480
471
    public boolean getVerticallyCenter(boolean value) {
481
    public boolean getVerticallyCenter(boolean value) {
472
        // TODO Auto-generated method stub
482
    	return getSheetTypePrintOptions().getVerticalCentered();
473
        return false;
474
    }
483
    }
475
484
476
    public void groupColumn(short fromColumn, short toColumn) {
485
    public void groupColumn(short fromColumn, short toColumn) {
Lines 726-744 Link Here
726
735
727
    }
736
    }
728
737
729
    public void setSelected(boolean sel) {
738
    public void setVerticallyCenter(boolean value) {
730
        // TODO Auto-generated method stub
739
    	getSheetTypePrintOptions().setVerticalCentered(value);
740
    }
731
741
742
    // HSSFSheet compatibility methods. See also the following zoom related methods
743
    public void setZoom(int numerator, int denominator) {
744
    	setZoom((numerator/denominator) * 100);
732
    }
745
    }
733
746
734
    public void setVerticallyCenter(boolean value) {
747
    public void setZoom(long scale) {
735
        // TODO Auto-generated method stub
748
    	getSheetTypeSheetView().setZoomScale(scale);
749
    }
736
750
751
    public void setZoomNormal(long scale) {
752
    	getSheetTypeSheetView().setZoomScaleNormal(scale);
737
    }
753
    }
738
754
739
    public void setZoom(int numerator, int denominator) {
755
    public void setZoomPageLayoutView(long scale) {
740
        // TODO Auto-generated method stub
756
    	getSheetTypeSheetView().setZoomScalePageLayoutView(scale);
757
    }
741
758
759
    public void setZoomSheetLayoutView(long scale) {
760
    	getSheetTypeSheetView().setZoomScaleSheetLayoutView(scale);
742
    }
761
    }
743
762
744
    public void shiftRows(int startRow, int endRow, int n) {
763
    public void shiftRows(int startRow, int endRow, int n) {
Lines 752-759 Link Here
752
    }
771
    }
753
772
754
    public void showInPane(short toprow, short leftcol) {
773
    public void showInPane(short toprow, short leftcol) {
755
        // TODO Auto-generated method stub
774
    	CellReference cellReference = new CellReference();
756
775
    	String cellRef = cellReference.convertRowColToString(toprow, leftcol);
776
    	getSheetTypeSheetView().setTopLeftCell(cellRef);
757
    }
777
    }
758
778
759
    public void ungroupColumn(short fromColumn, short toColumn) {
779
    public void ungroupColumn(short fromColumn, short toColumn) {
Lines 766-772 Link Here
766
786
767
    }
787
    }
768
788
769
    public void setTabSelected(boolean flag) {
789
    public void setSelected(boolean flag) {
770
        CTSheetViews views = getSheetTypeSheetViews();
790
        CTSheetViews views = getSheetTypeSheetViews();
771
        for (CTSheetView view : views.getSheetViewArray()) {
791
        for (CTSheetView view : views.getSheetViewArray()) {
772
            view.setTabSelected(flag);
792
            view.setTabSelected(flag);
Lines 781-787 Link Here
781
		return worksheet.getSheetViews();
801
		return worksheet.getSheetViews();
782
	}
802
	}
783
    
803
    
784
    public boolean isTabSelected() {
804
    public boolean isSelected() {
785
        CTSheetView view = getDefaultSheetView();
805
        CTSheetView view = getDefaultSheetView();
786
        return view != null && view.getTabSelected();
806
        return view != null && view.getTabSelected();
787
    }
807
    }
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java (+8 lines)
Lines 28-33 Link Here
28
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
28
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
29
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
29
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
30
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr;
30
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr;
31
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection;
31
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews;
32
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews;
32
33
33
public class XSSFDialogsheet extends XSSFSheet implements Sheet{
34
public class XSSFDialogsheet extends XSSFSheet implements Sheet{
Lines 96-100 Link Here
96
		}
97
		}
97
		return dialogsheet.getPrintOptions();
98
		return dialogsheet.getPrintOptions();
98
	}
99
	}
100
101
	protected CTSheetProtection getSheetTypeProtection() {
102
		if (dialogsheet.getSheetProtection() == null) {
103
			dialogsheet.setSheetProtection(CTSheetProtection.Factory.newInstance());
104
		}
105
		return dialogsheet.getSheetProtection();
106
	}
99
	
107
	
100
}
108
}
(-)src/ooxml/java/org/apache/poi/xssf/util/CellReference.java (-4 / +4 lines)
Lines 85-102 Link Here
85
		double div = 1;
85
		double div = 1;
86
		double mod = 0;
86
		double mod = 0;
87
		for (int i = 0 ; div >= 1 ; i ++) {
87
		for (int i = 0 ; div >= 1 ; i ++) {
88
			System.err.println("col: " + col);
89
			mod = col % 26;
88
			mod = col % 26;
90
			div = col / 26;
89
			div = col / 26;
91
			int AsciiIncrement = (i != 0 ? 64 : 65);
90
			int AsciiIncrement = (i != 0 ? 64 : 65);
92
			char modToChar = (char)(mod + AsciiIncrement);
91
			char modToChar = (char)(mod + AsciiIncrement);
93
			System.err.println("mod: " + mod);
94
			System.err.println("div: " + div);
95
			System.err.println("modToChar: " + modToChar);
96
			colRef = modToChar + colRef;
92
			colRef = modToChar + colRef;
97
			col = (short) ((col - mod) / 26);
93
			col = (short) ((col - mod) / 26);
98
		}
94
		}
99
		return colRef;
95
		return colRef;
100
	}
96
	}
97
	
98
	public String convertRowColToString(short row, short col) {
99
		return convertNumToColString(col) + ((short) (row + 1));
100
	}
101
101
102
}
102
}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java (+16 lines)
Lines 174-179 Link Here
174
        assertFalse(sheet.getHorizontallyCenter());
174
        assertFalse(sheet.getHorizontallyCenter());
175
    }
175
    }
176
    
176
    
177
    public void testGetSetVerticallyCentered() {
178
        XSSFWorkbook workbook = new XSSFWorkbook();
179
        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
180
        assertFalse(sheet.getVerticallyCenter());
181
        sheet.setVerticallyCenter(true);
182
        assertTrue(sheet.getVerticallyCenter());
183
        sheet.setVerticallyCenter(false);
184
        assertFalse(sheet.getVerticallyCenter());
185
    }
186
    
177
    public void testIsSetPrintGridlines() {
187
    public void testIsSetPrintGridlines() {
178
        XSSFWorkbook workbook = new XSSFWorkbook();
188
        XSSFWorkbook workbook = new XSSFWorkbook();
179
        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
189
        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
Lines 205-209 Link Here
205
        sheet.setDisplayRowColHeadings(false);
215
        sheet.setDisplayRowColHeadings(false);
206
        assertFalse(sheet.isDisplayRowColHeadings());
216
        assertFalse(sheet.isDisplayRowColHeadings());
207
    }
217
    }
218
    
219
    public void testGetScenarioProtect() {
220
        XSSFWorkbook workbook = new XSSFWorkbook();
221
        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
222
        assertFalse(sheet.getScenarioProtect());
223
    }
208
	
224
	
209
}
225
}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (+27 lines)
Lines 358-363 Link Here
358
        assertFalse(sheet.getHorizontallyCenter());
358
        assertFalse(sheet.getHorizontallyCenter());
359
    }
359
    }
360
    
360
    
361
    public void testGetSetVerticallyCentered() {
362
        XSSFWorkbook workbook = new XSSFWorkbook();
363
        XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
364
        assertFalse(sheet.getVerticallyCenter());
365
        sheet.setVerticallyCenter(true);
366
        assertTrue(sheet.getVerticallyCenter());
367
        sheet.setVerticallyCenter(false);
368
        assertFalse(sheet.getVerticallyCenter());
369
    }
370
    
361
    public void testIsSetPrintGridlines() {
371
    public void testIsSetPrintGridlines() {
362
        XSSFWorkbook workbook = new XSSFWorkbook();
372
        XSSFWorkbook workbook = new XSSFWorkbook();
363
        XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
373
        XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
Lines 389-392 Link Here
389
        sheet.setDisplayRowColHeadings(false);
399
        sheet.setDisplayRowColHeadings(false);
390
        assertFalse(sheet.isDisplayRowColHeadings());
400
        assertFalse(sheet.isDisplayRowColHeadings());
391
    }
401
    }
402
    
403
    public void testGetScenarioProtect() {
404
        XSSFWorkbook workbook = new XSSFWorkbook();
405
        XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
406
        assertFalse(sheet.getScenarioProtect());
407
    }
408
    
409
    public void testTopRowLeftCol() {
410
        XSSFWorkbook workbook = new XSSFWorkbook();
411
        XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
412
        sheet.showInPane((short)1, (short)1);
413
        assertEquals((short) 1, sheet.getTopRow());
414
        assertEquals((short) 1, sheet.getLeftCol());
415
        sheet.showInPane((short)2, (short)26);
416
        assertEquals((short) 2, sheet.getTopRow());
417
        assertEquals((short) 26, sheet.getLeftCol());
418
    }
392
}
419
}

Return to bug 44535