0

我正在尝试在 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-> Insert Caption 中做同样的标题。

一些如何实现这一点的信息将不胜感激。

4

2 回答 2

4

这是我用来创建字幕的方法。基本上,创建一个 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;
        }
于 2014-12-23T21:34:09.917 回答
0

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

(生产力工具) - 检查word文档并查看它们的组成。

放这里是代码:

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

要实际链接任何内容,您需要设置sf'instruction属性。

于 2013-03-21T13:56:13.073 回答