All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.cliveyuan.tools.data.ExcelWriter Maven / Gradle / Ivy

There is a newer version: 4.0.6
Show newest version
package com.gitee.cliveyuan.tools.data;

import com.gitee.cliveyuan.tools.enums.ExcelType;
import com.google.common.collect.Lists;
import lombok.Builder;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * Created by Clive on 2019/10/28.
 */
@Data
@Builder
@Slf4j
public class ExcelWriter implements Serializable {

    private String filePath;
    @Builder.Default
    private ExcelType excelType = ExcelType.XLSX;
    @Builder.Default
    private List sheetContentList = Lists.newArrayList();

    public ExcelWriter addSheetContent(String sheetName, String[] headers, Collection data) {
        this.sheetContentList.add(new SheetContent(sheetName, headers, data));
        return this;
    }

    public File write() {
        ExcelGenerateParam param = ExcelGenerateParam.builder()
                .filePath(filePath)
                .excelType(excelType)
                .sheetContentList(sheetContentList)
                .build();
        return TableUtils.generate(param);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy