hellokaton / excel-plus Goto Github PK
View Code? Open in Web Editor NEW❇️ Improve the productivity of the Excel operation library. https://hellokaton.github.io/excel-plus/#/
License: Apache License 2.0
❇️ Improve the productivity of the Excel operation library. https://hellokaton.github.io/excel-plus/#/
License: Apache License 2.0
请问两百万条数据怎么分表插入呢?因为Excel单表最高只能接收一百万左右的数据,超过的需要分表,而在Excel-plus的API中没有看到有分表的方法,那是不是需要自己写判断来分表呢?
如果一个Excel表的多个Sheet除了数据以外其他都是相同的,那么我得为这多个Sheet编写几乎一样的model类,仅仅只是因为他们的Sheet名不同。
所以我觉得可以增加一个可以动态制定sheet名的的功能,方便对同一个model重用。
场景,Excel列数不固定的时候,无法去定义一个实体对象,建议添加对Map类型的读取和写出
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)
Writer.create().withTemplate(path)
.sheet("成绩单")
.withRows(all)
.isAppend(true)
.to(new File(filePath));
我在web程序中,用示例的read 方法读取excel 后, 此时尝试打开被读取的excel文件会被提示该正在被占用,关闭web程序jvm后,才不会提示。
excelPlus.read(xxxxDTO.class, reader).asList();
自定义 sheet
名无效
如题。
我在接收前台参数时是用springmvc 的MultipartFile接收的,在解析excel转对象时传入的参数是File类型,可否有更方便的方法,谢谢
多个sheet写入没有相关方法 isAppend的作用是什么
Android导入运行到asList();后面代码直接return了,不运行了
在C:\Windows\Temp\poifiles生成大量临时文件poi-sxssf-sheet12345678.xml,导致c盘被占满
现在这种表格导出是给运营,会计使用的,他们需要统计,拉一列,就能够计算总和那种,但是现在是文本的导出来
How to export multi sheet?
val sheetName = Reader.create(ShoutListModel::class.java)
.from(File(FilePathConstants.EXCEL_FILE_PATH)).sheet(0).sheetName()
这样写的话 返回为null 不知道为什么
根据字段配置读取写入excel,有些场景需要根据参数设置行,使用注解的方式是固定的,不好扩展。
不知道能不能在一个excel文件中创建多个sheet,如果可以要怎么做呢
测试代码:
测试导出,模拟测试数据
@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解析到 primaryKey
为 null
的时候不执行 PrimaryKeyConverter#stringToR()
,导致 Boolean 会出现 null 值
另外还有以下一些问题:
Writer
还存着一个问题,就是headerStyle样式好像并没有生效。Writer
写出的时候,能否将 withRows
非必要条件,比如我只想导出一个模板,包含 实体类的字段信息,我直接导出实体类就行,没必要设置行数。Writer.create(ExcelType.XLSX).class(TalendModel.class).headerStyle((book, style) -> {
style.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.ORANGE.getIndex());
return style;
}).to(new File(fileName));
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
针对 ReaderResult 的处理,我有个想法。
因为 目前 excel-plus 的 ReaderResult 没有提供直接获取 List<Pair<Integer, T>> result 或者直接对 result 进行操作的方法(为啥不直接暴露内部的result对象呢?)
导致result的 Excel 行号在执行类似于 asList() 方法之后会丢失行号信息,只剩下单纯的对象列表了
所以ReaderResult是否可以直提供result的获取方法,或者提供针对result集合的“流式”的操作(如filter、peek等,目前只有valid)
比如我目前手头有个需求就对于成功的结果是必须要明确获取到对应Excel中的行号信息,对于失败的结果也要求行号和原始数据的回传,而现在只能在valid方法上进行扩展,在这里将行号回填,如果有错误信息将错误信息封装到自己的bean,并且错误的信息也要返回成validRow.ok()才能获取到完整的处理好的数据,然后自己根据最终获取到的集合重新用个流来进行错误和正确的分组。
群主大大,上周使用excelplus写入2000条数据,越到后面越慢,大概花了半个小时,看了一下花销,主要都花销在writeRows里面autoSizeColumn这个方法里。
原因应该和这个url里面说的一样
http://www.beyond-free.com/post/2016-07-01_be-careful-about-poi-autosizecolumn
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.