我正在尝试在OpenXml中创建这个结构:
<P>
<Table />
<Caption>Table 1 - Some Text 1 </Caption>
<Picture />
<Caption>Figure 1 - Some Text 2 </Caption>
</P>
就代码而言:
var currentLine = new Paragraph();
currentLine.AppendChild(new Run(elem)); -> Where the elem is Table
...
currentLine.AppendChild(new Run(elem2)); -> Where the elem2 is Drawing
所以我只想念添加字幕的方法,我在MS Word References中可以做的相同标题 - &gt;插入标题。
非常感谢如何实现这一目标的一些信息。
Rui
答案 0 :(得分:3)
这是我用来创建字幕的方法。基本上,创建一个SimpleField并将其附加到段落。
public Paragraph CreateCaption( string caption, string name )
{
Run run = new Run( new Text() { Text= name + " ", Space = SpaceProcessingModeValues.Preserve } );
SimpleField simpleField = new SimpleField( new Run( new RunProperties( new NoProof() ), new Text() { Text= " ", Space = SpaceProcessingModeValues.Preserve } ) );
simpleField.Instruction = @"SEQ " + name;
Run runLabel = new Run( new Text() { Text= " " + caption, Space = SpaceProcessingModeValues.Preserve } );
ParagraphProperties captionPr = new ParagraphProperties( new ParagraphStyleId() { Val = "Caption" } );
Paragraph paragraph = new Paragraph();
paragraph.ParagraphProperties = captionPr;
paragraph.Append( run );
paragraph.Append( simpleField );
paragraph.Append( runLabel );
return paragraph;
}
答案 1 :(得分:0)
使用此:http://www.microsoft.com/en-us/download/details.aspx?id=5124
(生产力工具) - 检查word文档并查看它们的组成。
这里是代码:
SimpleField sf = new SimpleField(new Run(new Text("Figure 1")));
要实际链接任何内容,您需要设置sf
的{{1}}属性。