在编一个程序时遇见了一个问题. 
 有一个程序需要将一些WORD上传并转为html,而且这些word是有图片和表格。现在在转换为html时这些图片和表格被显示在web页面的左方,不随显示器的大小改变位置,但文字部分就会随显示器大小改变位置,这样图片等就不能居中显示,而且图片和文字还发生错位.请问各位大虾,该怎样解决这个问题??.

解决方案 »

  1.   

    Word.ApplicationClass   word   =   new   ApplicationClass();   
      Type   wordType   =   word.GetType();   
      Word.Documents   docs   =   word.Documents;   
        
      //   Open   word   document.   
      Type   docsType   =   docs.GetType();   
      object   fileName   =   "d:\\test.doc";   
      Word.Document   doc   =   (Word.Document)docsType.InvokeMember("Open",System.Reflection.BindingFlags.InvokeMethod,   null,   docs,   new   Object[]   {fileName,   true,   true});   
                            
      //   Save   as   html   file.   
      Type   docType   =   doc.GetType();   
      object   saveFileName   =   "d:\\test1.html";   
      docType.InvokeMember("SaveAs",   System.Reflection.BindingFlags.InvokeMethod,   
      null,   doc,   new   object[]{saveFileName,   Word.WdSaveFormat.wdFormatHTML});   
        
      //   Quit.   
      wordType.InvokeMember("Quit",   System.Reflection.BindingFlags.InvokeMethod,null,   word,   null);
      

  2.   

    我就是用二楼的方法转的,只写了转换的程序,并没有对web页面的大小进行控制。
     希望大家多给意见
    谢谢!!1
      

  3.   

    下面是我的转换代码:           public string wordToHtml(System.Web.UI.HtmlControls.HtmlInputFile wordFilePath)
            {            Word.ApplicationClass word = new Word.ApplicationClass();
                Type wordType = word.GetType();
                Word.Documents docs = word.Documents;
                // 打开文件
                Type docsType = docs.GetType();
                //应当先把文件上传至服务器然后再解析文件为html
                string filePath = uploadWord(wordFilePath);
                //判断是否上传文件成功
                if (filePath == "0")
                    return "0";            //判断是否为word文件
                if (filePath == "1")
                    return "1";
                object fileName = filePath;
                Word.Document doc = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true });            // 转换格式,另存为html
                Type docType = doc.GetType();            string filename = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() +System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString();
                //被转换的html文档保存的位置
                string ConfigPath = HttpContext.Current.Server.MapPath("upload/" + filename + ".html");
                TB_filepath.Text = "upload/" + filename + ".html";
                object saveFileName = ConfigPath;            docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML });
                // 退出 Word
                wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
                //转到新生成的页面
                return ("upload/" + filename + ".html");
            }