题注添加到OpenXML的表或图(Add a Caption to a Table or Figur

2019-08-17 20:47发布

我想在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

Answer 1:

使用此: http://www.microsoft.com/en-us/download/details.aspx?id=5124

(生产力工具) - 检查word文档,看看它们是由的。

这里将是代码:

 SimpleField sf = new SimpleField(new Run(new Text("Figure 1")));

要真正连接东西,你需要设置sfinstruction属性。



Answer 2:

下面是我用来创建标题的方法。 基本上,创建一个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;
        }


文章来源: Add a Caption to a Table or Figure in OpenXml