或者你可以使用SharePoint解决,通常2003以上版本的office都支持 function viewWord() { var openDocObj; openDocObj = new ActiveXObject("SharePoint.OpenDocuments.2"); // 为了兼容Office XP,可以创建“SharePoint.OpenDocuments.1” openDocObj.ViewDocument("http://10.64.16.15:8088/webdav/12.doc"); }
么有安装SharePoint... 也不会让我在服务器上安装... 汗....
找到个其它办法.. 把文档转换为HTML 但还是不太符合要求... // 在此处放置用户代码以初始化页面 Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass(); Type wordType = word.GetType(); Microsoft.Office.Interop.Word.Documents docs = word.Documents; // 打开文件 Type docsType = docs.GetType(); object fileName = @"D:\Work\安信\Code\InvestmentBank\Repository\2.doc"; Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true }); // 转换格式,另存为 Type docType = doc.GetType(); object saveFileName = @"D:\Work\安信\Code\InvestmentBank\Repository\2.html"; //下面是Microsoft Word 9 Object Library的写法,如果是10,可能写成: /* docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML}); */ ///其它格式: ///wdFormatHTML ///wdFormatDocument ///wdFormatDOSText ///wdFormatDOSTextLineBreaks ///wdFormatEncodedText ///wdFormatRTF ///wdFormatTemplate ///wdFormatText ///wdFormatTextLineBreaks ///wdFormatUnicodeText docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML }); // 退出 Word wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
搂住可以试下把文件做成txt,然后用js引用进来,和小说网一样显示
怎么配置呢? 能具体说说吗?
谢谢.. 能给个代码我试试吗?
用JS启动word 应该也是调用了word进程吧.. 它的内容是在IE里显示的还是新打开一个word文件再显示的呢?
{
Response.Clear();
Response.ContentType="application/msword";
Response.WriteFile(Server.MapPath("~/aa.doc"));
Response.End();
}
function viewWord()
{
var openDocObj;
openDocObj = new ActiveXObject("SharePoint.OpenDocuments.2"); // 为了兼容Office XP,可以创建“SharePoint.OpenDocuments.1”
openDocObj.ViewDocument("http://10.64.16.15:8088/webdav/12.doc");
}
Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();
Type wordType = word.GetType();
Microsoft.Office.Interop.Word.Documents docs = word.Documents; // 打开文件
Type docsType = docs.GetType();
object fileName = @"D:\Work\安信\Code\InvestmentBank\Repository\2.doc";
Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true }); // 转换格式,另存为
Type docType = doc.GetType();
object saveFileName = @"D:\Work\安信\Code\InvestmentBank\Repository\2.html";
//下面是Microsoft Word 9 Object Library的写法,如果是10,可能写成:
/*
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML});
*/
///其它格式:
///wdFormatHTML
///wdFormatDocument
///wdFormatDOSText
///wdFormatDOSTextLineBreaks
///wdFormatEncodedText
///wdFormatRTF
///wdFormatTemplate
///wdFormatText
///wdFormatTextLineBreaks
///wdFormatUnicodeText
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML }); // 退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
null, word, null);
文档类型 键值
Microsoft Excel 7.0 worksheet Excel.Sheet.5
Microsoft Excel 97 worksheet Excel.Sheet.8
Microsoft Excel 2000 worksheet Excel.Sheet.8
Microsoft Word 7.0 document Word.Document.6
Microsoft Word 97 document Word.Document.8
Microsoft Word 2000 document Word.Document.8
bitsCN~com
Microsoft Project 98 project MSProject.Project.8
Microsoft PowerPoint 2000 document PowerPoint.Show.8
如果我们要修改Word文档的打开方式,,则在“HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Word.Document.8”下新建一个名为“BrowserFlags”,类型为“REG_DWORD”的子键值,如果设置其值为“8”,则在独立的窗口中打开Word文档,否则在嵌入IE的Word窗口中打开文档。
注:Microsoft Excel 7.0 worksheet稍有不同,应设置BrowserFlags的值为“9”方可在独立的窗口中打开文档。
【转自www.bitsCN.com】