本文介绍使用Spire.Doc for Java给Word中的指定文本字符添加边框的方法。
import com.spire.doc.*;
import com.spire.doc.documents.BorderStyle;
import com.spire.doc.documents.TextSelection;
import java.awt.*;
public class TextrangeBoder {
    public static void main(String[] args) {
        //加载Word文档
        Document document = new Document("inputfile.docx");
        //查找文本
        TextSelection[] textSelections1 = document.findAllString("Spire.Doc for Java", false, false);
        //给文本字符串添加边框
        for (TextSelection selection : textSelections1)
        {
            selection.getAsOneRange().getCharacterFormat().getBorder().setBorderType(BorderStyle.Single);
            selection.getAsOneRange().getCharacterFormat().getBorder().setColor(Color.red);
            selection.getAsOneRange().getCharacterFormat().getBorder().setLineWidth(2);
        }
        //保存文档
        document.saveToFile("BorderToCharacter.docx", FileFormat.Docx_2013);
    }
}
 



 
					



