Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
poc-api
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
poc
poc-api
Commits
9acbfe59
Commit
9acbfe59
authored
Feb 28, 2025
by
alex yao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:Excel文件加载问题
parent
a3fd0216
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
20 deletions
+12
-20
DocumentLoad.java
src/main/java/cn/com/poc/common/utils/DocumentLoad.java
+12
-20
No files found.
src/main/java/cn/com/poc/common/utils/DocumentLoad.java
View file @
9acbfe59
...
...
@@ -2,6 +2,8 @@ package cn.com.poc.common.utils;
import
cn.com.yict.framemax.core.i18n.I18nMessageException
;
import
cn.hutool.core.io.FileUtil
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.read.builder.ExcelReaderBuilder
;
import
io.github.furstenheim.*
;
import
org.apache.pdfbox.io.RandomAccessBufferedFileInputStream
;
import
org.apache.pdfbox.pdfparser.PDFParser
;
...
...
@@ -34,6 +36,7 @@ import java.net.URL;
import
java.net.URLConnection
;
import
java.nio.file.Files
;
import
java.util.Iterator
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
public
class
DocumentLoad
{
...
...
@@ -48,33 +51,22 @@ public class DocumentLoad {
public
static
String
excelToMarkdown
(
File
file
)
{
try
{
FileInputStream
inputStream
=
new
FileInputStream
(
file
);
Workbook
workbook
=
new
XSSFWorkbook
(
inputStream
);
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
Iterator
<
Row
>
rowIterator
=
sheet
.
iterator
();
List
<
Object
>
objects
=
EasyExcel
.
read
(
inputStream
)
.
sheet
()
.
doReadSync
();
StringBuilder
markdown
=
new
StringBuilder
();
while
(
rowIterator
.
hasNext
())
{
Row
row
=
rowIterator
.
next
();
Iterator
<
Cell
>
cellIterator
=
row
.
iterator
();
while
(
cellIterator
.
hasNext
())
{
Cell
cell
=
cellIterator
.
next
();
if
(
cell
.
getCellType
()
==
CellType
.
STRING
)
{
markdown
.
append
(
"| "
).
append
(
cell
.
getStringCellValue
());
}
else
if
(
cell
.
getCellType
()
==
CellType
.
NUMERIC
)
{
markdown
.
append
(
"| "
).
append
(
cell
.
getNumericCellValue
());
}
else
{
markdown
.
append
(
"| "
).
append
(
""
);
}
int
rowCount
=
objects
.
size
();
for
(
int
i
=
0
;
i
<
rowCount
;
i
++)
{
LinkedHashMap
linkedHashMap
=
(
LinkedHashMap
)
objects
.
get
(
i
);
int
cellCount
=
linkedHashMap
.
size
();
for
(
int
j
=
0
;
j
<
cellCount
;
j
++)
{
markdown
.
append
(
"| "
).
append
(
linkedHashMap
.
get
(
j
));
}
markdown
.
append
(
"|\n"
);
}
// 添加Markdown表格分隔线
markdown
.
insert
(
0
,
"|\n|--|--|\n"
);
workbook
.
close
();
inputStream
.
close
();
return
markdown
.
toString
();
}
catch
(
IOException
e
)
{
...
...
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