-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
addSheet时能不能添加模板,好像不支持模板+addSheet的结合使用 #256
Comments
由于前两页excel排版比较费劲,想模板填入,代码效果期待如下: |
目前对模板的支持较少,你的这种需求暂时可能并不支持,你可以试着将两个模板做在一个Excel文件的两个Worksheet中试试是否可行 |
其实想问的是【模板填充+新增sheet】,比较常见的一种需求来的了,如sheet1是汇总报表、sheet2是明细; |
不过感谢回答,原做大做强! |
感谢反馈,确实有这种场景,考虑增加TemplateSheet |
爱你! |
👍非常漂亮的样式,有空的话能否帮忙写一个WIKI供其它人参考,像这种汇总+明细的场景比较常用,如果有WIKI参考可以大大减少接入代价。 WIKI地址可以点上面 wiki 进入,诚恳邀请你写一篇WIKI文档,或者发布在你自己常用的其它技术类网站上,在本ISSUE添加连接。 |
【👍非常漂亮的样式,有空的话能否帮忙写一个WIKI供其它人参考】哈哈哈,好的我有空分享一下 Const.Limit.HEADER_SUB_COLUMNS 类型为int ,能否改成Integer方便反射 ,或增大一下数值? |
临时处理可以自定义sheet和column绕过这个判断 |
ListMapSheet没有封装好,需要复制一大堆父类的实现,覆写addSubColumn方法并注释掉sub-column size判断即可,不过这样很危险,除非你在外部有限制大小,否则内存消耗肯定不小,因为在整个写入文件过程中Column[]数据会一直常驻内存。 public class MyListMapSheet extends ListMapSheet {
@Override
protected org.ttzero.excel.entity.Column[] getHeaderColumns() {
if (headerReady) return columns;
Map<String, ?> first = getFirst();
// No data
if (first == null) {
if (columns == null) {
columns = new org.ttzero.excel.entity.Column[0];
}
} else if (!hasHeaderColumns()) {
int size = first.size(), i = 0;
columns = new org.ttzero.excel.entity.Column[size];
for (Iterator<? extends Map.Entry<String, ?>> it = first.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, ?> entry = it.next();
// Ignore the null key
if (isEmpty(entry.getKey())) continue;
Object value = entry.getValue();
columns[i++] = new org.ttzero.excel.entity.Column(entry.getKey(), entry.getKey(), value != null ? value.getClass() : String.class) {
@Override
public org.ttzero.excel.entity.Column addSubColumn(org.ttzero.excel.entity.Column column) {
if (this == column) {
return this;
}
if (next != null) {
// int subSize = subColumnSize(), appendSize = column.subColumnSize();
// if (subSize + appendSize > Const.Limit.HEADER_SUB_COLUMNS) {
// throw new ExcelWriteException("Too many sub-column occur. Max support " + Const.Limit.HEADER_SUB_COLUMNS + ", current is " + subSize);
// }
column.prev = this.tail;
this.tail.next = column;
} else {
this.next = column;
column.prev = this;
}
this.tail = column.tail != null ? column.tail : column;
return this;
}
};
}
} else {
Object o;
for (int i = 0; i < columns.length; i++) {
org.ttzero.excel.entity.Column hc = columns[i].tail != null ? columns[i].tail : columns[i];
if (isEmpty(hc.key)) {
throw new ExcelWriteException(getClass() + " must specify the 'key' name.");
}
if (hc.getClazz() == null) {
hc.setClazz((o = first.get(hc.key)) != null ? o.getClass() : String.class);
}
}
}
return columns;
}
} |
我这边也写了一个报表类样式的WIKI 可以相互参考 |
v0.5.14已支持模板工作表它可以与普通工作表混合使用 |
addSheet时能不能添加模板,好像不支持模板+addSheet的结合使用
The text was updated successfully, but these errors were encountered: