在word里有大量表格,现将word转换成html,但转换后表格并不是居中显示的,请问在程序里,如何做使word转换成html后 所有表格都是居中显示的???

解决方案 »

  1.   

    这是转换代码:
       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");
      

  2.   

    你这个是直接从word转换成html,中间无法处理了,看看转换成的html源码吧,用css控制一下看看可否
      

  3.   

    我试过在html源码里,加了<div align=center>,的确可以使表格居中,但这样有两个问题:
      1.如果转换的word多的话,每个都要到源码里改,很麻烦,客户肯定不愿这么做。
      2.有的用户并不能接触到html源码,所以也没法改。
    各位大侠给说说,有没有更好的方法??