求助,转换html后的格式问题?? 在word里有大量表格,现将word转换成html,但转换后表格并不是居中显示的,请问在程序里,如何做使word转换成html后 所有表格都是居中显示的??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是转换代码: 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"); 你这个是直接从word转换成html,中间无法处理了,看看转换成的html源码吧,用css控制一下看看可否 我试过在html源码里,加了<div align=center>,的确可以使表格居中,但这样有两个问题: 1.如果转换的word多的话,每个都要到源码里改,很麻烦,客户肯定不愿这么做。 2.有的用户并不能接触到html源码,所以也没法改。各位大侠给说说,有没有更好的方法?? visual studio 2005下编制的程序能在windows 7 下运行吗? C# 页面判断问题~ 奇怪的问题,为什么我用不了委托事件中的方法?? WebService 类型转换问题 怎样做一个后台删除功能 VS2008 WinForm打包的时候,添加项目输出组的都是空的是什么情况? 想过这个问题没有 获取oracle服务器当前时间 DataGrid时实打印程序!!! .net SDK升级问题,请速回(jackyhx) C#如何访问远程电脑上的ACESS数据库 如何改变datagridview的值
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");
1.如果转换的word多的话,每个都要到源码里改,很麻烦,客户肯定不愿这么做。
2.有的用户并不能接触到html源码,所以也没法改。
各位大侠给说说,有没有更好的方法??