分类: Java
2021-04-24 15:16:45
通过textrange.getCharacterFormat()方法读取文本字符串格式,通过paragraph.getFormat()读取段落格式,读取具体文字及段落属性时,可支持读取字体、字号、文字颜色、文字背景、文字是否加粗或倾斜、文字下划线、大小写、边框、上标下标、行距、段落缩进、对齐方式、段落边框、背景等等,下表中罗列了所有可支持读取的样式属性,供参考:
读取文本格式 getCharacterFormat():
方法 |
类型 |
getFontName() |
String |
getFontNameAscii() |
String |
getFontNameBidi() |
String |
getFontNameFarEast() |
String |
getFontNameNonFarEast() |
String |
getBold() |
boolean |
getFontSize() |
float |
getHighlightColor() |
Color |
getItalic() |
boolean |
getTextBackgroundColor() |
Color |
getTextColor() |
Color |
getAllCaps() |
boolean |
getAllowContextualAlternates() |
boolean |
getBidi() |
boolean |
getBoldBidi() |
boolean |
getBorder() |
Border |
getCharacterSpacing() |
float |
getDoubleStrike() |
boolean |
getEmboss() |
boolean |
getEmphasisMark() |
Emphasis |
getEngrave() |
boolean |
getFontSizeBidi() |
float |
getFontTypeHint() |
FontTypeHint |
getHidden() |
boolean |
getItalicBidi() |
boolean |
getLigaturesType() |
LigatureType |
getLocaleIdASCII() |
short |
getLocaleIdFarEast() |
short |
getNumberFormType() |
NumberFormType |
getNumberSpaceType() |
NumberSpaceType |
getPosition() |
float |
getStylisticSetType() |
StylisticSetType |
getSubSuperScript() |
SubSuperScript |
getTextScale() |
short |
getUnderlineStyle() |
UnderlineStyle |
读取段落格式:getFormat()
方法 |
类型 |
getLineSpacing() |
float |
getFirstLineIndent() |
float |
getLeftIndent() |
float |
getAfterSpacing() |
float |
getBeforeSpacing() |
float |
getRightIndent() |
float |
getTextAlignment() |
TextAlignmnet |
getAfterAutoSpacing() |
boolean |
getAutoSpaceDE() |
boolean |
getAutoSpaceDN() |
boolean |
getBackColor() |
Color |
getBeforeAutoSpacing() |
boolean |
getBoders() |
Borders |
getHorizontalAlignment() |
HorizontalAlignmnet |
getKeepFollow() |
boolean |
getKeepLines() |
boolean |
getLineSpacingRule() |
LineSpacingRule |
getMirrorIndents() |
boolean |
getOutlineLevel() |
OutlineLevel |
getOverflowPunc() |
boolean |
getPageBreakAfter() |
boolean |
getPageBreakBefore() |
boolean |
getSuppressAutoHyphens() |
boolean |
getTabs() |
TabCollection |
用于测试的Word文档:
Java示例代码
点击(此处)折叠或打开
运行程序,输入获取结果: