poi 读取word标题,如何用POI来读取每个字的字体大小在Word文档中?

I am trying to find out whether there exist anything in the word document that has a font of 2. However, I have not been able to do this. To begin with, I've tried to read the font of each word in a sample word document that only has one line and 7 words. I am not getting the correct results.

Here is my code:

HWPFDocument doc = new HWPFDocument (fileStream);

WordExtractor we = new WordExtractor(doc);

Range range = doc.getRange()

String[] paragraphs = we.getParagraphText();

for (int i = 0; i < paragraphs.length; i++) {

Paragraph pr = range.getParagraph(i);

int k = 0

while (true) {

CharacterRun run = pr.getCharacterRun(k++);

System.out.println("Color: " + run.getColor());

System.out.println("Font: " + run.getFontName());

System.out.println("Font Size: " + run.getFontSize());

if (run.getEndOffSet() == pr.getEndOffSet())

break;

}

}

However, the above code always doubles the font size. i.e. if the actual font size in the document is 12 then it outputs 24 and if actual font is 8 then it outputs 16.

Is this the correct way to read font size from a word document ??

解决方案

Yes, that's the correct way; the measurement is in half points.

In a docx, you'd have something like:

Its the same with the binary doc format, which HWPF supports. If you look at [MS-DOC], you'll see it also specifies the size of text in half-points.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值