Package org.apache.poi.hssf.model

Examples of org.apache.poi.hssf.model.Sheet


    public void testProtectSheet() {
        short expected = (short)0xfef1;
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet s = wb.createSheet();
        s.protectSheet("abcdefghij");
        Sheet sheet = s.getSheet();
        ProtectRecord protect = sheet.getProtect();
        PasswordRecord pass = sheet.getPassword();
        assertTrue("protection should be on",protect.getProtect());
        assertTrue("object protection should be on",sheet.isProtected()[1]);
        assertTrue("scenario protection should be on",sheet.isProtected()[2]);
        assertEquals("well known value for top secret hash should be "+Integer.toHexString(expected).substring(4),expected,pass.getPassword());
    }
View Full Code Here


        FormulaShifter shifter = FormulaShifter.createForRowShift(externSheetIndex, startRow, endRow, n);
        sheet.updateFormulasAfterCellShift(shifter, externSheetIndex);

        int nSheets = workbook.getNumberOfSheets();
        for(int i=0; i<nSheets; i++) {
            Sheet otherSheet = workbook.getSheetAt(i).getSheet();
            if (otherSheet == this.sheet) {
                continue;
            }
            short otherExtSheetIx = book.checkExternSheet(i);
            otherSheet.updateFormulasAfterCellShift(shifter, otherExtSheetIx);
        }
        // TODO - adjust formulas in named ranges
    }
View Full Code Here

    //read in sample
    HSSFWorkbook book = openSample("Simple.xls");
   
    //check initial position
    HSSFSheet umSheet = book.getSheetAt(0);
    Sheet s = umSheet.getSheet();
    assertEquals("Initial active cell should be in col 0",
      (short) 0, s.getActiveCellCol());
    assertEquals("Initial active cell should be on row 1",
      1, s.getActiveCellRow());
   
    //modify position through HSSFCell
    HSSFCell cell = umSheet.createRow(3).createCell(2);
    cell.setAsActiveCell();
    assertEquals("After modify, active cell should be in col 2",
      (short) 2, s.getActiveCellCol());
    assertEquals("After modify, active cell should be on row 3",
      3, s.getActiveCellRow());
   
    //write book to temp file; read and verify that position is serialized
    book = writeOutAndReadBack(book);

    umSheet = book.getSheetAt(0);
    s = umSheet.getSheet();
   
    assertEquals("After serialize, active cell should be in col 2",
      (short) 2, s.getActiveCellCol());
    assertEquals("After serialize, active cell should be on row 3",
      3, s.getActiveCellRow());
  }
View Full Code Here

        // convert all LabelRecord records to LabelSSTRecord
        convertLabelRecords(records, recOffset);
        RecordStream rs = new RecordStream(records, recOffset);
        while (rs.hasNext()) {
            Sheet sheet = Sheet.createSheet(rs);
            _sheets.add(new HSSFSheet(this, sheet));
        }

        for (int i = 0 ; i < workbook.getNumNames() ; ++i){
            HSSFName name = new HSSFName(this, workbook.getNameRecord(i));
View Full Code Here

     * errors are particularly hard to track down.  This test ensures that HSSFWorkbook throws
     * a specific exception as soon as the situation is detected. See bugzilla 45066
     */
    public void testSheetSerializeSizeMismatch_bug45066() {
        HSSFWorkbook wb = new HSSFWorkbook();
        Sheet sheet = wb.createSheet("Sheet1").getSheet();
        List<RecordBase> sheetRecords = sheet.getRecords();
        // one way (of many) to cause the discrepancy is with a badly behaved record:
        sheetRecords.add(new BadlyBehavedRecord());
        // There is also much logic inside Sheet that (if buggy) might also cause the discrepancy
        try {
            wb.getBytes();
View Full Code Here

    public void testBackupRecord()
            throws Exception
    {
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet s = wb.createSheet();
        Sheet sheet = s.getSheet();

        assertEquals(true, sheet.getGridsetRecord().getGridset());
        s.setGridsPrinted(true);
        assertEquals(false, sheet.getGridsetRecord().getGridset());
    }
View Full Code Here

    public void testVerticallyCenter()
            throws Exception
    {
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet s = wb.createSheet();
        Sheet sheet = s.getSheet();
        VCenterRecord record =
                (VCenterRecord) sheet.findFirstRecordBySid(VCenterRecord.sid);

        assertEquals(false, record.getVCenter());
        s.setVerticallyCenter(true);
        assertEquals(true, record.getVCenter());
View Full Code Here

    public void testHorizontallyCenter()
            throws Exception
    {
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet s = wb.createSheet();
        Sheet sheet = s.getSheet();
        HCenterRecord record =
                (HCenterRecord) sheet.findFirstRecordBySid(HCenterRecord.sid);

        assertEquals(false, record.getHCenter());
        s.setHorizontallyCenter(true);
        assertEquals(true, record.getHCenter());
View Full Code Here

    public void testWSBool()
    {
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet s = wb.createSheet();
        Sheet sheet = s.getSheet();
        WSBoolRecord record =
                (WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);

        // Check defaults
        assertEquals(true, record.getAlternateExpression());
        assertEquals(true, record.getAlternateFormula());
        assertEquals(false, record.getAutobreaks());
View Full Code Here

   * Test that the ProtectRecord is included when creating or cloning a sheet
   */
  public void testProtect() {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet hssfSheet = workbook.createSheet();
    Sheet sheet = hssfSheet.getSheet();
    ProtectRecord protect = sheet.getProtect();
    
    assertFalse(protect.getProtect());

    // This will tell us that cloneSheet, and by extension,
    // the list forms of createSheet leave us with an accessible
    // ProtectRecord.
    hssfSheet.setProtect(true);
    Sheet cloned = sheet.cloneSheet();
    assertNotNull(cloned.getProtect());
    assertTrue(hssfSheet.getProtect());
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.model.Sheet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.