Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
769ad805
Commit
769ad805
authored
May 08, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Excel导出功能
parent
dc139fcf
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
801 additions
and
0 deletions
+801
-0
pom.xml
pom.xml
+6
-0
pom.xml
yzg-util-cloud/pom.xml
+6
-0
ExcelHttp.java
.../src/main/java/com/yanzuoguang/cloud/excel/ExcelHttp.java
+62
-0
pom.xml
yzg-util-db/pom.xml
+5
-0
ExcelConsole.java
...-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
+354
-0
ExcelMergerData.java
.../src/main/java/com/yanzuoguang/excel/ExcelMergerData.java
+72
-0
ExcelRow.java
...util-db/src/main/java/com/yanzuoguang/excel/ExcelRow.java
+18
-0
ExcelRowDefault.java
.../src/main/java/com/yanzuoguang/excel/ExcelRowDefault.java
+34
-0
ExportBase.java
...il-db/src/main/java/com/yanzuoguang/excel/ExportBase.java
+33
-0
ExportColumn.java
...-db/src/main/java/com/yanzuoguang/excel/ExportColumn.java
+63
-0
ExportData.java
...il-db/src/main/java/com/yanzuoguang/excel/ExportData.java
+148
-0
No files found.
pom.xml
View file @
769ad805
...
...
@@ -28,6 +28,7 @@
<spring.boot.version>
2.0.2.RELEASE
</spring.boot.version>
<fastjson.version>
1.2.47
</fastjson.version>
<mysql.version>
6.0.6
</mysql.version>
<poi.version>
3.9
</poi.version>
<yzg.version>
1.0-SNAPSHOT
</yzg.version>
</properties>
...
...
@@ -95,6 +96,11 @@
<version>
${yzg.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
<version>
${poi.version}
</version>
</dependency>
</dependencies>
</dependencyManagement>
...
...
yzg-util-cloud/pom.xml
View file @
769ad805
...
...
@@ -76,6 +76,12 @@
<groupId>
com.yanzuoguang
</groupId>
<artifactId>
yzg-util-base
</artifactId>
</dependency>
<dependency>
<groupId>
com.yanzuoguang
</groupId>
<artifactId>
yzg-util-db
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/excel/ExcelHttp.java
0 → 100755
View file @
769ad805
package
com
.
yanzuoguang
.
cloud
.
excel
;
import
com.yanzuoguang.cloud.helper.HttpFileHelper
;
import
com.yanzuoguang.excel.ExcelConsole
;
import
com.yanzuoguang.excel.ExcelRow
;
import
com.yanzuoguang.excel.ExportData
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
/**
* HTTP方式下载Excel文件
*
* @param <T> 行数据的类型
* @author 颜佐光
*/
public
class
ExcelHttp
<
T
extends
Object
>
extends
ExcelConsole
<
T
>
{
/**
* 导出成Excel
*
* @param exportData 导出信息
*/
public
ExcelHttp
(
ExportData
exportData
)
{
super
(
exportData
);
}
/**
* 导出成Excel
*
* @param config 导出信息
* @param rowHandle 导出下载信息
*/
public
ExcelHttp
(
ExportData
config
,
ExcelRow
<
T
>
rowHandle
)
{
super
(
config
,
rowHandle
);
}
/**
* 下载文件
*
* @param response 输出流
*/
public
ExcelHttp
down
(
HttpServletResponse
response
)
throws
IOException
{
return
this
.
down
(
response
,
StringHelper
.
EMPTY
);
}
/**
* 下载文件
*
* @param response 输出流
* @param downFileName 下载文件名
*/
public
ExcelHttp
down
(
HttpServletResponse
response
,
String
downFileName
)
throws
IOException
{
if
(
StringHelper
.
isEmpty
(
downFileName
)){
downFileName
=
this
.
getConfig
().
getFileName
();
}
HttpFileHelper
.
localToDown
(
this
.
getFileName
(),
downFileName
,
response
);
return
this
;
}
}
yzg-util-db/pom.xml
View file @
769ad805
...
...
@@ -49,5 +49,10 @@
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
0 → 100755
View file @
769ad805
This diff is collapsed.
Click to expand it.
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelMergerData.java
0 → 100644
View file @
769ad805
package
com
.
yanzuoguang
.
excel
;
import
com.yanzuoguang.util.helper.StringHelper
;
/**
* 数据合并处理
* @author 颜佐光
*/
public
class
ExcelMergerData
{
/**
* 上次合并的数据
*/
private
String
data
;
/**
* 合并行号
*/
private
int
rowIndex
=
-
1
;
/**
* 数据合并行数
*/
private
int
rowCell
;
/**
* 写入新数据
*
* @param rowIndex 行号
* @param nowCellData 新数据
*/
public
void
updateMerger
(
int
rowIndex
,
String
nowCellData
)
{
if
(
this
.
rowIndex
==
-
1
||
!
StringHelper
.
compare
(
this
.
data
,
nowCellData
))
{
this
.
rowIndex
=
rowIndex
;
this
.
data
=
nowCellData
;
this
.
rowCell
=
1
;
}
else
{
this
.
rowCell
++;
}
}
/**
* 写入数据,并且判断是否需要创建单元格
*
* @param nowCellData 需要写入的单元格的数据
* @return
*/
public
boolean
isMergerHistory
(
String
nowCellData
)
{
return
isMergerHistory
()
&&
!
StringHelper
.
compare
(
this
.
data
,
nowCellData
);
}
/**
* 是否合并单元格
*
* @return 合并标记
*/
public
boolean
isMergerHistory
()
{
return
rowCell
>
1
&&
rowIndex
>=
0
;
}
public
String
getData
()
{
return
data
;
}
public
int
getRowIndex
()
{
return
rowIndex
;
}
public
int
getRowCell
()
{
return
rowCell
;
}
}
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelRow.java
0 → 100755
View file @
769ad805
package
com
.
yanzuoguang
.
excel
;
/**
* 获取行中的某列数据
* @param <T>
* @author 颜佐光
*/
public
interface
ExcelRow
<
T
>
{
/**
* 获取行里面的某列数据
*
* @param row 行
* @param field 列
* @return
*/
String
get
(
T
row
,
String
field
);
}
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelRowDefault.java
0 → 100755
View file @
769ad805
package
com
.
yanzuoguang
.
excel
;
import
com.yanzuoguang.util.base.ObjectHelper
;
/**
* 行数据默认处理
* @author 颜佐光
*/
public
class
ExcelRowDefault
implements
ExcelRow
<
Object
>
{
/**
* 获取行里面的某列数据
*
* @param row 行
* @param field 列
* @return
*/
@Override
public
String
get
(
Object
row
,
String
field
)
{
return
ObjectHelper
.
getString
(
row
,
field
);
}
private
static
ExcelRowDefault
my
=
new
ExcelRowDefault
();
/**
* 获取默认实例
*
* @return
*/
public
static
ExcelRowDefault
getInstance
()
{
return
my
;
}
}
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExportBase.java
0 → 100755
View file @
769ad805
package
com
.
yanzuoguang
.
excel
;
/**
* 导出数据
* @param <T>
* @author 颜佐光
*/
public
class
ExportBase
<
T
extends
Object
>
{
/**
* 导出格式
*/
private
ExportData
config
;
/**
* 查询条件
*/
private
T
cond
;
public
ExportData
getConfig
()
{
return
config
;
}
public
void
setConfig
(
ExportData
config
)
{
this
.
config
=
config
;
}
public
T
getCond
()
{
return
cond
;
}
public
void
setCond
(
T
cond
)
{
this
.
cond
=
cond
;
}
}
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExportColumn.java
0 → 100755
View file @
769ad805
package
com
.
yanzuoguang
.
excel
;
/**
* 列设置
* @author 颜佐光
*/
public
class
ExportColumn
{
/**
* 列标题,如 A.B
*/
private
String
title
;
/**
* 数据单元格
*/
private
String
name
;
/**
* 数据是否合并
*/
private
boolean
merger
;
/**
* 高度
*/
private
short
width
;
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
boolean
isMerger
()
{
return
merger
;
}
public
void
setMerger
(
boolean
merger
)
{
this
.
merger
=
merger
;
}
public
short
getWidth
()
{
if
(
width
<
1
){
return
ExportData
.
COLUMN_WIDTH
;
}
return
width
;
}
public
void
setWidth
(
short
width
)
{
this
.
width
=
width
;
}
}
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExportData.java
0 → 100755
View file @
769ad805
package
com
.
yanzuoguang
.
excel
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 订单导出数据
*
* @author 颜佐光
*/
public
class
ExportData
{
public
static
final
short
ROW_HEIGHT_UNIT
=
10
;
public
static
final
short
TITLE_HEIGHT
=
80
;
public
static
final
short
SUB_TITLE_HEIGHT
=
40
;
public
static
final
short
HEAD_HEIGHT
=
20
;
public
static
final
short
ROW_HEIGHT
=
20
;
public
static
final
short
COLUMN_WIDTH
=
120
;
/**
* 服务器保存路径
*/
private
String
serverPath
;
/**
* 文件名
*/
private
String
fileName
;
/**
* 标题
*/
private
String
title
;
/**
* 标题高度
*/
private
short
titleHeight
;
/**
* 子标题
*/
private
String
subTitle
;
/**
* 子标题高度
*/
private
short
subTitleHeight
;
/**
* 列标题高度
*/
private
short
headHeight
;
/**
* 行高度
*/
private
short
rowHeight
;
/**
* 包含列
*/
private
List
<
ExportColumn
>
columns
=
new
ArrayList
<>();
public
String
getServerPath
()
{
return
serverPath
;
}
public
void
setServerPath
(
String
serverPath
)
{
this
.
serverPath
=
serverPath
;
}
public
String
getFileName
()
{
return
fileName
;
}
public
void
setFileName
(
String
fileName
)
{
this
.
fileName
=
fileName
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
short
getTitleHeight
()
{
if
(
titleHeight
<
1
)
{
return
TITLE_HEIGHT
;
}
return
titleHeight
;
}
public
void
setTitleHeight
(
short
titleHeight
)
{
this
.
titleHeight
=
titleHeight
;
}
public
String
getSubTitle
()
{
return
subTitle
;
}
public
void
setSubTitle
(
String
subTitle
)
{
this
.
subTitle
=
subTitle
;
}
public
short
getSubTitleHeight
()
{
if
(
subTitleHeight
<
1
)
{
return
SUB_TITLE_HEIGHT
;
}
return
subTitleHeight
;
}
public
void
setSubTitleHeight
(
short
subTitleHeight
)
{
this
.
subTitleHeight
=
subTitleHeight
;
}
public
short
getHeadHeight
()
{
if
(
headHeight
<
1
)
{
return
HEAD_HEIGHT
;
}
return
headHeight
;
}
public
void
setHeadHeight
(
short
headHeight
)
{
this
.
headHeight
=
headHeight
;
}
public
short
getRowHeight
()
{
if
(
rowHeight
<
1
)
{
return
ROW_HEIGHT
;
}
return
rowHeight
;
}
public
void
setRowHeight
(
short
rowHeight
)
{
this
.
rowHeight
=
rowHeight
;
}
public
List
<
ExportColumn
>
getColumns
()
{
return
columns
;
}
public
void
setColumns
(
List
<
ExportColumn
>
columns
)
{
this
.
columns
=
columns
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment