zoukankan      html  css  js  c++  java
  • 轻松完成excel读写操作- 基于POI的框架BingExcel的使用(1)

    Bingexcel User Guide

    1. 使用maven进行项目开发
      目前项目的maven仓库是在github上,浏览地址为 https://github.com/bingyulei007/mvn-repo/tree/master/repository/com/bing/excel,在使用时候,你只要加上一下远程仓库:
      <repositories>
            <repository>
                <id>bingyulei-mvn-repo</id>
                <url>https://raw.github.com/bingyulei007/mvn-repo/master/repository</url>
            </repository>
        </repositories>

    然后加入jar包的引用,就可以轻松读写excel了。

     <dependency>
            <groupId>com.bing</groupId>
            <artifactId>excel</artifactId>
            <version>1.2-SNAPSHOT</version>
         </dependency>

    2. 简单读取实例
    可以从这里下载person表格,数据如图:
    person表数据

    然后你需要创建一个java的实体对象与表格内容对应:

    1. public class Person {
          @CellConfig(index = 1)
          private int age;
          //@CellConfig(index = 0,readRequired=true)
          @CellConfig(index = 0)
          private String name;
          @CellConfig(index = 3)
          private Double salary;
      
          public String getName() {
              return name;
          }
      
          public void setName(String name) {
              this.name = name;
          }
      
          public int getAge() {
              return age;
          }
      
          public Double getSalary() {
              return salary;
          }
      
          public String toString() {
              return MoreObjects.toStringHelper(this.getClass()).omitNullValues()
                      .add("name", name).add("age", age).add("salary", salary)
                      .toString();
          }
      }

      其中的 @CellConfig是关键配置,用于对应映射关系。 然后,你就可以开始你的读写了。这里是介绍数据量不大的普通模式:

       File f = new File("person.xls");
      
          BingExcel bing = BingExcelBuilder.toBuilder().builder();
          try {
              SheetVo<Person> vo = bing.readFile(f, Person.class, 1);
              System.out.println(vo.getSheetIndex());//打印对应的sheet的顺序
              System.out.println(vo.getSheetName());//对应sheet工作表的名称
              System.out.println(vo.getObjectList());//数据对象
          } catch (Exception e) {
              e.printStackTrace();
          }
     更多内容可以关注:项目地址https://git.oschina.net/bingyulei007/bingExcel,也可以去项目页留言。提出宝贵的改进意见
     
  • 相关阅读:
    进度条
    radio checkbox 修改默认样式
    css3实现的switch开关按钮
    CSS常用样式
    js定义对象的多个属性值
    jquey常用代码
    分享一个酷炫动态登录页面html
    博客园添加背景音乐,背景效果!
    几个有益的 CSS 小知识
    html+css-->background-img(背景图的设置)
  • 原文地址:https://www.cnblogs.com/shizhongtao/p/5492436.html
Copyright © 2011-2022 走看看