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
81f94227
Commit
81f94227
authored
Jun 02, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
输出内容
parent
7a386d76
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
2 deletions
+41
-2
ExcelHttp.java
.../src/main/java/com/yanzuoguang/cloud/excel/ExcelHttp.java
+7
-0
ExcelConsole.java
...-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
+20
-2
ExportTempRes.java
...db/src/main/java/com/yanzuoguang/excel/ExportTempRes.java
+14
-0
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/excel/ExcelHttp.java
View file @
81f94227
...
@@ -3,9 +3,11 @@ package com.yanzuoguang.cloud.excel;
...
@@ -3,9 +3,11 @@ package com.yanzuoguang.cloud.excel;
import
com.yanzuoguang.cloud.helper.HttpFileHelper
;
import
com.yanzuoguang.cloud.helper.HttpFileHelper
;
import
com.yanzuoguang.excel.*
;
import
com.yanzuoguang.excel.*
;
import
com.yanzuoguang.util.helper.FileHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
org.springframework.http.MediaType
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.File
;
...
@@ -66,6 +68,9 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
...
@@ -66,6 +68,9 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
// 临时文件
// 临时文件
String
fileNameTemp
=
this
.
getFileNameTemp
();
String
fileNameTemp
=
this
.
getFileNameTemp
();
File
fileTemp
=
new
File
(
fileNameTemp
);
File
fileTemp
=
new
File
(
fileNameTemp
);
// 临时文件行数
String
fileNameRow
=
this
.
getFileNameRow
();
File
fileRow
=
new
File
(
fileNameRow
);
boolean
isDown
=
file
.
exists
();
boolean
isDown
=
file
.
exists
();
if
(
isDown
)
{
if
(
isDown
)
{
...
@@ -77,7 +82,9 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
...
@@ -77,7 +82,9 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
ExportTempRes
res
=
new
ExportTempRes
();
ExportTempRes
res
=
new
ExportTempRes
();
res
.
setFileName
(
fileName
);
res
.
setFileName
(
fileName
);
res
.
setSize
(
fileTemp
.
length
());
res
.
setSize
(
fileTemp
.
length
());
res
.
setRow
(
StringHelper
.
toLong
(
FileHelper
.
readFile
(
fileRow
,
"utf-8"
)));
// 输出结果
// 输出结果
response
.
setContentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
);
response
.
getWriter
().
print
(
JsonHelper
.
serialize
(
res
));
response
.
getWriter
().
print
(
JsonHelper
.
serialize
(
res
));
}
}
return
isDown
;
return
isDown
;
...
...
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
View file @
81f94227
...
@@ -10,6 +10,7 @@ import com.yanzuoguang.util.table.TableHeadItem;
...
@@ -10,6 +10,7 @@ import com.yanzuoguang.util.table.TableHeadItem;
import
org.apache.poi.hssf.util.HSSFColor
;
import
org.apache.poi.hssf.util.HSSFColor
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.xssf.streaming.SXSSFWorkbook
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
java.io.File
;
import
java.io.File
;
...
@@ -42,7 +43,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
...
@@ -42,7 +43,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
/**
/**
* 工作薄
* 工作薄
*/
*/
private
Workbook
workbook
;
private
SXSSF
Workbook
workbook
;
/**
/**
* 工作Sheet
* 工作Sheet
...
@@ -170,7 +171,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
...
@@ -170,7 +171,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
columnBytes
=
new
HashMap
<>();
columnBytes
=
new
HashMap
<>();
// 创建工作簿对象
// 创建工作簿对象
workbook
=
new
XSSFWorkbook
(
);
workbook
=
new
SXSSFWorkbook
(
100
);
sheet
=
workbook
.
createSheet
();
sheet
=
workbook
.
createSheet
();
style
=
initColumnCenterstyle
(
workbook
);
style
=
initColumnCenterstyle
(
workbook
);
...
@@ -308,6 +309,10 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
...
@@ -308,6 +309,10 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
}
}
rowIndex
++;
rowIndex
++;
if
(
this
.
rowIndex
%
100
==
0
)
{
FileHelper
.
writeFile
(
new
File
(
this
.
getFileNameRow
()),
StringHelper
.
toString
(
this
.
rowIndex
),
"utf-8"
);
}
}
}
/**
/**
...
@@ -409,6 +414,10 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
...
@@ -409,6 +414,10 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
if
(
this
.
workbook
!=
null
)
{
if
(
this
.
workbook
!=
null
)
{
workbook
=
null
;
workbook
=
null
;
}
}
File
fileRow
=
new
File
(
this
.
getFileNameRow
());
if
(
fileRow
.
exists
())
{
fileRow
.
delete
();
}
File
file
=
new
File
(
this
.
getFileName
());
File
file
=
new
File
(
this
.
getFileName
());
if
(
file
.
exists
())
{
if
(
file
.
exists
())
{
if
(!
file
.
delete
())
{
if
(!
file
.
delete
())
{
...
@@ -438,6 +447,15 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
...
@@ -438,6 +447,15 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
return
getFileName
()
+
".tmp"
;
return
getFileName
()
+
".tmp"
;
}
}
/**
* 获取保存文件名(全路径)
*
* @return 文件名
*/
public
String
getFileNameRow
()
{
return
getFileName
()
+
".row"
;
}
/**
/**
* 创建单元格
* 创建单元格
*
*
...
...
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExportTempRes.java
View file @
81f94227
...
@@ -22,6 +22,12 @@ public class ExportTempRes extends BaseVo {
...
@@ -22,6 +22,12 @@ public class ExportTempRes extends BaseVo {
@ApiModelProperty
(
notes
=
"已生成文件大小"
)
@ApiModelProperty
(
notes
=
"已生成文件大小"
)
private
long
size
;
private
long
size
;
/**
* 已生成文件行数
*/
@ApiModelProperty
(
notes
=
"已生成文件行数"
)
private
long
row
;
public
String
getFileName
()
{
public
String
getFileName
()
{
return
fileName
;
return
fileName
;
}
}
...
@@ -37,4 +43,12 @@ public class ExportTempRes extends BaseVo {
...
@@ -37,4 +43,12 @@ public class ExportTempRes extends BaseVo {
public
void
setSize
(
long
size
)
{
public
void
setSize
(
long
size
)
{
this
.
size
=
size
;
this
.
size
=
size
;
}
}
public
long
getRow
()
{
return
row
;
}
public
void
setRow
(
long
row
)
{
this
.
row
=
row
;
}
}
}
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