Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
苏木力格
easyexcel
提交
41460978
E
easyexcel
项目概览
苏木力格
/
easyexcel
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
easyexcel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
41460978
编写于
7月 30, 2019
作者:
Z
zhuangjiaju
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改宽度策略
上级
ad9544c4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
22 addition
and
26 deletion
+22
-26
src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java
...baba/excel/write/metadata/holder/AbstractWriteHolder.java
+5
-7
src/main/java/com/alibaba/excel/write/style/column/AbstractColumnWidthStyleStrategy.java
.../write/style/column/AbstractColumnWidthStyleStrategy.java
+5
-5
src/main/java/com/alibaba/excel/write/style/column/AbstractHeadColumnWidthStyleStrategy.java
...te/style/column/AbstractHeadColumnWidthStyleStrategy.java
+7
-4
src/main/java/com/alibaba/excel/write/style/column/SimpleColumnWidthStyleStrategy.java
...el/write/style/column/SimpleColumnWidthStyleStrategy.java
+5
-10
未找到文件。
src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java
浏览文件 @
41460978
...
...
@@ -8,9 +8,7 @@ import java.util.Map;
import
java.util.Set
;
import
java.util.TreeMap
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.converters.ConverterKeyBuild
;
...
...
@@ -37,7 +35,6 @@ import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import
com.alibaba.excel.write.metadata.style.WriteFont
;
import
com.alibaba.excel.write.property.ExcelWriteHeadProperty
;
import
com.alibaba.excel.write.style.RowCellStyleStrategy
;
import
com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy
;
import
com.alibaba.excel.write.style.column.AbstractHeadColumnWidthStyleStrategy
;
import
com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy
;
...
...
@@ -248,15 +245,16 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
}
private
void
dealColumnWidth
(
List
<
WriteHandler
>
handlerList
)
{
WriteHandler
columnWidthStyleStrategy
=
new
AbstractColumnWidthStyleStrategy
()
{
WriteHandler
columnWidthStyleStrategy
=
new
Abstract
Head
ColumnWidthStyleStrategy
()
{
@Override
protected
void
setColumnWidth
(
Sheet
sheet
,
Cell
cell
,
Head
head
)
{
protected
Integer
columnWidth
(
Head
head
)
{
if
(
head
==
null
)
{
return
;
return
null
;
}
if
(
head
.
getColumnWidthProperty
()
!=
null
)
{
sheet
.
setColumnWidth
(
head
.
getColumnIndex
(),
head
.
getColumnWidthProperty
().
getWidth
()
);
return
head
.
getColumnWidthProperty
().
getWidth
(
);
}
return
null
;
}
};
handlerList
.
add
(
columnWidthStyleStrategy
);
...
...
src/main/java/com/alibaba/excel/write/style/column/AbstractColumnWidthStyleStrategy.java
浏览文件 @
41460978
...
...
@@ -32,10 +32,7 @@ public abstract class AbstractColumnWidthStyleStrategy implements CellWriteHandl
@Override
public
void
afterCellCreate
(
WriteSheetHolder
writeSheetHolder
,
WriteTableHolder
writeTableHolder
,
Cell
cell
,
Head
head
,
int
relativeRowIndex
,
boolean
isHead
)
{
if
(!
isHead
&&
relativeRowIndex
!=
0
)
{
return
;
}
setColumnWidth
(
writeSheetHolder
.
getSheet
(),
cell
,
head
);
setColumnWidth
(
writeSheetHolder
.
getSheet
(),
cell
,
head
,
relativeRowIndex
,
isHead
);
}
/**
...
...
@@ -44,7 +41,10 @@ public abstract class AbstractColumnWidthStyleStrategy implements CellWriteHandl
* @param sheet
* @param cell
* @param head
* @param relativeRowIndex
* @param isHead
*/
protected
abstract
void
setColumnWidth
(
Sheet
sheet
,
Cell
cell
,
@Nullable
Head
head
);
protected
abstract
void
setColumnWidth
(
Sheet
sheet
,
Cell
cell
,
@Nullable
Head
head
,
int
relativeRowIndex
,
boolean
isHead
);
}
src/main/java/com/alibaba/excel/write/style/column/AbstractHeadColumnWidthStyleStrategy.java
浏览文件 @
41460978
...
...
@@ -8,12 +8,15 @@ import com.sun.istack.internal.Nullable;
/**
* Returns the column width according to each column header
*
*
* @author zhuangjiaju
*/
public
abstract
class
AbstractHeadColumnWidthStyleStrategy
extends
AbstractColumnWidthStyleStrategy
{
@Override
protected
void
setColumnWidth
(
Sheet
sheet
,
Cell
cell
,
Head
head
)
{
protected
void
setColumnWidth
(
Sheet
sheet
,
Cell
cell
,
Head
head
,
int
relativeRowIndex
,
boolean
isHead
)
{
if
(!
isHead
&&
relativeRowIndex
!=
0
)
{
return
;
}
Integer
width
=
columnWidth
(
head
);
if
(
width
!=
null
)
{
sheet
.
setColumnWidth
(
cell
.
getColumnIndex
(),
columnWidth
(
head
));
...
...
@@ -22,9 +25,9 @@ public abstract class AbstractHeadColumnWidthStyleStrategy extends AbstractColum
/**
* Returns the column width corresponding to each column head.
*
*
* <li>if return null,ignore
*
*
* @param head
* @return the width in units of 1/256th of a character width . Using the Calibri font as an example, the maximum
* digit width of 11 point font size is 7 pixels (at 96 dpi). If you set a column width to be eight
...
...
src/main/java/com/alibaba/excel/write/style/column/SimpleColumnWidthStyleStrategy.java
浏览文件 @
41460978
package
com.alibaba.excel.write.style.column
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
com.alibaba.excel.metadata.Head
;
/**
* All the columns are the same width
*
*
* @author zhuangjiaju
*/
public
class
SimpleColumnWidthStyleStrategy
extends
AbstractColumnWidthStyleStrategy
{
public
class
SimpleColumnWidthStyleStrategy
extends
Abstract
Head
ColumnWidthStyleStrategy
{
private
Integer
columnWidth
;
/**
* Using the Calibri font as an example, the maximum digit width of 11 point font size is 7 pixels (at 96 dpi). * If
* you set a column width to be eight characters wide, e.g. <code>SimpleColumnWidthStyleStrategy( 8*256)</code>,
*
*
* @param columnWidth
* the width in units of 1/256th of a character width
*/
...
...
@@ -25,9 +22,7 @@ public class SimpleColumnWidthStyleStrategy extends AbstractColumnWidthStyleStra
}
@Override
protected
void
setColumnWidth
(
Sheet
sheet
,
Cell
cell
,
Head
head
)
{
if
(
columnWidth
!=
null
)
{
sheet
.
setColumnWidth
(
cell
.
getColumnIndex
(),
columnWidth
);
}
protected
Integer
columnWidth
(
Head
head
)
{
return
columnWidth
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录