Here is my code.

这是我的代码。

XWPFRun run = runlist.get(0);
double fontsize = (double)(run.getFontSize());
String fontfamily = (String)run.getFontFamily();

When it read the .docx file it will sometimes return -1 in font size and null in font family.

当它读取.docx文件时,它有时会返回字体大小为-1而字体系列为null。

I know that it's because they are default value but I don't want -1 and null I just want the name of that default value.

我知道这是因为它们是默认值但我不想-1和null我只想要该默认值的名称。

How can I read it?

我怎么读呢?

2 个解决方案

#1


The font/character properties on a XWPFRun only return the override details, so settings which are different on that run to the surrounding text

XWPFRun上的字体/字符属性仅返回覆盖详细信息,因此运行到周围文本的设置不同

If the run is using the default stylings, you'll need to move up to the XWPFParagraph it belongs to (or table etc), then call getStyleId() to get the style which applies to the paragraph.

如果运行使用默认样式,则需要向上移动到它所属的XWPFParagraph(或表等),然后调用getStyleId()以获取适用于段落的样式。

Then, on the document, call XWPFDocument.getStyles().getStyle(styleId) to get the XWPFStyle object that applies to the paragraph of interest.

然后,在文档上,调用XWPFDocument.getStyles()。getStyle(styleId)以获取适用于感兴趣段落的XWPFStyle对象。

From the style, you can fetch the properties defined in that style such as the font. You may also need to fetch the parent, if the style inherits from one.

从样式中,您可以获取该样式中定义的属性,例如字体。如果样式从一个继承,您可能还需要获取父级。

Currently, the XWPFStyle object is a bit low level, so patches to improve it would be gratefully received!

目前,XWPFStyle对象有点低级别,所以要感谢补丁以获得改进!

更多相关文章

  1. java中excel导出包括合并单元格和单元格样式

随机推荐

  1. android调用cocos2dx例子
  2. android 设置边框圆角
  3. android IP
  4. android 易忘知识
  5. Android之Notification
  6. java.net.SocketTimeoutException: conne
  7. Android基础-Android的生命周期
  8. Android 自定义进度条
  9. Android进度条总结
  10. android源码在线查看