错误的显示格式为.doc

问题描述:

基本上我想在WWW显示.doc文件,我试图通过代码获取数据以下 我可以从.doc获取数据,但输出不是预期的格式。内部.DOC错误的显示格式为.doc

数据

Ç

输出结果

A B C

我的预期结果是

Ç

保护无效Button2_Click(对象发件人,EventArgs的) {

 Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); 

     // File Path 

     string strFilePath = @"C:\Users\Roy\Desktop\fypdoc.doc"; 

     // Create obj filename to pass it as paremeter in open 
     object objFile = strFilePath; object objNull = System.Reflection.Missing.Value; 

     object objReadOnly = true;//Open Document 
     Microsoft.Office.Interop.Word.Document Doc = wordApp.Documents.Open(ref objFile, ref objNull, ref objReadOnly, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull); 

     // To read each line consider each line as paragraph Docuemnt 

     int i = 1; 

     foreach (Microsoft.Office.Interop.Word.Paragraph objParagraph in Doc.Paragraphs) 
     { 

      try 
      { 
       p1.InnerHtml += Doc.Paragraphs[i].Range.Text.Replace(Environment.NewLine,"</br>"); 

      } 
      catch (Exception ex) { throw ex; } i++; 

     } // close document and Quit Word ApplicationDoc.Close(ref objNull, ref objNull, ref objNull); 

     wordApp.Quit(ref objNull, ref objNull, ref objNull); 

    } 

而不是使用换行符,尽量保留段落的语义值:

p1.InnerHtml += "<p>" + Doc.Paragraphs[i].Range.Text + "</p>"; 
+0

谢谢!!它的工作=) – 2012-02-02 09:50:40

尝试用<br />更换</br>

+0

它没有工作=( – 2012-02-02 09:39:40

我觉得这里的问题是,你在3个段落,可是并没有他们时之间添加添加行将它们转移到您的html。

看起来您正在循环每个段落,并且如果您希望每个段落都是由换行符分隔的文本块,那么它们本身不会包含任何换行符。

在连接文本或使用段落标记后添加br。