Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_879456671
easyexcel
提交
54c9c36a
E
easyexcel
项目概览
qq_879456671
/
easyexcel
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
54c9c36a
编写于
5月 07, 2021
作者:
庄家钜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
移除多余代码
上级
d0a55912
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
8 addition
and
249 deletion
+8
-249
src/main/java/com/alibaba/excel/annotation/write/style/ImagePosition.java
...m/alibaba/excel/annotation/write/style/ImagePosition.java
+0
-61
src/main/java/com/alibaba/excel/metadata/property/ImagePositionProperty.java
...libaba/excel/metadata/property/ImagePositionProperty.java
+0
-135
src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java
src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java
+2
-8
src/test/java/com/alibaba/easyexcel/test/demo/write/ImageDataWithAnnotation.java
...ba/easyexcel/test/demo/write/ImageDataWithAnnotation.java
+0
-6
src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
...java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
+6
-39
未找到文件。
src/main/java/com/alibaba/excel/annotation/write/style/ImagePosition.java
已删除
100644 → 0
浏览文件 @
d0a55912
package
com.alibaba.excel.annotation.write.style
;
import
org.apache.poi.ss.usermodel.ClientAnchor
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Inherited
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
java.lang.annotation.Retention
;
/**
* This annotation is used to set the position of a picture.
* See {@link ClientAnchor}
*/
@Target
(
ElementType
.
FIELD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Inherited
public
@interface
ImagePosition
{
/**
* The x coordinate within the first cell.
*/
int
dx1
();
/**
* The y coordinate within the first cell.
*/
int
dy1
();
/**
* The x coordinate within the second cell.
*/
int
dx2
();
/**
* The y coordinate within the second cell
*/
int
dy2
();
/**
* 0-based column of the first cell.
*/
short
col1
();
/**
* 0-based row of the first cell.
*/
int
row1
();
/**
* 0-based column of the second cell.
*/
short
col2
();
/**
* 0-based row of the second cell.
*/
int
row2
();
}
src/main/java/com/alibaba/excel/metadata/property/ImagePositionProperty.java
已删除
100644 → 0
浏览文件 @
d0a55912
package
com.alibaba.excel.metadata.property
;
import
com.alibaba.excel.annotation.write.style.ImagePosition
;
/**
* Keep the image position information from an annotation.
*
* @author Pengliang Zhao
*/
public
class
ImagePositionProperty
{
/**
* The x coordinate within the first cell.
*/
private
int
dx1
;
/**
* The y coordinate within the first cell.
*/
private
int
dy1
;
/**
* The x coordinate within the second cell.
*/
private
int
dx2
;
/**
* The y coordinate within the second cell
*/
private
int
dy2
;
/**
* 0-based column of the first cell.
*/
private
short
col1
;
/**
* 0-based row of the first cell.
*/
private
int
row1
;
/**
* 0-based column of the second cell.
*/
private
short
col2
;
/**
* 0-based row of the second cell.
*/
private
int
row2
;
public
static
ImagePositionProperty
build
(
ImagePosition
imagePosition
)
{
if
(
imagePosition
==
null
)
{
return
null
;
}
return
new
ImagePositionProperty
(
imagePosition
.
dx1
(),
imagePosition
.
dy1
(),
imagePosition
.
dx2
(),
imagePosition
.
dy2
(),
imagePosition
.
col1
(),
imagePosition
.
row1
(),
imagePosition
.
col2
(),
imagePosition
.
row2
());
}
public
ImagePositionProperty
(
int
dx1
,
int
dy1
,
int
dx2
,
int
dy2
,
short
col1
,
int
row1
,
short
col2
,
int
row2
)
{
this
.
dx1
=
dx1
;
this
.
dy1
=
dy1
;
this
.
dx2
=
dx2
;
this
.
dy2
=
dy2
;
this
.
col1
=
col1
;
this
.
row1
=
row1
;
this
.
col2
=
col2
;
this
.
row2
=
row2
;
}
public
int
getDx1
()
{
return
dx1
;
}
public
void
setDx1
(
int
dx1
)
{
this
.
dx1
=
dx1
;
}
public
int
getDy1
()
{
return
dy1
;
}
public
void
setDy1
(
int
dy1
)
{
this
.
dy1
=
dy1
;
}
public
int
getDx2
()
{
return
dx2
;
}
public
void
setDx2
(
int
dx2
)
{
this
.
dx2
=
dx2
;
}
public
int
getDy2
()
{
return
dy2
;
}
public
void
setDy2
(
int
dy2
)
{
this
.
dy2
=
dy2
;
}
public
short
getCol1
()
{
return
col1
;
}
public
void
setCol1
(
short
col1
)
{
this
.
col1
=
col1
;
}
public
int
getRow1
()
{
return
row1
;
}
public
void
setRow1
(
int
row1
)
{
this
.
row1
=
row1
;
}
public
short
getCol2
()
{
return
col2
;
}
public
void
setCol2
(
short
col2
)
{
this
.
col2
=
col2
;
}
public
int
getRow2
()
{
return
row2
;
}
public
void
setRow2
(
int
row2
)
{
this
.
row2
=
row2
;
}
}
src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java
浏览文件 @
54c9c36a
...
...
@@ -48,11 +48,8 @@ public enum ExcelTypeEnum {
}
// If there is a password, use the FileMagic first
if
(!
StringUtils
.
isEmpty
(
readWorkbook
.
getPassword
()))
{
BufferedInputStream
bufferedInputStream
=
new
BufferedInputStream
(
new
FileInputStream
(
file
));
try
{
try
(
BufferedInputStream
bufferedInputStream
=
new
BufferedInputStream
(
new
FileInputStream
(
file
)))
{
return
recognitionExcelType
(
bufferedInputStream
);
}
finally
{
bufferedInputStream
.
close
();
}
}
// Use the name to determine the type
...
...
@@ -63,11 +60,8 @@ public enum ExcelTypeEnum {
return
XLS
;
}
if
(
StringUtils
.
isEmpty
(
readWorkbook
.
getPassword
()))
{
BufferedInputStream
bufferedInputStream
=
new
BufferedInputStream
(
new
FileInputStream
(
file
));
try
{
try
(
BufferedInputStream
bufferedInputStream
=
new
BufferedInputStream
(
new
FileInputStream
(
file
)))
{
return
recognitionExcelType
(
bufferedInputStream
);
}
finally
{
bufferedInputStream
.
close
();
}
}
}
...
...
src/test/java/com/alibaba/easyexcel/test/demo/write/ImageDataWithAnnotation.java
浏览文件 @
54c9c36a
...
...
@@ -7,7 +7,6 @@ import java.net.URL;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
com.alibaba.excel.annotation.write.style.ColumnWidth
;
import
com.alibaba.excel.annotation.write.style.ContentRowHeight
;
import
com.alibaba.excel.annotation.write.style.ImagePosition
;
import
com.alibaba.excel.converters.string.StringImageConverter
;
import
lombok.Data
;
...
...
@@ -20,23 +19,18 @@ import lombok.Data;
@ContentRowHeight
(
100
)
@ColumnWidth
(
100
/
8
)
public
class
ImageDataWithAnnotation
{
@ImagePosition
(
dx1
=
0
,
dy1
=
0
,
dx2
=
0
,
dy2
=
0
,
col1
=
0
,
row1
=
3
,
col2
=
1
,
row2
=
4
)
private
File
file
;
@ImagePosition
(
dx1
=
0
,
dy1
=
0
,
dx2
=
0
,
dy2
=
0
,
col1
=
0
,
row1
=
1
,
col2
=
2
,
row2
=
2
)
private
InputStream
inputStream
;
/**
* 如果string类型 必须指定转换器,string默认转换成string
*/
@ExcelProperty
(
converter
=
StringImageConverter
.
class
)
@ImagePosition
(
dx1
=
0
,
dy1
=
0
,
dx2
=
0
,
dy2
=
0
,
col1
=
2
,
row1
=
1
,
col2
=
3
,
row2
=
3
)
private
String
string
;
@ImagePosition
(
dx1
=
0
,
dy1
=
0
,
dx2
=
0
,
dy2
=
0
,
col1
=
3
,
row1
=
1
,
col2
=
4
,
row2
=
5
)
private
byte
[]
byteArray
;
/**
* 根据url导出
*
* @since 2.1.1
*/
@ImagePosition
(
dx1
=
0
,
dy1
=
0
,
dx2
=
0
,
dy2
=
0
,
col1
=
4
,
row1
=
1
,
col2
=
5
,
row2
=
2
)
private
URL
url
;
}
src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
浏览文件 @
54c9c36a
...
...
@@ -9,12 +9,6 @@ import java.util.HashSet;
import
java.util.List
;
import
java.util.Set
;
import
org.apache.poi.ss.usermodel.FillPatternType
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
import
org.apache.poi.xssf.streaming.SXSSFSheet
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
com.alibaba.easyexcel.test.util.TestFileUtil
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.ExcelWriter
;
...
...
@@ -33,6 +27,12 @@ import com.alibaba.excel.write.metadata.style.WriteFont;
import
com.alibaba.excel.write.style.HorizontalCellStyleStrategy
;
import
com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy
;
import
org.apache.poi.ss.usermodel.FillPatternType
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
import
org.apache.poi.xssf.streaming.SXSSFSheet
;
import
org.junit.Ignore
;
import
org.junit.Test
;
/**
* 写的常见写法
*
...
...
@@ -257,39 +257,6 @@ public class WriteTest {
}
}
/**
* 使用注解设置图片位置,然后导出
* <p>
* 1. 创建excel对应的实体对象 参照{@link ImageData}
* <p>
* 2. 直接写即可
*/
@Test
public
void
imageWriteWithAnnotation
()
throws
Exception
{
String
fileName
=
TestFileUtil
.
getPath
()
+
"imageWriteWithAnnotation"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 如果使用流 记得关闭
InputStream
inputStream
=
null
;
try
{
List
<
ImageDataWithAnnotation
>
list
=
new
ArrayList
<
ImageDataWithAnnotation
>();
ImageDataWithAnnotation
imageData
=
new
ImageDataWithAnnotation
();
list
.
add
(
imageData
);
String
imagePath
=
TestFileUtil
.
getPath
()
+
"converter"
+
File
.
separator
+
"img.jpg"
;
// 放入五种类型的图片 实际使用只要选一种即可
imageData
.
setByteArray
(
FileUtils
.
readFileToByteArray
(
new
File
(
imagePath
)));
imageData
.
setFile
(
new
File
(
imagePath
));
imageData
.
setString
(
imagePath
);
inputStream
=
FileUtils
.
openInputStream
(
new
File
(
imagePath
));
imageData
.
setInputStream
(
inputStream
);
imageData
.
setUrl
(
new
URL
(
"https://raw.githubusercontent.com/alibaba/easyexcel/master/src/test/resources/converter/img.jpg"
));
EasyExcel
.
write
(
fileName
,
ImageDataWithAnnotation
.
class
).
sheet
().
doWrite
(
list
);
}
finally
{
if
(
inputStream
!=
null
)
{
inputStream
.
close
();
}
}
}
/**
* 根据模板写入
* <p>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录