关于Microsoft.Office的另存为操作 急!!!!
if (_fileType == "DOC" || _fileType == "DOCX")
{
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(@HostingEnvironment.ApplicationPhysicalPath + "/" + _originalFilePath);
doc.SaveAs2(@HostingEnvironment.ApplicationPhysicalPath + "/" + _savedFilePath, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatWebArchive);
app.Quit();
}
else if (_fileType == "XLS" || _fileType == "XLSX")
{
Microsoft.Office.Interop.Excel.Application work = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook xls = work.Workbooks.Open(@HostingEnvironment.ApplicationPhysicalPath + "/" + _originalFilePath);
xls.SaveAs(@HostingEnvironment.ApplicationPhysicalPath + "/" + _savedFilePath, Microsoft.Office.Interop.Excel.XlFileFormat.xlWebArchive);
work.Quit();
}
else if (_fileType == "PPT" || _fileType == "PPTX")
{
Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application();
Microsoft.Office.Interop.PowerPoint.Presentation ppt=app.Presentations.Open(@HostingEnvironment.ApplicationPhysicalPath + "/" + _originalFilePath);
ppt.SaveAs(@HostingEnvironment.ApplicationPhysicalPath + "/" + _savedFilePath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsWebArchive);
app.Quit();
}
注:_savedFilePath是我自己拼接的字符串路径后缀名为.mht,_originalFilePath是已存在的文件的相对路径
为什么保存Excel文件的时候报错了,保存PPT文件的时候,竟然自己打开了另存为之后的文件了。