如何使用poi在已存在的excel中插入一行???

YellowSnake 2004-01-05 10:38:48
例如:在第一和第二行中插入一行???
...全文
995 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
turbocrm 2004-01-06
  • 打赏
  • 举报
回复
跪求大家,帮我看看这个问题,谢谢!!!!!!!!!!!!!

http://expert.csdn.net/Expert/topic/2633/2633574.xml?temp=.6377375
cold_blooded 2004-01-06
  • 打赏
  • 举报
回复
package testz1;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;

public class Hello {
public Hello() {
}

public static void main(String[] args)

{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow( (short) 0);
createCell(wb, row, (short) 0, HSSFCellStyle.ALIGN_CENTER, 1);
createCell(wb, row, (short) 1, HSSFCellStyle.ALIGN_CENTER_SELECTION, 1);
createCell(wb, row, (short) 2, HSSFCellStyle.ALIGN_FILL, 1);
createCell(wb, row, (short) 3, HSSFCellStyle.ALIGN_GENERAL, 1);
createCell(wb, row, (short) 4, HSSFCellStyle.ALIGN_JUSTIFY, 1);
createCell(wb, row, (short) 5, HSSFCellStyle.ALIGN_LEFT, 1);
createCell(wb, row, (short) 6, HSSFCellStyle.ALIGN_RIGHT, 1);

HSSFRow row2 = sheet.createRow( (short) 1);
row2.setRowNum( (short) 5);
createCell(wb, row2, (short) 0, HSSFCellStyle.ALIGN_CENTER, 2);
createCell(wb, row2, (short) 1, HSSFCellStyle.ALIGN_CENTER_SELECTION, 2);
createCell(wb, row2, (short) 2, HSSFCellStyle.ALIGN_FILL, 2);
createCell(wb, row2, (short) 3, HSSFCellStyle.ALIGN_GENERAL, 2);
createCell(wb, row2, (short) 4, HSSFCellStyle.ALIGN_JUSTIFY, 2);
createCell(wb, row2, (short) 5, HSSFCellStyle.ALIGN_LEFT, 2);
createCell(wb, row2, (short) 6, HSSFCellStyle.ALIGN_RIGHT, 2);

HSSFRow row3 = sheet.createRow( (short) 1);
createCell(wb, row3, (short) 0, HSSFCellStyle.ALIGN_CENTER, 3);
createCell(wb, row3, (short) 1, HSSFCellStyle.ALIGN_CENTER_SELECTION, 3);
createCell(wb, row3, (short) 2, HSSFCellStyle.ALIGN_FILL, 3);
createCell(wb, row3, (short) 3, HSSFCellStyle.ALIGN_GENERAL, 3);
createCell(wb, row3, (short) 4, HSSFCellStyle.ALIGN_JUSTIFY, 3);
createCell(wb, row3, (short) 5, HSSFCellStyle.ALIGN_LEFT, 3);
createCell(wb, row3, (short) 6, HSSFCellStyle.ALIGN_RIGHT, 3);

try {
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
catch (Exception e) {}
}

private static void createCell(HSSFWorkbook wb, HSSFRow row, short column,
short align, int i) {
HSSFCell cell = row.createCell(column);
cell.setCellValue(Integer.toString(i));
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setAlignment(align);
cell.setCellStyle(cellStyle);
}

}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧