-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如何插入word中表格或者图片的题注,就表序号和图的序号(How to insert the table or picture caption in the word, the table number and the number of the figure) #106
Comments
@jeremyliu17 图片或表格阳离子作为简单文本和带有适当标签的 SEQ 字段插入。 所以你可以使用这样的代码: Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("Table ");
builder.insertField("SEQ Table");
doc.save("C:\\Temp\\out.docx"); |
非常感谢,这样能够生成表1,表2...连续的序列,如果想生成这种形式表1-1,表1-2,第一个1表示跟随章节标题去变化,第二个数字为表的顺序,这种有好的办法解决吗 |
@jeremyliu17 如果可能的话,您能否使用 MS Word 创建预期的输出并附在此处供我们参考? 通过截图很难看出文档中使用了哪些字段。 |
期望输出.docx |
@jeremyliu17 感谢您提供更多信息。 在表格标题中有“STYLEREF”和“SEQ”字段: 因此,您应该插入两者以获得所需的输出: Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
doc.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1).getListFormat().applyNumberDefault();
builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
builder.writeln("This is some styled paragraph");
builder.getParagraphFormat().clearFormatting();
builder.write("Table ");
builder.insertField("STYLEREF \"Heading 1\" \\s");
builder.write("-");
builder.insertField("SEQ Table");
builder.write(" Some table caption");
doc.save("C:\\Temp\\out.docx"); |
No description provided.
The text was updated successfully, but these errors were encountered: