There is a bug with how (at least hssf sometimes records workbook sizes.
In the code below I write with HSSF and then open it with jxl.
There is then a warning
Warning: Some cells exceeded the specified bounds. Resizing sheet
dimensions from 1x2 to 2x2
Note: If I Open and the Save the workbook using Excel and then just run
the jxl part there is no such warning so it is a HSSF issue.
tested with poi.3.7-20101029
=== Example code ====
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class ColumnProblem {
public static void main(String[] args) throws Exception {
File file = new File("test.xls");
/* HSSF PART */
HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
HSSFSheet hssfSheet = hssfWorkbook.createSheet("foo");
HSSFRow hssfRow = hssfSheet.createRow(1);
HSSFCell hssfCell = hssfRow.createCell(1);
hssfCell.setCellValue("Hello World");
hssfSheet = hssfWorkbook.createSheet("bar");
hssfRow = hssfSheet.createRow(1);
hssfCell = hssfRow.createCell(2);
hssfCell.setCellValue("Me again World");
FileOutputStream outputStream = new FileOutputStream(file);
hssfWorkbook.write(outputStream);
outputStream.close();
/* JXL Part */
jxl.WorkbookSettings settings = new jxl.WorkbookSettings();
settings.setEncoding("iso-8859-1"); // TODO encoding cfg
support - use hard-coded latin1 by now...
FileInputStream inputStream = new FileInputStream(file);
jxl.Workbook jxlWorkbook = jxl.Workbook.getWorkbook(inputStream
, settings);
jxl.Sheet jxlSheet = jxlWorkbook.getSheet("foo");
jxl.Cell jxlCell = jxlSheet.getCell(1, 1);
System.out.println(jxlCell.getContents());
jxlSheet = jxlWorkbook.getSheet("bar");
jxlCell = jxlSheet.getCell(2, 1);
System.out.println(jxlCell.getContents());
}
}
On 15/07/2011 11:39, Yegor Kozlov wrote:
HSSF or XSSF? Can you post sample code to demonstrate the problem ?
Yegor
--
Christian Brenninkmeijer
Department of Computer Science
University of Manchester
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]