Java 用Poi操作Excel。
在指定行的下面,插入一行,但是每次它都是替换这行的数据,大神帮忙解决下吧。付代码--------------------------------POIFSFileSyst...
在指定行的下面,插入一行,但是每次它都是替换这行的数据,大神帮忙解决下吧。付代码
--------------------------------
POIFSFileSystem fs =new POIFSFileSystem(new FileInputStream("D:\\Test.xls"));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
//创建行
HSSFRow row=sheet.createRow(rowindex);
//创建列
HSSFCell cell=row.createCell(cellindex);
HSSFCell cell1=row.createCell(cellindex);
HSSFCell cell2=row.createCell(cellindex);
HSSFCell cell3=row.createCell(cellindex);
//写入单元格内容
cell=row.createCell((cellindex-1));
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue(1);
cell1=row.createCell(cellindex);
cell1.setCellType(HSSFCell.CELL_TYPE_STRING);
cell1.setCellValue(merName);
cell2=row.createCell((cellindex+3));
cell2.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell2.setCellValue(price);
cell3=row.createCell((cellindex+6));
cell3.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell3.setCellValue(quantity);
// 输出文件
FileOutputStream fileOut = new FileOutputStream("D:\\Temp.xls");
wb.write(fileOut);
fileOut.close();
-----------------------------------END; 展开
--------------------------------
POIFSFileSystem fs =new POIFSFileSystem(new FileInputStream("D:\\Test.xls"));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
//创建行
HSSFRow row=sheet.createRow(rowindex);
//创建列
HSSFCell cell=row.createCell(cellindex);
HSSFCell cell1=row.createCell(cellindex);
HSSFCell cell2=row.createCell(cellindex);
HSSFCell cell3=row.createCell(cellindex);
//写入单元格内容
cell=row.createCell((cellindex-1));
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell.setCellValue(1);
cell1=row.createCell(cellindex);
cell1.setCellType(HSSFCell.CELL_TYPE_STRING);
cell1.setCellValue(merName);
cell2=row.createCell((cellindex+3));
cell2.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell2.setCellValue(price);
cell3=row.createCell((cellindex+6));
cell3.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cell3.setCellValue(quantity);
// 输出文件
FileOutputStream fileOut = new FileOutputStream("D:\\Temp.xls");
wb.write(fileOut);
fileOut.close();
-----------------------------------END; 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询