asked on
ASKER
import org.apache.poi.hssf.usermodel.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class TestPOI {
public TestPOI(){
try{
FileInputStream oFileInputStream=new FileInputStream("c:/temp/Book_test.xls");
HSSFWorkbook oWorkbook=new HSSFWorkbook(oFileInputStream);
HSSFSheet oWorksheet = oWorkbook.createSheet("New Sheet-1");
HSSFRow oRow = oWorksheet.createRow(0);
HSSFCell oCell=oRow.createCell((short)0);
HSSFRichTextString oTextString=new HSSFRichTextString("Sample String");
oCell.setCellValue(oTextString);
FileOutputStream oOutputStream = new FileOutputStream("c:/temp/Book_test1.xls");
oWorkbook.write(oOutputStream);
oOutputStream.close();
} catch(Exception ex){
System.out.println(ex.toString());
ex.printStackTrace();
}
}
public static void main(String [] args){
new TestPOI();
}
}
ASKER
ASKER
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
TRUSTED BY
What happens if you first create an empty Excel workbook manually- add visual basic macro to it using microsoft
recommendations - and then when creating your spreadsheet with POI - start from this workbook with embedded macro,
say copy the file every time with java code, and then open it with POI and insert the
contents you need.
Perhaps it will still keep the macro within?
Have you tried it this way?