/* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache POI" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache POI", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ /* * TestCellStyle.java * * Created on December 11, 2001, 5:51 PM */ package org.apache.poi.hssf.usermodel; import java.io.*; import java.util.*; import junit.framework.*; /** * Class to test header footer functionality * * @author Andrew C. Oliver * @author Shawn Laubach */ public class TestHeadersFootersPrintSetup extends TestCase { /** Creates a new instance of TestHeadersFootersPrintSetup */ public TestHeadersFootersPrintSetup(String name) { super(name); } /** * TEST NAME: Test Write Sheet HeadersFooters

* OBJECTIVE: Test that HSSF can create a simple spreadsheet with numeric and string values and should print the HeadersFooters.

* SUCCESS: HSSF creates a sheet. Filesize matches a known good. HSSFSheet objects * Last row, first row is tested against the correct values (99,0).

* FAILURE: HSSF does not create a sheet or excepts. Filesize does not match the known good. * HSSFSheet last row or first row is incorrect.

* */ public void testWriteSheetHeadersFooters() throws IOException { File file = File.createTempFile("testWriteSheetHeadersFooters", ".xls"); FileOutputStream out = new FileOutputStream(file); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s = wb.createSheet(); HSSFRow r = null; HSSFCell c = null; HSSFHeader h = null; HSSFFooter f = null; for (short rownum = ( short ) 0; rownum < 100; rownum++) { r = s.createRow(rownum); // r.setRowNum(( short ) rownum); for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2) { c = r.createCell(cellnum); c.setCellValue(rownum * 10000 + cellnum + ((( double ) rownum / 1000) + (( double ) cellnum / 10000))); c = r.createCell(( short ) (cellnum + 1)); c.setCellValue("TEST"); } } h = s.getHeader(); h.setCenter("Tab: " + HSSFHeader.tab()); h.setLeft("Date: " + HSSFHeader.date()); h.setRight("Time: " + HSSFHeader.time()); f = s.getFooter(); f.setCenter("Pages: " + HSSFFooter.fontSize((short)25) + HSSFFooter.numPages()); f.setLeft("File: " + HSSFFooter.file()); f.setRight("Page: " + HSSFFooter.page()); wb.write(out); out.close(); assertEquals("FILE LENGTH == 87040", file.length(), 87040); assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); // assert((s.getLastRowNum() == 99)); } /** * TEST NAME: Test Write Sheet Width Landscape

* OBJECTIVE: Test that HSSF can create a simple spreadsheet with numeric and string values and should print the Width Landscape.

* SUCCESS: HSSF creates a sheet. Filesize matches a known good. HSSFSheet objects * Last row, first row is tested against the correct values (99,0).

* FAILURE: HSSF does not create a sheet or excepts. Filesize does not match the known good. * HSSFSheet last row or first row is incorrect.

* */ public void testWriteSheetScaleLandscape() throws IOException { File file = File.createTempFile("testWriteSheetScaleLandscape", ".xls"); FileOutputStream out = new FileOutputStream(file); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s = wb.createSheet(); HSSFRow r = null; HSSFCell c = null; HSSFPrintSetup ps = null; ps = s.getPrintSetup(); ps.setLandscape(true); ps.setFitWidth((short)1); ps.setFitHeight((short)4); ps.setScale((short)26); for (short rownum = ( short ) 0; rownum < 100; rownum++) { r = s.createRow(rownum); // r.setRowNum(( short ) rownum); for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2) { c = r.createCell(cellnum); c.setCellValue(rownum * 10000 + cellnum + ((( double ) rownum / 1000) + (( double ) cellnum / 10000))); c = r.createCell(( short ) (cellnum + 1)); c.setCellValue("TEST"); } } wb.write(out); out.close(); assertEquals("FILE LENGTH == 87040", file.length(), 87040); assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); // assert((s.getLastRowNum() == 99)); } /** * TEST NAME: Test Write Sheet PagesNumbers

* OBJECTIVE: Test that HSSF can create a simple spreadsheet with numeric and string values and should print the PagesNumbers.

* SUCCESS: HSSF creates a sheet. Filesize matches a known good. HSSFSheet objects * Last row, first row is tested against the correct values (99,0).

* FAILURE: HSSF does not create a sheet or excepts. Filesize does not match the known good. * HSSFSheet last row or first row is incorrect.

* */ public void testWriteSheetPagesNumbers() throws IOException { File file = File.createTempFile("testWriteSheetPagesNumbers", ".xls"); FileOutputStream out = new FileOutputStream(file); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s = wb.createSheet(); HSSFRow r = null; HSSFCell c = null; HSSFPrintSetup ps = null; HSSFFooter f = null; ps = s.getPrintSetup(); ps.setLeftToRight(false); ps.setUsePage(true); ps.setPageStart((short)5); for (short rownum = ( short ) 0; rownum < 100; rownum++) { r = s.createRow(rownum); // r.setRowNum(( short ) rownum); for (short cellnum = ( short ) 0; cellnum < 50; cellnum += 2) { c = r.createCell(cellnum); c.setCellValue(rownum * 10000 + cellnum + ((( double ) rownum / 1000) + (( double ) cellnum / 10000))); c = r.createCell(( short ) (cellnum + 1)); c.setCellValue("TEST"); } } f = s.getFooter(); f.setCenter("Page: " + HSSFFooter.page() + "/" + HSSFFooter.numPages()); wb.write(out); out.close(); assertEquals("FILE LENGTH == 87040", file.length(), 87040); assertEquals("LAST ROW == 99", 99, s.getLastRowNum()); assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum()); // assert((s.getLastRowNum() == 99)); } public static void main(String [] ignored_args) { System.out .println("Testing org.apache.poi.hssf.usermodel.HSSFHeader"); System.out .println("Testing org.apache.poi.hssf.usermodel.HSSFFooter"); System.out .println("Testing org.apache.poi.hssf.usermodel.HSSFPrintSetup"); junit.textui.TestRunner.run(TestHeadersFootersPrintSetup.class); } }