Skip to content

semihunaldi/ExcelOrm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Experimental Excel ORM library

<dependency>
  <groupId>com.semihunaldi</groupId>
  <artifactId>excel-orm</artifactId>
  <version>0.0.1-BETA-SNAPSHOT</version>
</dependency>

<repositories>
  <repository>
    <id>oss.sonatype.org-snapshot</id>
    <url>http://oss.sonatype.org/content/repositories/snapshots</url>
    <releases>
      <enabled>false</enabled>
    </releases>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
  </repository>
</repositories>

Limitations

  • Every sheet maps to only ONE POJO.
  • Sadly, every time you need to update any data, whole sheet of the excel will be rewritten. This will be a major problem if data is huge.
  • Only String, Integer, Double, BigInteger, Long, Boolean, Date and Enum classes are supported.

Name Last Name Age Amount Description Date Status
Name1 Last Name1 11 101.1 description1 16/09/2017 19:30 FINISHED
Name2 Last Name2 12 102.2 description2 16/09/2017 19:30 ACTIVE
Name3 Last Name3 13 103.3 description3 16/09/2017 19:30 ACTIVE
Name4 Last Name4 14 104.4 description4 16/09/2017 19:30 FINISHED
@Excel(firstRow = 1, firstCol = 0, sheetName = "Tasks")
@Data
public class Task extends BaseExcel
{
    @ExcelColumn(col = 0, columnName = "Name")
    private String firstName;

    @ExcelColumn(col = 1, columnName = "Last Name")
    private String lastName;

    @ExcelColumn(col = 2, columnName = "Age")
    private Integer age;

    @ExcelColumn(col = 3, columnName = "Amount")
    private Double amount;

    @ExcelColumn(col = 4, columnName = "Description")
    private String description;
    
    @ExcelColumn(col = 5, columnName = "Date", dateFormat = "dd/MM/yyyy HH:mm")
    private Date date;
    
    @ExcelColumn(col = 6, columnName = "Status")
    private Status status;
}
public class Test
{
    public static void main(String[] args)
    {
        File file = new File("/some/path/Excel.xlsx");
        //reading
        ExcelReader excelReader = new ExcelReader();
        List<Task> taskList = excelReader.read(file, Task.class);
        //writing
        ExcelWriter excelWriter = new ExcelWriter();
        taskList.remove(2);
        excelWriter.write(file,taskList,Task.class);
    }
}