我的代码是想把word文件转换成html
但是我现在的代码只能将doc转换成html
但是office 2007 2010 的文件docs就不能转换了
求大神帮忙看一下
还有个问题是这个程序关闭时怎么删除刚生成的temp.html文件。using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using System.IO;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
main();
} private void main()
{ Microsoft.Office.Interop.Word.Application word = new ApplicationClass();
Type wordType = word.GetType();
Microsoft.Office.Interop.Word.Documents docs = word.Documents;
Type docsType = docs.GetType();
object fileName = "D://Test.docs";
Microsoft.Office.Interop.Word.Document doc = (Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true });
Type docType = doc.GetType();
object saveFileName = "D://temp.html";
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, WdSaveFormat.wdFormatHTML });
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null); }
}
}
但是我现在的代码只能将doc转换成html
但是office 2007 2010 的文件docs就不能转换了
求大神帮忙看一下
还有个问题是这个程序关闭时怎么删除刚生成的temp.html文件。using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using System.IO;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
main();
} private void main()
{ Microsoft.Office.Interop.Word.Application word = new ApplicationClass();
Type wordType = word.GetType();
Microsoft.Office.Interop.Word.Documents docs = word.Documents;
Type docsType = docs.GetType();
object fileName = "D://Test.docs";
Microsoft.Office.Interop.Word.Document doc = (Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true });
Type docType = doc.GetType();
object saveFileName = "D://temp.html";
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, WdSaveFormat.wdFormatHTML });
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null); }
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货