poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ramon F Herrera <ra...@patriot.net>
Subject Trying to edit a spreadsheet using XSSF
Date Wed, 21 Apr 2010 23:27:19 GMT

Hello all,

I am using the example provided with the POI distribution 
(ReadWriteWorkBook.java, below) as a reference. It works fine, but when 
I try to port it to XSSF, the final write() statement fails.

The file is created, but seems to be corrupted.

In my next post, I will included the program as modified by me.




package org.apache.poi.hssf.usermodel.examples;

import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

  * This example demonstrates opening a workbook, modifying
  * it and writing the results back out.
  * @author Glen Stampoultzis (glens at apache.org)

public class ReadWriteWorkbook {
     public static void main(String[] args) throws IOException {
         FileInputStream fileIn = null;
         FileOutputStream fileOut = null;

             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(3);
             if (cell == null)
                 cell = row.createCell(3);
             cell.setCellValue("a test");

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

To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org

View raw message