Code Monkey home page Code Monkey logo

excel-plus's Introduction

excel-plus's People

Contributors

hellokaton avatar hwywl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

excel-plus's Issues

Problem with export

Hi everyone;
When i want to export a simple excel file I get this error:

java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/xml/stream/XMLStreamReader; at org.apache.xmlbeans.XmlBeans.buildStreamToNodeMethod(XmlBeans.java:247) at org.apache.xmlbeans.XmlBeans.<clinit>(XmlBeans.java:134) at org.apache.xmlbeans.XmlBeans.typeLoaderForClassLoader(XmlBeans.java:715) at org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook$Factory.getTypeLoader(Unknown Source:25) at org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook$Factory.newInstance(Unknown Source:0) at org.apache.poi.xssf.usermodel.XSSFWorkbook.onWorkbookCreate(XSSFWorkbook.java:460) at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:263) at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:257) at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:245) at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:243) at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:213) at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:188) at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:274) at io.github.biezhi.excel.plus.writer.WriterWith2007.writeSheet(WriterWith2007.java:48) at io.github.biezhi.excel.plus.Writer.to(Writer.java:284) at io.github.biezhi.excel.plus.Writer.to(Writer.java:267) at tools.ActivityExcelExporter.onCreate(ActivityExcelExporter.java:34) at android.app.Activity.performCreate(Activity.java:7327) at android.app.Activity.performCreate(Activity.java:7318) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1275) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3095) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3258) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1955) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7058) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965) Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.xml.stream.XMLStreamReader" on path: DexPathList[[zip file "/data/app/ir.adinapp.supermarket-rusFzlLBnp2BrQKogUvP3g==/base.apk"],nativeLibraryDirectories=[/data/app/ir.adinapp.supermarket-rusFzlLBnp2BrQKogUvP3g==/lib/arm64, /system/lib64]]

anybody can help me? tanx

导入excel报错:Zip bomb detected! The file would exceed the max. ratio of compressed file size to the size of the expanded data.

Zip bomb detected! The file would exceed the max. ratio of compressed file size to the size of the expanded data.
This may indicate that the file is used to inflate memory usage and thus could pose a security risk.
You can adjust this limit via ZipSecureFile.setMinInflateRatio() if you need to work with files which exceed this limit.
Uncompressed size: 147803, Raw/compressed size: 1462, ratio: 0.009892
Limits: MIN_INFLATE_RATIO: 0.010000, Entry: xl/styles.xml"}
java.io.IOException: Zip bomb detected! The file would exceed the max. ratio of compressed file size to the size of the expanded data.
This may indicate that the file is used to inflate memory usage and thus could pose a security risk.
You can adjust this limit via ZipSecureFile.setMinInflateRatio() if you need to work with files which exceed this limit.
Uncompressed size: 147803, Raw/compressed size: 1462, ratio: 0.009892
Limits: MIN_INFLATE_RATIO: 0.010000, Entry: xl/styles.xml
at org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.checkThreshold(ZipArchiveThresholdInputStream.java:130)
at org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.read(ZipArchiveThresholdInputStream.java:80)
at org.apache.poi.util.IOUtils.toByteArray(IOUtils.java:151)
at org.apache.poi.util.IOUtils.toByteArray(IOUtils.java:120)
at org.apache.poi.openxml4j.util.ZipArchiveFakeEntry.(ZipArchiveFakeEntry.java:47)
at org.apache.poi.openxml4j.util.ZipInputStreamZipEntrySource.(ZipInputStreamZipEntrySource.java:51)
at org.apache.poi.openxml4j.opc.ZipPackage.(ZipPackage.java:106)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:299)
at org.apache.poi.ooxml.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:307)

[建议]希望可以在运行时动态指定 sheet 名

需求

如果一个Excel表的多个Sheet除了数据以外其他都是相同的,那么我得为这多个Sheet编写几乎一样的model类,仅仅只是因为他们的Sheet名不同。

建议

所以我觉得可以增加一个可以动态制定sheet名的的功能,方便对同一个model重用。

Excel两百万条数据分表写入

请问两百万条数据怎么分表插入呢?因为Excel单表最高只能接收一百万左右的数据,超过的需要分表,而在Excel-plus的API中没有看到有分表的方法,那是不是需要自己写判断来分表呢?

reader 读完excel 后似乎不会关闭文件句柄

我在web程序中,用示例的read 方法读取excel 后, 此时尝试打开被读取的excel文件会被提示该正在被占用,关闭web程序jvm后,才不会提示。

excelPlus.read(xxxxDTO.class, reader).asList();

【question】Reader读取Excel的时候遇到null值不处理 converter

测试代码:

测试导出,模拟测试数据

@Test
public void testWriter() throws WriterException {
    String fileName = "/Users/yangkai.shen/Desktop/模板.xlsx";
    List<TalendModel> rows = Lists.newArrayList(new TalendModel("1","1","1","1","1",true,"1","1"),new TalendModel("1","1","1","1","1",false,"1","1"),new TalendModel("1","1","1","1","1",null,"1","1"));
    Writer.create(ExcelType.XLSX).withRows(rows).headerStyle((book, style) -> {
        style.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.ORANGE.getIndex());
        return style;
    }).to(new File(fileName));
}

测试导入

@Test
public void testReader() {
    String fileName = "/Users/yangkai.shen/Desktop/模板.xlsx";
    List<TalendModel> talendModels = Reader.create(TalendModel.class)
            .from(new File(fileName))
            .sheet(0)
            .start(1)
            .asList();
    talendModels.forEach(System.out::println);
}

实体类代码

@Data
@NoArgsConstructor
@AllArgsConstructor
public class TalendModel {
    /**
     * 表中文名
     */
    @ExcelColumn(title = "表中文名", index = 0)
    private String tableChineseName;
    /**
     * 表英文名
     */
    @ExcelColumn(title = "表英文名", index = 1)
    private String tableEnglishName;
    /**
     * 字段中文名
     */
    @ExcelColumn(title = "字段中文名", index = 2)
    private String columnChineseName;
    /**
     * 字段英文名
     */
    @ExcelColumn(title = "字段英文名", index = 3)
    private String columnEnglishName;
    /**
     * 字段数据类型
     */
    @ExcelColumn(title = "字段数据类型", index = 4)
    private String columnDataType;
    /**
     * 主键
     */
    @ExcelColumn(title = "主键", index = 5, converter = PrimaryKeyConverter.class)
    private Boolean primaryKey;
    /**
     * 关联外键表
     */
    @ExcelColumn(title = "关联外键表", index = 6)
    private String foreignTableName;
    /**
     * 外键关联表字段
     */
    @ExcelColumn(title = "外键关联表字段", index = 7)
    private String foreignColumnName;
}

类型转换Converter代码

public class PrimaryKeyConverter implements Converter<String, Boolean> {
    @Override
    public Boolean stringToR(String value) {
        if (StrUtil.isNotBlank(value) && StrUtil.equals("Y", value)) {
            return true;
        }
        return false;
    }

    @Override
    public String toString(Boolean fieldValue) {
        if (fieldValue) {
            return "Y";
        }
        return "";
    }
}

遇到的问题:
Reader解析到 primaryKeynull 的时候不执行 PrimaryKeyConverter#stringToR(),导致 Boolean 会出现 null 值

另外还有以下一些问题:

  1. Writer 还存着一个问题,就是headerStyle样式好像并没有生效。
  2. Writer 写出的时候,能否将 withRows非必要条件,比如我只想导出一个模板,包含 实体类的字段信息,我直接导出实体类就行,没必要设置行数。
    建议添加个class参数如下:
Writer.create(ExcelType.XLSX).class(TalendModel.class).headerStyle((book, style) -> {
        style.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.ORANGE.getIndex());
        return style;
    }).to(new File(fileName));

如何获取xls中多个sheet的名字

val sheetName = Reader.create(ShoutListModel::class.java)
.from(File(FilePathConstants.EXCEL_FILE_PATH)).sheet(0).sheetName()
这样写的话 返回为null 不知道为什么

一个关于ReaderResult功能请求

针对 ReaderResult 的处理,我有个想法。

因为 目前 excel-plusReaderResult 没有提供直接获取 List<Pair<Integer, T>> result 或者直接对 result 进行操作的方法(为啥不直接暴露内部的result对象呢?)

导致result的 Excel 行号在执行类似于 asList() 方法之后会丢失行号信息,只剩下单纯的对象列表了

所以ReaderResult是否可以直提供result的获取方法,或者提供针对result集合的“流式”的操作(如filter、peek等,目前只有valid)

比如我目前手头有个需求就对于成功的结果是必须要明确获取到对应Excel中的行号信息,对于失败的结果也要求行号和原始数据的回传,而现在只能在valid方法上进行扩展,在这里将行号回填,如果有错误信息将错误信息封装到自己的bean,并且错误的信息也要返回成validRow.ok()才能获取到完整的处理好的数据,然后自己根据最终获取到的集合重新用个流来进行错误和正确的分组。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.