ExcelTypeEnum.java 1017 字节
Newer Older
J
update  
jipengfei.jpf 已提交
1 2
package com.alibaba.excel.support;

3 4 5
import java.io.IOException;
import java.io.InputStream;

Z
zhuangjiaju 已提交
6 7
import org.apache.poi.poifs.filesystem.FileMagic;

J
update  
jipengfei.jpf 已提交
8 9 10 11
/**
 * @author jipengfei
 */
public enum ExcelTypeEnum {
12 13 14

    XLS(".xls"), XLSX(".xlsx");

J
update  
jipengfei.jpf 已提交
15 16
    private String value;

17
    ExcelTypeEnum(String value) {
J
update  
jipengfei.jpf 已提交
18 19 20
        this.setValue(value);
    }

Z
zhuangjiaju 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    public static ExcelTypeEnum valueOf(InputStream inputStream) {
        try {
            if (!inputStream.markSupported()) {
                return null;
            }
            FileMagic fileMagic = FileMagic.valueOf(inputStream);
            if (FileMagic.OLE2.equals(fileMagic)) {
                return XLS;
            }
            if (FileMagic.OOXML.equals(fileMagic)) {
                return XLSX;
            }
            return null;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

J
update  
jipengfei.jpf 已提交
39 40 41 42 43 44 45 46
    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}