如何将execl word 转化成流 然后保存到页面显示出来啊、!!!!
有一个文件,文件后面有两个按钮,一个是显示一个是下载,点击显示的时候直接显示为html格式文本。
看了你的回复,瞬间觉得,你要的仅仅的代码~
建议搜下 Aspose.Word 非常好用,能直接把word转换成html。
一般是office转pdf,再转swf 就可以在线预览
/// <summary>
///
/// </summary>
/// <param name="filePath">文件路径</param>
/// <param name="htmlPath">保存html格式的路径</param>
public static void WordHtml(string filePath, string htmlPath)
{
Word.Application wordApp;
Word.Document wordDoc;
Object Nothing = Missing.Value;
Console.WriteLine("Input path:");
Object path = Console.ReadLine();
path = filePath;
wordApp = new Word.ApplicationClass();
wordDoc = wordApp.Documents.Add(ref path, ref Nothing, ref Nothing, ref Nothing);
object format = Word.WdSaveFormat.wdFormatFilteredHTML;
Object newPath = htmlPath;
wordDoc.SaveAs(ref newPath, ref format, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
}
/// <summary>
///
/// </summary>
/// <param name="filePath">文件路径</param>
/// <param name="htmlPath">保存html格式的路径</param>
public static void ExeclHtml(string filePath, string htmlPath)
{
try
{
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
app.Visible = false;
app.DisplayAlerts = false;
object o = Missing.Value;
Microsoft.Office.Interop.Excel.Workbook workbook = null;
workbook = app.Workbooks.Open(filePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
object fileName = htmlPath;
object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;
workbook.SaveAs(fileName, format, o, o, o, o, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, o, o, o, o);
app.Quit();
Process[] myProces = Process.GetProcessesByName("EXCEL");
foreach (Process proces in myProces)
{
proces.Kill();
}
}
catch (Exception ex)
{
System.Console.Write(ex.Message);
}
}