作者:乔山办公网日期:
返回目录:excel表格制作
报格式错误是因为百你没有填充EXCEL的内容。
正确的度做法是:知
1, HSSFWorkbook ws = new HSSFWorkbook();//建立新HSSFWorkbook对象
2, Sheet sheet = workbook.createSheet(0); //建立一个道新的sheet
3,Row row = sheet.createRow(1); //建立一个新的row对象
4, Cell cell = row.createCell(0); //在row上创建方版格即列,
cell.setCellValue(cellValue); //设置这个行中列的值权
cell.setCellStyle(cellStyle); //设置样式
12345678910111281920212223242526272829 private static void WriteExcel2010() throws IOException { String path="C:\\poi2.xlsx"; XSSFWorkbook workbook=new XSSFWorkbook(); XSSFSheet sheet=workbook.createSheet("我的Sheet"); XSSFRow row=sheet.createRow(0); XSSFCell cell=row.createCell(0); cell.setCellValue("我是POI写入e799bee5baa6e997aee7ad94e78988e69d83332的"); XSSFRow row1=sheet.createRow(1); XSSFCell cell1=row1.createCell(0); cell1.setCellValue("2010"); FileOutputStream outputStream=new FileOutputStream(path); workbook.write(outputStream); outputStream.close(); } private static void WriteExcel2003() throws IOException { String path="C:\\poi2.xls"; HSSFWorkbook workbook=new HSSFWorkbook(); HSSFSheet sheet=workbook.createSheet("我的Excel"); HSSFRow row=sheet.createRow(0); HSSFCell cell=row.createCell(0); cell.setCellValue("我是POI写入的"); FileOutputStream outputStream=new FileOutputStream(path); workbook.write(outputStream); outputStream.close(); }
response.setContentType("bin");
response.setHeader("Content-disposition","attachment;filename=test.xls");
你在百servlet里面设置响应头为这样,然后就能够实现下载了,然后使度用输出流进行输出下载
.....还有问题的专话属就问..
你要是想全部代码都写的话..加我扣扣 1195391953..
private static void WriteExcel2010() throws IOException {
String path="C:\\poi2.xlsx";
XSSFWorkbook workbook=new XSSFWorkbook();
XSSFSheet sheet=workbook.createSheet("我的Sheet");
XSSFRow row=sheet.createRow(0);
XSSFCell cell=row.createCell(0);
cell.setCellValue("我是7a686964616fe58685e5aeb9333POI写入的");
XSSFRow row1=sheet.createRow(1);
XSSFCell cell1=row1.createCell(0);
cell1.setCellValue("2010");
FileOutputStream outputStream=new FileOutputStream(path);
workbook.write(outputStream);
outputStream.close();
}
private static void WriteExcel2003() throws IOException {
String path="C:\\poi2.xls";
HSSFWorkbook workbook=new HSSFWorkbook();
HSSFSheet sheet=workbook.createSheet("我的Excel");
HSSFRow row=sheet.createRow(0);
HSSFCell cell=row.createCell(0);
cell.setCellValue("我是POI写入的");
FileOutputStream outputStream=new FileOutputStream(path);
workbook.write(outputStream);
outputStream.close();
}