Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
common
Project
Project
Details
Activity
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
曲欣亮
common
Commits
f6ae26bc
Commit
f6ae26bc
authored
Dec 01, 2020
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
43a90d05
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
20 deletions
+16
-20
ExcelUtil.java
src/main/java/com/egolm/common/ExcelUtil.java
+16
-20
No files found.
src/main/java/com/egolm/common/ExcelUtil.java
View file @
f6ae26bc
...
@@ -14,12 +14,12 @@ import java.util.Map;
...
@@ -14,12 +14,12 @@ import java.util.Map;
import
org.apache.poi.hssf.usermodel.HSSFCell
;
import
org.apache.poi.hssf.usermodel.HSSFCell
;
import
org.apache.poi.hssf.usermodel.HSSFCellStyle
;
import
org.apache.poi.hssf.usermodel.HSSFCellStyle
;
import
org.apache.poi.hssf.usermodel.HSSFDateUtil
;
import
org.apache.poi.hssf.usermodel.HSSFRichTextString
;
import
org.apache.poi.hssf.usermodel.HSSFRichTextString
;
import
org.apache.poi.hssf.usermodel.HSSFRow
;
import
org.apache.poi.hssf.usermodel.HSSFRow
;
import
org.apache.poi.hssf.usermodel.HSSFSheet
;
import
org.apache.poi.hssf.usermodel.HSSFSheet
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.CellType
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Row
;
/**
/**
...
@@ -78,8 +78,7 @@ public class ExcelUtil {
...
@@ -78,8 +78,7 @@ public class ExcelUtil {
* @param widths 列宽度{24, 12, 15, 15}
* @param widths 列宽度{24, 12, 15, 15}
*/
*/
public
static
void
excel
(
OutputStream
os
,
Object
[][]
objs
,
Integer
[]
widths
)
{
public
static
void
excel
(
OutputStream
os
,
Object
[][]
objs
,
Integer
[]
widths
)
{
try
{
try
(
HSSFWorkbook
wb
=
new
HSSFWorkbook
())
{
HSSFWorkbook
wb
=
new
HSSFWorkbook
();
HSSFCellStyle
bodyStyle
=
wb
.
createCellStyle
();
HSSFCellStyle
bodyStyle
=
wb
.
createCellStyle
();
bodyStyle
.
setWrapText
(
true
);
bodyStyle
.
setWrapText
(
true
);
HSSFSheet
sheet
=
wb
.
createSheet
(
"sheet1"
);
HSSFSheet
sheet
=
wb
.
createSheet
(
"sheet1"
);
...
@@ -194,8 +193,7 @@ public class ExcelUtil {
...
@@ -194,8 +193,7 @@ public class ExcelUtil {
* @throws IOException
* @throws IOException
*/
*/
public
static
String
[][]
excel
(
InputStream
is
)
{
public
static
String
[][]
excel
(
InputStream
is
)
{
try
{
try
(
HSSFWorkbook
wb
=
new
HSSFWorkbook
(
is
))
{
HSSFWorkbook
wb
=
new
HSSFWorkbook
(
is
);
HSSFSheet
sheet
=
wb
.
getSheetAt
(
0
);
HSSFSheet
sheet
=
wb
.
getSheetAt
(
0
);
String
[][]
datas
=
new
String
[
sheet
.
getLastRowNum
()+
1
][];
String
[][]
datas
=
new
String
[
sheet
.
getLastRowNum
()+
1
][];
for
(
int
i
=
0
;
i
<
datas
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
datas
.
length
;
i
++)
{
...
@@ -220,33 +218,31 @@ public class ExcelUtil {
...
@@ -220,33 +218,31 @@ public class ExcelUtil {
* @return
* @return
*/
*/
private
static
String
stringVal
(
Cell
cell
)
{
private
static
String
stringVal
(
Cell
cell
)
{
try
{
if
(
cell
!=
null
)
{
int
cellType
=
cell
.
getCellType
();
CellType
cellType
=
cell
.
getCellType
();
if
(
cellType
==
HSSFCell
.
CELL_TYPE_
NUMERIC
)
{
if
(
cellType
==
CellType
.
NUMERIC
)
{
if
(
HSSF
DateUtil
.
isCellDateFormatted
(
cell
))
{
if
(
org
.
apache
.
poi
.
ss
.
usermodel
.
DateUtil
.
isCellDateFormatted
(
cell
))
{
return
DateUtil
.
format
(
HSSF
DateUtil
.
getJavaDate
(
cell
.
getNumericCellValue
()));
return
DateUtil
.
format
(
org
.
apache
.
poi
.
ss
.
usermodel
.
DateUtil
.
getJavaDate
(
cell
.
getNumericCellValue
()));
}
else
{
}
else
{
return
String
.
valueOf
(
FMT_INT
.
format
(
cell
.
getNumericCellValue
()));
return
String
.
valueOf
(
FMT_INT
.
format
(
cell
.
getNumericCellValue
()));
}
}
}
else
if
(
cellType
==
HSSFCell
.
CELL_TYPE_
STRING
)
{
}
else
if
(
cellType
==
CellType
.
STRING
)
{
return
String
.
valueOf
(
cell
.
getRichStringCellValue
()
);
return
cell
.
getStringCellValue
(
);
}
else
if
(
cellType
==
HSSFCell
.
CELL_TYPE_
FORMULA
)
{
}
else
if
(
cellType
==
CellType
.
FORMULA
)
{
String
value
=
String
.
valueOf
(
cell
.
getNumericCellValue
());
String
value
=
String
.
valueOf
(
cell
.
getNumericCellValue
());
if
(
value
.
equals
(
"NaN"
))
{
if
(
value
.
equals
(
"NaN"
))
{
value
=
String
.
valueOf
(
cell
.
getRichStringCellValue
());
value
=
String
.
valueOf
(
cell
.
getRichStringCellValue
());
}
}
return
value
;
return
value
;
}
else
if
(
cellType
==
HSSFCell
.
CELL_TYPE_
BOOLEAN
)
{
}
else
if
(
cellType
==
CellType
.
BOOLEAN
)
{
return
String
.
valueOf
(
cell
.
getBooleanCellValue
());
return
String
.
valueOf
(
cell
.
getBooleanCellValue
());
}
else
if
(
cellType
==
HSSFCell
.
CELL_TYPE_BLANK
)
{
}
else
if
(
cellType
==
CellType
.
BLANK
||
cellType
==
CellType
.
ERROR
)
{
return
""
;
}
else
if
(
cellType
==
HSSFCell
.
CELL_TYPE_ERROR
)
{
return
""
;
return
""
;
}
else
{
}
else
{
return
String
.
valueOf
(
cell
.
getRichStringCellValue
()
);
return
cell
.
getStringCellValue
(
);
}
}
}
catch
(
Exception
e
)
{
}
else
{
return
null
;
return
""
;
}
}
}
}
...
...
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