写入数据到已存在的excel中的问题
写excel方法有个new FileOutputStream("文件路径及名称");这个是要新建一个excel表,我担心我用这个方法时会把我已经存在的excel覆盖了,因为这个excel表中还有别的要留在上面的数据。
我要把一些数据写到一个已经存在的excel表中,在第6行写入数据
下面是我的代码:
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("报错信息");
FileOutputStream fos=null;
HSSFRow row=null;
HSSFCell cell=null;
// 列名
row = sheet.createRow(6);
cell = row.createCell((short) 0);
for (int y=0;y<obj.length;y++)
{
//写入对应的单元格中 }
try{
fos = new FileOutputStream("d:\\基本模板格式.xls");
wb.setSheetName(0, "报错信息");
wb.write(fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (fos != null)
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
问题一、这样写会不会把已存在的excel表覆盖?
问题二、如果有别的方法,请详细说明,最好有代码参照
谢谢!!!