1 CuteEditor Html中显示Word格式粘贴的文章[CuteEditor WordToHtml]
3 word转换到CuteEditor:
函数uploadFileToEditor()的参数: urlstr 是指你要求的word文档的位置,(不知道为什么,貌似文件名中假如出现空格的时候,就会出问题,所以记住这一点,希望有人帮忙解答!)
同样...记得引用Microsoft.Office.Interop.Word;.dll
然后再文件上面添加:
using System.Web.UI.HtmlControls;
using Word = Microsoft.Office.Interop.Word;
using System.IO;
private void uploadFileToEditor(string urlstr)
{
//string filename = Request.QueryString["wordname"];
string filename = WordToHtml(urlstr);
StreamReader fread = new StreamReader(filename, System.Text.Encoding.GetEncoding("gb2312"));
string ss = fread.ReadToEnd();
Editor1.Text = ss;
//Response.Write(ss);
fread.Close();
fread.Dispose();
}
private string WordToHtml(object wordFileName)
{
//在此处放置用户代码以初始化页面
Word.ApplicationClass word = new Word.ApplicationClass();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;
//打开文件
Type docsType = docs.GetType();
Word.Document doc = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { wordFileName, true, true });
//转换格式,另存为
Type docType = doc.GetType();
string wordSaveFileName = wordFileName.ToString();
string strSaveFileName = wordSaveFileName.Substring(0, wordSaveFileName.Length - 3) + "html";
object saveFileName = (object)strSaveFileName;
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML });
docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, doc, null);
//退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
return saveFileName.ToString();
}
这个用法,有点笨吧,我是用来给CuteEditor添加”模板“的。
最主要的一句话:
string ss = fread.ReadToEnd();
Editor1.Text = ss;
.....不过貌似,还是有些格式的问题:
原图:
在CuteEditor里面显示的格式:
......暂时没找到解决方法.....待续...