简体   繁体   English

如何在富文本框中使用图像和项目符号打开Word文件

[英]How to open word file with images and bullets in a rich text box

Hi i am open a word file 2007(.doc file) in a rich text box through open dialog box. 嗨,我通过打开对话框在富文本框中打开Word文件2007(.doc文件)。 It works fine but images and bullets are not shown in a rich text box. 它可以正常工作,但富文本框中不会显示图像和项目符号。 i want to open open word file with images and bullets in a rich text box. 我想在一个富文本框中打开带有图像和项目符号的打开的Word文件。

I am using this code for open a word file and convert it to sentence by sentence. 我正在使用此代码打开一个Word文件,并将其转换为逐句。

Microsoft.Office.Interop.Word.ApplicationClass wordObject = new Microsoft.Office.Interop.Word.ApplicationClass();
object File = txtfilepath.Text; //this is the path
object nullobject = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Application wordobject = new Microsoft.Office.Interop.Word.Application();
wordobject.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone;
Microsoft.Office.Interop.Word._Document docs = wordObject.Documents.Open(ref File, ref nullobject, ref nullobject, ref nullobject,
                ref nullobject, ref nullobject, ref nullobject, ref nullobject,
                ref nullobject, ref nullobject, ref nullobject, ref nullobject,
                ref nullobject, ref nullobject, ref nullobject, ref nullobject);
                docs.ActiveWindow.Selection.WholeStory();
                docs.ActiveWindow.Selection.Copy();
                IDataObject data = Clipboard.GetDataObject();
                rtbgermanfile.Text = data.GetData(DataFormats.Text).ToString();
                string name = rtbgermanfile.Text.Trim();
                name = String.Join(Environment.NewLine, name.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries));
                string newtext = name.Replace("\n\n", "\n");
                string newtext2 = newtext.Replace("\n\n", "\n");
                rtbgermanfile.Text = newtext2.ToString();
                txtwriteingerman.Text = rtbgermanfile.Lines[0];
                docs.Close(ref nullobject, ref nullobject, ref nullobject);
                wordobject.Quit(ref nullobject, ref nullobject, ref nullobject);
                //wordobject.Quit(SaveChanges:false, OriginalFormat: false, RouteDocument: false);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(wordobject);

I don't think it is all that easy. 我认为这不是那么容易。 RTF or ANSI are the text data format's for rich text box if I recall correctly (maybe any of the TextDataFormat types). 如果我没记错的话,RTF或ANSI是富文本框的文本数据格式(可能是任何TextDataFormat类型)。 I can't talk to ANSI but RTF is not a great tool. 我无法与ANSI对话,但是RTF并不是一个很好的工具。

suggest using word itself. 建议使用单词本身。 http://msdn.microsoft.com/en-us/office2010developertrainingcourse_gettingstartedlab_topic3.aspx http://msdn.microsoft.com/zh-cn/office2010developertrainingcourse_gettingstartedlab_topic3.aspx

But if RTF check out this one for a hint of how to do this. 但是,如果是RTF,请查看此提示,以获取有关如何执行此操作的提示。 Programmatically adding Images to RTF Document 以编程方式将图像添加到RTF文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM