永发信息网

javaweb 导出excel需要哪些jar包

答案:3  悬赏:0  手机版
解决时间 2021-11-26 00:12
  • 提问者网友:城市野鹿
  • 2021-11-25 17:58
javaweb 导出excel需要哪些jar包
最佳答案
  • 五星知识达人网友:雾月
  • 2021-11-25 18:47
java导出Excel需要用到poi的jar包,
// 第一步,创建一个webbook,对应一个Excel文件  
HSSFWorkbook wb = new HSSFWorkbook();  
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet  
HSSFSheet sheet = wb.createSheet("学生表一");  
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short  
HSSFRow row = sheet.createRow((int) 0);  
// 第四步,创建单元格,并设置值表头 设置表头居中  
HSSFCellStyle style = wb.createCellStyle();  
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式  
HSSFCell cell = row.createCell((short) 0);  
cell.setCellValue("学号");  
cell.setCellStyle(style);  
cell = row.createCell((short) 1);  
cell.setCellValue("姓名");  
cell.setCellStyle(style);  
cell = row.createCell((short) 2);  
cell.setCellValue("年龄");  
cell.setCellStyle(style);  
cell = row.createCell((short) 3);  
cell.setCellValue("生日");  
cell.setCellStyle(style);  
// 第五步,写入实体数据 实际应用中这些数据从数据库得到,  
List list = CreateSimpleExcelToDisk.getStudent();  
for (int i = 0; i < list.size(); i++)  
{  
row = sheet.createRow((int) i + 1);  
Student stu = (Student) list.get(i);  
// 第四步,创建单元格,并设置值  
row.createCell((short) 0).setCellValue((double) stu.getId());  
row.createCell((short) 1).setCellValue(stu.getName());  
row.createCell((short) 2).setCellValue((double) stu.getAge());  
cell = row.createCell((short) 3);  
cell.setCellValue(new SimpleDateFormat("yyyy-mm-dd").format(stu  
.getBirth()));  
}  
// 第六步,将文件存到指定位置  
try  
{  
FileOutputStream fout = new FileOutputStream("E:/students.xls");  
wb.write(fout);  
fout.close();  
}  
catch (Exception e)  
{  
e.printStackTrace();  
}  
}
微软的OFFICE是最为流行的办公软件,主要有OFFICE2010和OFFICE2007两个版本。Office 2000是第三代办公处理软件的代表产品,可以作为办公和管理的平台,以提高使用者的工作效率和决策能力。Office 2000中文版有4种不同的版本:标准版、中小企业版、中文专业版和企业版。
在Office 2000中各个组件仍有着比较明确的分工:一般说来,Word主要用来进行文本的输入、编辑、排版、打印等工作;Excel主要用来进行有繁重计算任务的预算、财务、数据汇总等工作;PowerPoint主要用来制作演示文稿和幻灯片及投影片等;Access是一个桌面数据库系统及数据库应用程序;Outlook是一个桌面信息管理的应用程序;FrontPage主要用来制作和发布因特网的Web页面。
Microsoft Office XP是微软有史以来所发行的Office版本中最重要的版本,而且也被认为是迄今为止功能最强大、最易于使用的Office产品。新版Office放弃了以往以产品发布年命名的惯例!产品名称中的XP,是英文Experience(体验)的缩写,代表着新版Office在包容覆盖广泛设备的Web服务之后,将给用户带来丰富的、充分扩展的全新体验。
除核心的 Office XP 程序 — Microsoft Word、Excel、Outlook和 PowerPoint— 外,Office XP 专业版 中包含 Microsoft Access 2002,它是 Office XP 数据库解决方案,可帮助用户存储、访问和分析数据。
全部回答
  • 1楼网友:猎心人
  • 2021-11-25 20:15
用poi-3.9.jar还有logging-commong.jar log4j.jar
  • 2楼网友:忘川信使
  • 2021-11-25 19:49
java导出Excel需要用到poi的jar包,
// 第一步,创建一个webbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("学生表一");
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
HSSFRow row = sheet.createRow((int) 0);
// 第四步,创建单元格,并设置值表头 设置表头居中
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式

HSSFCell cell = row.createCell((short) 0);
cell.setCellValue("学号");
cell.setCellStyle(style);
cell = row.createCell((short) 1);
cell.setCellValue("姓名");
cell.setCellStyle(style);
cell = row.createCell((short) 2);
cell.setCellValue("年龄");
cell.setCellStyle(style);
cell = row.createCell((short) 3);
cell.setCellValue("生日");
cell.setCellStyle(style);

// 第五步,写入实体数据 实际应用中这些数据从数据库得到,
List list = CreateSimpleExcelToDisk.getStudent();

for (int i = 0; i < list.size(); i++)
{
row = sheet.createRow((int) i + 1);
Student stu = (Student) list.get(i);
// 第四步,创建单元格,并设置值
row.createCell((short) 0).setCellValue((double) stu.getId());
row.createCell((short) 1).setCellValue(stu.getName());
row.createCell((short) 2).setCellValue((double) stu.getAge());
cell = row.createCell((short) 3);
cell.setCellValue(new SimpleDateFormat("yyyy-mm-dd").format(stu
.getBirth()));
}
// 第六步,将文件存到指定位置
try
{
FileOutputStream fout = new FileOutputStream("E:/students.xls");
wb.write(fout);
fout.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯