Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
E
event
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
陈世强
event
Commits
4d588d16
提交
4d588d16
authored
3月 26, 2025
作者:
yanxin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
处理excel单元格长度问题
上级
e946419c
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
290 行增加
和
0 行删除
+290
-0
SpreadsheetVersion.java
src/main/java/org/apache/poi/ss/SpreadsheetVersion.java
+122
-0
DocEntity.java
src/main/java/org/apache/poi/xwpf/usermodel/DocEntity.java
+14
-0
DocResult.java
src/main/java/org/apache/poi/xwpf/usermodel/DocResult.java
+11
-0
UXWPFDocument.java
...ain/java/org/apache/poi/xwpf/usermodel/UXWPFDocument.java
+20
-0
XWPFSDTContent.java
...in/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java
+123
-0
没有找到文件。
src/main/java/org/apache/poi/ss/SpreadsheetVersion.java
0 → 100644
浏览文件 @
4d588d16
package
org
.
apache
.
poi
.
ss
;
import
org.apache.poi.ss.util.CellReference
;
/**
* @author : wp
* @title : SpreadsheetVersion
* @description: 重写SpreadsheetVersion
* @date : Created in 2022/6/7 19:57
* @modified By:
*/
public
enum
SpreadsheetVersion
{
/**
* Excel97 format aka BIFF8
* <ul>
* <li>The total number of available rows is 64k (2^16)</li>
* <li>The total number of available columns is 256 (2^8)</li>
* <li>The maximum number of arguments to a function is 30</li>
* <li>Number of conditional format conditions on a cell is 3</li>
* <li>Number of cell styles is 4000</li>
* <li>Length of text cell contents is 32767</li>
* </ul>
*/
EXCEL97
(
0x10000
,
0x0100
,
30
,
3
,
4000
,
Integer
.
MAX_VALUE
),
/**
* Excel2007
*
* <ul>
* <li>The total number of available rows is 1M (2^20)</li>
* <li>The total number of available columns is 16K (2^14)</li>
* <li>The maximum number of arguments to a function is 255</li>
* <li>Number of conditional format conditions on a cell is unlimited
* (actually limited by available memory in Excel)</li>
* <li>Number of cell styles is 64000</li>
* <li>Length of text cell contents is 32767</li>
* <ul>
*/
EXCEL2007
(
0x100000
,
0x4000
,
255
,
Integer
.
MAX_VALUE
,
64000
,
Integer
.
MAX_VALUE
);
private
final
int
_maxRows
;
private
final
int
_maxColumns
;
private
final
int
_maxFunctionArgs
;
private
final
int
_maxCondFormats
;
private
final
int
_maxCellStyles
;
private
final
int
_maxTextLength
;
private
SpreadsheetVersion
(
int
maxRows
,
int
maxColumns
,
int
maxFunctionArgs
,
int
maxCondFormats
,
int
maxCellStyles
,
int
maxText
)
{
_maxRows
=
maxRows
;
_maxColumns
=
maxColumns
;
_maxFunctionArgs
=
maxFunctionArgs
;
_maxCondFormats
=
maxCondFormats
;
_maxCellStyles
=
maxCellStyles
;
_maxTextLength
=
maxText
;
}
/**
* @return the maximum number of usable rows in each spreadsheet
*/
public
int
getMaxRows
()
{
return
_maxRows
;
}
/**
* @return the last (maximum) valid row index, equals to <code> getMaxRows() - 1 </code>
*/
public
int
getLastRowIndex
()
{
return
_maxRows
-
1
;
}
/**
* @return the maximum number of usable columns in each spreadsheet
*/
public
int
getMaxColumns
()
{
return
_maxColumns
;
}
/**
* @return the last (maximum) valid column index, equals to <code> getMaxColumns() - 1 </code>
*/
public
int
getLastColumnIndex
()
{
return
_maxColumns
-
1
;
}
/**
* @return the maximum number arguments that can be passed to a multi-arg function (e.g. COUNTIF)
*/
public
int
getMaxFunctionArgs
()
{
return
_maxFunctionArgs
;
}
/**
* @return the maximum number of conditional format conditions on a cell
*/
public
int
getMaxConditionalFormats
()
{
return
_maxCondFormats
;
}
/**
* @return the maximum number of cell styles per spreadsheet
*/
public
int
getMaxCellStyles
()
{
return
_maxCellStyles
;
}
/**
*
* @return the last valid column index in a ALPHA-26 representation
* (<code>IV</code> or <code>XFD</code>).
*/
public
String
getLastColumnName
()
{
return
CellReference
.
convertNumToColString
(
getLastColumnIndex
());
}
/**
* @return the maximum length of a text cell
*/
public
int
getMaxTextLength
()
{
return
_maxTextLength
;
}
}
src/main/java/org/apache/poi/xwpf/usermodel/DocEntity.java
0 → 100644
浏览文件 @
4d588d16
package
org
.
apache
.
poi
.
xwpf
.
usermodel
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
DocEntity
{
public
String
name
;
public
String
content
;
public
List
<
DocEntity
>
section
;
public
String
parentId
;
public
String
id
;
}
src/main/java/org/apache/poi/xwpf/usermodel/DocResult.java
0 → 100644
浏览文件 @
4d588d16
package
org
.
apache
.
poi
.
xwpf
.
usermodel
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
DocResult
{
String
content
;
List
<
DocEntity
>
chapter
;
}
src/main/java/org/apache/poi/xwpf/usermodel/UXWPFDocument.java
0 → 100644
浏览文件 @
4d588d16
package
org
.
apache
.
poi
.
xwpf
.
usermodel
;
import
org.apache.poi.xwpf.usermodel.XWPFDocument
;
import
org.apache.poi.xwpf.usermodel.XWPFSDT
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.List
;
public
class
UXWPFDocument
extends
XWPFDocument
{
public
UXWPFDocument
(
InputStream
inputStream
)
throws
IOException
{
super
(
inputStream
);
}
public
List
<
XWPFSDT
>
getContentControls
()
{
return
this
.
contentControls
;
}
}
src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java
0 → 100644
浏览文件 @
4d588d16
package
org
.
apache
.
poi
.
xwpf
.
usermodel
;
import
org.apache.poi.xwpf.usermodel.*
;
import
org.apache.xmlbeans.XmlCursor
;
import
org.apache.xmlbeans.XmlObject
;
import
org.openxmlformats.schemas.wordprocessingml.x2006.main.*
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
XWPFSDTContent
implements
ISDTContent
{
public
List
<
ISDTContents
>
getBodyElements
()
{
return
bodyElements
;
}
public
void
setBodyElements
(
List
<
ISDTContents
>
bodyElements
)
{
this
.
bodyElements
=
bodyElements
;
}
// private final IBody part;
// private final XWPFDocument document;
// private List<XWPFParagraph> paragraphs = new ArrayList<>();
// private List<XWPFTable> tables = new ArrayList<>();
// private List<XWPFRun> runs = new ArrayList<>();
// private List<XWPFSDT> contentControls = new ArrayList<>();
private
List
<
ISDTContents
>
bodyElements
=
new
ArrayList
<>();
public
XWPFSDTContent
(
CTSdtContentRun
sdtRun
,
IBody
part
,
IRunBody
parent
)
{
if
(
sdtRun
==
null
)
{
return
;
}
for
(
CTR
ctr
:
sdtRun
.
getRArray
())
{
XWPFRun
run
=
new
XWPFRun
(
ctr
,
parent
);
// runs.add(run);
bodyElements
.
add
(
run
);
}
}
public
XWPFSDTContent
(
CTSdtContentBlock
block
,
IBody
part
,
IRunBody
parent
)
{
if
(
block
==
null
)
{
return
;
}
XmlCursor
cursor
=
block
.
newCursor
();
cursor
.
selectPath
(
"./*"
);
while
(
cursor
.
toNextSelection
())
{
XmlObject
o
=
cursor
.
getObject
();
if
(
o
instanceof
CTP
)
{
XWPFParagraph
p
=
new
XWPFParagraph
((
CTP
)
o
,
part
);
bodyElements
.
add
(
p
);
// paragraphs.add(p);
}
else
if
(
o
instanceof
CTTbl
)
{
XWPFTable
t
=
new
XWPFTable
((
CTTbl
)
o
,
part
);
bodyElements
.
add
(
t
);
// tables.add(t);
}
else
if
(
o
instanceof
CTSdtBlock
)
{
XWPFSDT
c
=
new
XWPFSDT
(((
CTSdtBlock
)
o
),
part
);
bodyElements
.
add
(
c
);
// contentControls.add(c);
}
else
if
(
o
instanceof
CTR
)
{
XWPFRun
run
=
new
XWPFRun
((
CTR
)
o
,
parent
);
// runs.add(run);
bodyElements
.
add
(
run
);
}
}
cursor
.
dispose
();
}
@Override
public
String
getText
()
{
StringBuilder
text
=
new
StringBuilder
();
boolean
addNewLine
=
false
;
for
(
int
i
=
0
;
i
<
bodyElements
.
size
();
i
++)
{
Object
o
=
bodyElements
.
get
(
i
);
if
(
o
instanceof
XWPFParagraph
)
{
appendParagraph
((
XWPFParagraph
)
o
,
text
);
addNewLine
=
true
;
}
else
if
(
o
instanceof
XWPFTable
)
{
appendTable
((
XWPFTable
)
o
,
text
);
addNewLine
=
true
;
}
else
if
(
o
instanceof
XWPFSDT
)
{
text
.
append
(((
XWPFSDT
)
o
).
getContent
().
getText
());
addNewLine
=
true
;
}
else
if
(
o
instanceof
XWPFRun
)
{
text
.
append
(
o
);
addNewLine
=
false
;
}
if
(
addNewLine
&&
i
<
bodyElements
.
size
()
-
1
)
{
text
.
append
(
"\n"
);
}
}
return
text
.
toString
();
}
private
void
appendTable
(
XWPFTable
table
,
StringBuilder
text
)
{
//this works recursively to pull embedded tables from within cells
for
(
XWPFTableRow
row
:
table
.
getRows
())
{
List
<
ICell
>
cells
=
row
.
getTableICells
();
for
(
int
i
=
0
;
i
<
cells
.
size
();
i
++)
{
ICell
cell
=
cells
.
get
(
i
);
if
(
cell
instanceof
XWPFTableCell
)
{
text
.
append
(((
XWPFTableCell
)
cell
).
getTextRecursively
());
}
else
if
(
cell
instanceof
XWPFSDTCell
)
{
text
.
append
(((
XWPFSDTCell
)
cell
).
getContent
().
getText
());
}
if
(
i
<
cells
.
size
()
-
1
)
{
text
.
append
(
"\t"
);
}
}
text
.
append
(
'\n'
);
}
}
private
void
appendParagraph
(
XWPFParagraph
paragraph
,
StringBuilder
text
)
{
for
(
IRunElement
run
:
paragraph
.
getRuns
())
{
text
.
append
(
run
);
}
}
@Override
public
String
toString
()
{
return
getText
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论