Java如何使用POI库将数据导出到Excel?

技术百科 心靈之曲 发布时间:2024-12-01 浏览:

java导出数据到excel

在java中,可以使用第三方库poi将查询出的数据导出到excel表格中。

步骤:

  1. 导入poi库

导入poi和poi-ooxml依赖项:


    org.apache.poi
    poi
    4.0.1


    org.apache.poi
    poi-ooxml
    4.0.1
  1. 创建工作簿
xssfworkbook xssfworkbook = new xssfworkbook();
  1. 创建表
xssfsheet xssfsheet = xssfworkbook.createsheet("first_sheet");
  1. 创建行和单元格,并赋值
xssfrow row1 = xssfsheet.createrow(0);
row1.createcell(0).setcellvalue("姓名");
row1.createcell(1).setcellvalue("年龄");
row1.createcell(2).setcellvalue("性别");

row2.createcell(0).setcellvalue("张三");
row2.createcell(1).setcellvalue("18");
row2.createcell(2).setcellvalue("男");

// 以此类推创建更多行
  1. 写入磁盘
try (FileOutputStream out = new FileOutputStream("D:/output.xlsx")) {
    xssfWorkbook.write(out);
}

通过以上步骤,就可以将数据导出到excel文件中。


# excel  # 可以使用  # 第三方  # 单元格  # 就可以  # 以此类推  # Java  # apache  # 导出到  # excel表格  # 创建工作  # org  # dependency 


相关栏目: <?muma $count = M('archives')->where(['typeid'=>$field['id']])->count(); ?> 【 AI推广<?muma echo $count; ?> 】 <?muma $count = M('archives')->where(['typeid'=>$field['id']])->count(); ?> 【 SEO优化<?muma echo $count; ?> 】 <?muma $count = M('archives')->where(['typeid'=>$field['id']])->count(); ?> 【 技术百科<?muma echo $count; ?> 】 <?muma $count = M('archives')->where(['typeid'=>$field['id']])->count(); ?> 【 谷歌推广<?muma echo $count; ?> 】 <?muma $count = M('archives')->where(['typeid'=>$field['id']])->count(); ?> 【 百度推广<?muma echo $count; ?> 】 <?muma $count = M('archives')->where(['typeid'=>$field['id']])->count(); ?> 【 网络营销<?muma echo $count; ?> 】 <?muma $count = M('archives')->where(['typeid'=>$field['id']])->count(); ?> 【 案例网站<?muma echo $count; ?> 】 <?muma $count = M('archives')->where(['typeid'=>$field['id']])->count(); ?> 【 精选文章<?muma echo $count; ?>

相关推荐

在线咨询

点击这里给我发消息QQ客服

在线咨询

免费通话

24h咨询:4006964355


如您有问题,可以咨询我们的24H咨询电话!

免费通话

微信扫一扫

微信联系
返回顶部