1

私のプログラムは、Word ファイルの脚注の番号を付け直す必要があります。

同じことを行うVBA-Macroがありますが、遅すぎます。

    Dim fussnote As Footnote
    For Each fussnote In ActiveDocument.Footnotes
    fussnote.Reference.Select
    With Selection
       With .FootnoteOptions
            .Location = wdBottomOfPage
            .NumberingRule = wdRestartContinuous
            .StartingNumber = 1
            .NumberStyle = wdNoteNumberStyleArabic
            .NumberingRule = wdRestartSection
       End With
       .Footnotes.Add range:=Selection.range, Reference:=""
    End With
Next

すべての脚注を複製してから、それら (およびその参照) を調べてIDを変更しようとしました ( Id は正しいプロパティですか?)

私のコードは次のようになります(動作していません):

        public override void Work(WordprocessingDocument args)
    {
        var __allFootnotes = (Footnotes)args.MainDocumentPart
            .FootnotesPart.Footnotes.Clone();
        var footnotes = __allFootnotes.Elements<Footnote>()
            .SkipWhile(f => !(f.Id.Value > 0)).ToList();
        RenumberFootnotes(footnotes, 
            args.MainDocumentPart.Document.Body.Descendants<Paragraph>().ToList());

        var __styles = args.MainDocumentPart
            .StyleDefinitionsPart.Styles;

        for (int i = 0; i < footnotes.Count(); i++)
        {
            //var footnote = footnotes[i];
        }

        args.MainDocumentPart.FootnotesPart
            .Footnotes = __allFootnotes;
    }


    private void RenumberFootnotes(List<Footnote> footnotes, List<Paragraph> paragraphs)
    {
        var __p = paragraphs.Where(p => p.Descendants<FootnoteReference>().Any());
        var __references = __p.SelectMany(p => p.Descendants<FootnoteReference>());
        for (int i = 1; i < footnotes.Count; i++)
        {
            var __tempId = footnotes[i].Id.Value;
            footnotes[i].Id.Value = i;
            var __reference = __references.First(fr => fr.Id.Value == __tempId);
            __reference.Id.Value = i;
        }
    }
4

1 に答える 1

0

質問から抽出された解決策:

新しい 'FootnoteReferenceMark' オブジェクトを Footnote の Run に追加する必要があります。「footnote」は、脚注の変数です。次に、タイプ「Run」の最初の子孫を取得し、「FootnoteReferenceMark」の新しい子を追加します。

footnote.Descendants<Run>().First().AppendChild(new FootnoteReferenceMark());
于 2015-03-03T00:39:12.300 に答える