Hi, all POI users,
I generated a excel workbook by the code as below, there will be a error
message that "Can not read file" when I open the workbook. Is there
something wrong with my code?
Note: my POI version is 3.7
Any body can solve my question? tks.
public static void main(String[] args) throws IOException {
String filePath = "E:/test.xls";
File iFile = new File(filePath);
FileOutputStream fout = new FileOutputStream(iFile);
HSSFWorkbook wbook = new HSSFWorkbook();
HSSFSheet sheet = wbook.createSheet();
HSSFRow row = sheet.createRow(1);
HSSFCell cell = row.createCell(2);
String string = "String";
HSSFPatriarch patr = sheet.createDrawingPatriarch();
HSSFClientAnchor clientAnchor =
new HSSFClientAnchor(0 , 0 , 0 , 0 , ( short ) 2 , 1, ( short
) 3 , 4);
HSSFComment comment = patr.createComment(clientAnchor);
HSSFRichTextString str = new HSSFRichTextString("comment");
comment.setString(str);
comment.setVisible(false);
cell.setCellComment(comment);
cell.setCellValue(string);
wbook.cloneSheet(0);
wbook.write(fout);
}
besides, there will throw an exception when run the code as bellow,
public static void main(String[] args) throws IOException {
String filePath = "E:/test.xls";
File iFile = new File(filePath);
FileOutputStream fout = new FileOutputStream(iFile);
HSSFWorkbook wbook = new HSSFWorkbook();
HSSFSheet sheet = wbook.createSheet();
HSSFPatriarch patr = sheet.createDrawingPatriarch();
wbook.cloneSheet(0);
wbook.write(fout);
}
Exception in thread "main" java.lang.IllegalStateException: EOF - next
record not available
at
org.apache.poi.hssf.record.RecordInputStream.nextRecord(RecordInputStream.java:191)
at org.apache.poi.hssf.record.Record.cloneViaReserialise(Record.java:88)
at
rg.apache.poi.hssf.record.AbstractEscherHolderRecord.clone(AbstractEscherHolderRecord.java:153)
at
org.apache.poi.hssf.model.InternalSheet.cloneSheet(InternalSheet.java:388)
at
org.apache.poi.hssf.usermodel.HSSFSheet.cloneSheet(HSSFSheet.java:125)
at
org.apache.poi.hssf.usermodel.HSSFWorkbook.cloneSheet(HSSFWorkbook.java:652)
at com.mypackage.CreateExcel.main(CreateExcel.java:44)
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/Something-wrong-when-using-Workbook-cloneSheet-tp4722496p4722496.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]