Search in sources :

Example 1 with SCLRecord

use of org.apache.poi.hssf.record.SCLRecord in project poi by apache.

the class HSSFSheet method setZoom.

/**
     * Sets the zoom magnification for the sheet.  The zoom is expressed as a
     * fraction.  For example to express a zoom of 75% use 3 for the numerator
     * and 4 for the denominator.
     *
     * @param numerator   The numerator for the zoom magnification.
     * @param denominator The denominator for the zoom magnification.
     * @see #setZoom(int)
     */
public void setZoom(int numerator, int denominator) {
    if (numerator < 1 || numerator > 65535)
        throw new IllegalArgumentException("Numerator must be greater than 0 and less than 65536");
    if (denominator < 1 || denominator > 65535)
        throw new IllegalArgumentException("Denominator must be greater than 0 and less than 65536");
    SCLRecord sclRecord = new SCLRecord();
    sclRecord.setNumerator((short) numerator);
    sclRecord.setDenominator((short) denominator);
    getSheet().setSCLRecord(sclRecord);
}
Also used : SCLRecord(org.apache.poi.hssf.record.SCLRecord)

Example 2 with SCLRecord

use of org.apache.poi.hssf.record.SCLRecord in project poi by apache.

the class HSSFChart method createSCLRecord.

private SCLRecord createSCLRecord(short numerator, short denominator) {
    SCLRecord r = new SCLRecord();
    r.setDenominator(denominator);
    r.setNumerator(numerator);
    return r;
}
Also used : SCLRecord(org.apache.poi.hssf.record.SCLRecord)

Example 3 with SCLRecord

use of org.apache.poi.hssf.record.SCLRecord in project poi by apache.

the class TestHSSFSheet method zoom.

@SuppressWarnings("deprecation")
@Test
public void zoom() throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    assertEquals(-1, sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid));
    sheet.setZoom(75);
    assertTrue(sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid) > 0);
    SCLRecord sclRecord = (SCLRecord) sheet.getSheet().findFirstRecordBySid(SCLRecord.sid);
    assertEquals(75, 100 * sclRecord.getNumerator() / sclRecord.getDenominator());
    int sclLoc = sheet.getSheet().findFirstRecordLocBySid(SCLRecord.sid);
    int window2Loc = sheet.getSheet().findFirstRecordLocBySid(WindowTwoRecord.sid);
    assertTrue(sclLoc == window2Loc + 1);
    // verify limits
    try {
        sheet.setZoom(0);
        fail("Should catch Exception here");
    } catch (IllegalArgumentException e) {
        assertEquals("Numerator must be greater than 0 and less than 65536", e.getMessage());
    }
    try {
        sheet.setZoom(65536);
        fail("Should catch Exception here");
    } catch (IllegalArgumentException e) {
        assertEquals("Numerator must be greater than 0 and less than 65536", e.getMessage());
    }
    try {
        sheet.setZoom(2, 0);
        fail("Should catch Exception here");
    } catch (IllegalArgumentException e) {
        assertEquals("Denominator must be greater than 0 and less than 65536", e.getMessage());
    }
    try {
        sheet.setZoom(2, 65536);
        fail("Should catch Exception here");
    } catch (IllegalArgumentException e) {
        assertEquals("Denominator must be greater than 0 and less than 65536", e.getMessage());
    }
    wb.close();
}
Also used : SCLRecord(org.apache.poi.hssf.record.SCLRecord) Test(org.junit.Test)

Aggregations

SCLRecord (org.apache.poi.hssf.record.SCLRecord)3 Test (org.junit.Test)1