各位大哥:
    请帮小弟想想办法:我用word转成html文件,想在转的过程中把新生成的html body改成<body oncopy="return false;" onselectstart="return false;" oncontextmenu="return false;">,同时在加些js进去,不知道怎么加?
请帮帮我,谢谢啦!

解决方案 »

  1.   

    如果是用C#调用office tools来操作word转存为html
    可以在保存后通过htmlelement来取得body内容,直接添加修改即可
      

  2.   

    这是我转的代码,不知道您说的要加在哪里,小弟初学,请多帮忙 谢谢!
    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:\\web\\GRPSTest\\doc\\eGift_RLN_20090624.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:\\web\\GRPSTest\\doc\\test.htm";
        //下面是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
        ///
            
        //app.Selection.WholeStory();
        //app.Selection.Copy();
        //QuestionDoc.Activate();
        //app.Selection.Paste(); 
        
        //    Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML    //    document.body.innerHTML
            doc.
        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);        docType.InvokeMember(
        }
      

  3.   

    饿
    刚看到回复对html源文件编辑放在最后就可以了
    建议等待几秒再执行,因为InvokeMember可能没执行结束,文件还在占用