Why does ParagraphFormat.getFirstLineIndent() return -28.35

请看一下附件里的template.zip (42.3 KB)这个模板文件,可以看到如附件里的


这个截图所示,first line indent是没有设置的。

然后当我在用Aspose Java的API去读取这个模板文件里的这个样式的first line indent时,发现得到的是-28.35,见附件里的


截图。截图里的程序如下,把new Document(new FileInputStream(“xxx.dotm”));这里的xxx.dotm换成附件里的模板文件路径即可。

package com.envision.sales.smartbid.check.service;

import com.aspose.words.*;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.io.FileInputStream;
import java.util.*;

@Slf4j
public class AsposeStyleTest {

    @SneakyThrows
    public  static void main(String [] args) {
        Document templateDoc = new Document(new FileInputStream("xxx.dotm"));
        Iterator<Style> styleIterator = templateDoc.getStyles().iterator();
        while(styleIterator.hasNext()) {
            Style style = styleIterator.next();
            if(style.getName().equals("技术附录A.1.1")) {
                System.out.println("first indent is " + style.getParagraphFormat().getFirstLineIndent());
            }
        }
    }
}

@leotest1234

Cause

The getFirstLineIndent() method returning a negative value, such as -28.35, typically indicates that the paragraph has a hanging indent set. This means that the first line of the paragraph is indented to the left of the left margin, resulting in a negative value.

Solution

To resolve this issue, you should check the paragraph formatting in your template document. If you want to set the first line indent to zero or a positive value, you can modify the paragraph format accordingly.

Code

Here’s how you can set the first line indent to a specific value using Aspose.Words for Java:

Document templateDoc = new Document(new FileInputStream("path/to/your/template.dotm"));
Iterator<Style> styleIterator = templateDoc.getStyles().iterator();
while (styleIterator.hasNext()) {
    Style style = styleIterator.next();
    if (style.getName().equals("技术附录A.1.1")) {
        // Set the first line indent to 0
        style.getParagraphFormat().setFirstLineIndent(0);
        System.out.println("First line indent set to " + style.getParagraphFormat().getFirstLineIndent());
    }
}

Next Steps

  1. Run the above code to set the first line indent to your desired value.
  2. Verify the changes by checking the output of getFirstLineIndent() again.
  3. If you still encounter issues, double-check the paragraph settings in your template file to ensure there are no conflicting styles or settings.

Please implement these steps, and let me know if you need further assistance!

这个模板文件不是我能修改的,然后我要做的其实是将一个word文件中的样式和这个模板文件中定义的样式进行对比,检查出相同名称但是样式属性不一样的样式。

我检查的是附件里这个文件,
sameStyle.docx (48.6 KB)
用我之前发的样例程序,得到的ParagraphFormat().getFirstLineIndent()结果是0,这个文件就是将模板文件另存为成的word文件。

结果见附件截图,

另外,我用Aspose版本25.2和25.6都有这个问题。

@leotest1234 我们将调查这个问题并给您回复。

@leotest1234 感谢您报告此问题。 我们已经在我们的内部问题跟踪系统中打开了以下新工单,并将根据 免费支持政策 中提到的条款提供它们的修复:

Issue ID(s): WORDSNET-28431

如果您需要优先支持以及直接联系我们的付费支持管理团队,您可以获得 付费支持服务

你好,想了解一下这个问题的进展,有没有一些发现或者是需要我提供更多的线索

@leotest1234 目前正在对该问题进行分析,尚无相关信息。

The issues you have found earlier (filed as WORDSNET-28431) have been fixed in this Aspose.Words for Java 25.8 update.

The issues you have found earlier (filed as WORDSNET-28431) have been fixed in this Aspose.Words for Java 25.8 update.