Add a Caption to a Table or Figure in OpenXml

前端 未结 2 490
攒了一身酷
攒了一身酷 2021-01-28 03:58

I\'m trying to create this structure in OpenXml:

2条回答
  •  情深已故
    2021-01-28 04:27

    Here is the method I used to create Captions. Basically, create a SimpleField and append it to the paragraph.

    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;
            }
    

提交回复
热议问题
Table 1 - Some Text 1