我想在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引用 - >插入标题做相同的标题的方式。
有些信息如何做到这一点将是非常赞赏。
Rui
使用此: http://www.microsoft.com/en-us/download/details.aspx?id=5124
(生产力工具) - 检查word文档,看看它们是由的。
这里将是代码:
SimpleField sf = new SimpleField(new Run(new Text("Figure 1")));
要真正连接东西,你需要设置sf
的instruction
属性。
下面是我用来创建标题的方法。 基本上,创建一个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;
}