FileDocCategorySizeDatePackage
ReadWriteWorkbook.javaAPI DocApache Poi 3.0.12594Mon Jan 01 12:39:42 GMT 2007org.apache.poi.hssf.usermodel.examples

ReadWriteWorkbook

public class ReadWriteWorkbook extends Object
This example demonstrates opening a workbook, modifying it and writing the results back out.
author
Glen Stampoultzis (glens at apache.org)

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        FileInputStream fileIn = null;
        FileOutputStream fileOut = null;

        try
        {
            fileIn = new FileInputStream("workbook.xls");
            POIFSFileSystem fs = new POIFSFileSystem(fileIn);
            HSSFWorkbook wb = new HSSFWorkbook(fs);
            HSSFSheet sheet = wb.getSheetAt(0);
            HSSFRow row = sheet.getRow(2);
            if (row == null)
                row = sheet.createRow(2);
            HSSFCell cell = row.getCell((short)3);
            if (cell == null)
                cell = row.createCell((short)3);
            cell.setCellType(HSSFCell.CELL_TYPE_STRING);
            cell.setCellValue("a test");

            // Write the output to a file
            fileOut = new FileOutputStream("workbookout.xls");
            wb.write(fileOut);
        }
        finally
        {
            if (fileOut != null)
                fileOut.close();
            if (fileIn != null)
                fileIn.close();
        }