[英]Insert a formatted footnote using Microsoft.Interop.Office.Word
I am trying to inset formatted footnotes into an open word document using a WinForms application. 我正在尝试使用WinForms应用程序将带格式的脚注插入到打开的Word文档中。
While I am able to use Interop.Word to set plain text footnotes and so long as I use plain text it works fine. 虽然我可以使用Interop.Word设置纯文本脚注,但只要使用纯文本,它就可以正常工作。 However, I also want the user to be able to paste rich text formatted text from a rich text box into the footnote.
但是,我也希望用户能够将格式丰富的文本从格式文本框中粘贴到脚注中。 This never works and always shows the rich text codes.
这永远不会起作用,并且总是显示富文本代码。
I know that footnotes can take formatting because if I put the rich text int a clipboard and paste it into a footnote the formatting is preserved. 我知道脚注可以采用格式,因为如果我将富文本插入剪贴板并将其粘贴到脚注中,则会保留格式。
I have even tried putting the rich text into the clipboard and then setting the string (s) to the clipboard contents using "s = Clipboard.GetText(TextDataFormat.Rtf);" 我什至尝试将富文本格式放入剪贴板,然后使用“ s = Clipboard.GetText(TextDataFormat.Rtf);”将字符串设置为剪贴板内容。 It seems as if this should be exactly what I am pasting, but if I paste into the footnote it works.
似乎这应该正是我要粘贴的内容,但是如果我将其粘贴到脚注中,则可以正常工作。 If the program sets it using the code below it does not work.
如果程序使用下面的代码对其进行设置,则它将不起作用。
I appreciate any help. 感谢您的帮助。
application = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
application.ActiveDocument.Footnotes.Add(application.Selection.Range, "", s);
Cindy's answer was helpful. 辛迪的回答很有帮助。 I fixed the problem by doing the following:
我通过执行以下操作解决了该问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.