Free Support Forum - aspose.com

insertHtml的内容如何才能做到右对齐?


#1

我在word文档的最下面加入了一串LOGO,想让 builder.insertHtml插入的内容右对齐,我该如何做?
代码如下:
String DOC_LOGO = “谷歌中国欢迎你!”
DocumentBuilder builder = new DocumentBuilder(mInWordDoc);
Font font = builder.getFont();
font.setSize(12);
font.setColor(Color.BLACK);
font.setName(“Arial”);
builder.moveToDocumentEnd();
builder.write("\n");
builder.insertHtml("<a href=“https://www.google.com”>" + DOC_LOGO + “”);

谢谢!!!


#2

@jcing,

在这种情况下,以下代码将使插入的HTML右对齐。

Document doc = new Document("E:\\temp\\in.docx");

String DOC_LOGO = "Google China welcomes you!";
DocumentBuilder builder = new DocumentBuilder(doc);
Font font = builder.getFont();
font.setSize(12);
font.setColor(Color.BLACK);
font.setName ("Arial");
builder.moveToDocumentEnd();
builder.write("\n");

builder.getParagraphFormat().setAlignment(ParagraphAlignment.RIGHT);
builder.insertHtml("<a href='https://www.google.com'>" + DOC_LOGO + "</a>") ;

doc.save("E:\\temp\\awjava-19.1.docx");

#3

谢谢, 我试试看!:grinning: