1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > word excel转换成html格式的文件 将PPTWORDEXCEL转换成html格式

word excel转换成html格式的文件 将PPTWORDEXCEL转换成html格式

时间:2020-08-22 07:03:27

相关推荐

word excel转换成html格式的文件 将PPTWORDEXCEL转换成html格式

public static void PptToHtmlFile(string PptFilePath)

{

Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();

Microsoft.Office.Interop.PowerPoint.Presentation pptFile = null;

try

{

//获得html文件名

string htmlFileName = PptFilePath.Substring(0, PptFilePath.LastIndexOf(".")) + ".html";

//打开一个ppt文件

pptFile = ppt.Presentations.Open(PptFilePath, Microsoft.Office.Core.MsoTriState.msoTrue,

Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoFalse);

//转换成html格式

pptFile.SaveAs(htmlFileName, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML,

Microsoft.Office.Core.MsoTriState.msoCTrue);

}

finally

{

if (pptFile != null)

{

pptFile.Close();

}

ppt.Quit();

GC.Collect();

}

}

将Excel文件转换成HTML格式

Excel文件路径

public static void ExcelToHtmlFile(string ExcelFilePath)

{

Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();

Microsoft.Office.Interop.Excel.Workbook oBook = null;

缺省参数

object Unknown = Type.Missing;

try

{

目标html文件路径

object Target = ExcelFilePath.Substring(0, ExcelFilePath.LastIndexOf(".")) + ".html";

为了保险,只读方式打开

object readOnly = true;

指定另存为格式(html)

object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;

打开Excel文件

oBook = excelApp.Workbooks.Open(ExcelFilePath, Unknown, readOnly,

Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,

Unknown, Unknown, Unknown, Unknown, Unknown, Unknown);

转换格式

oBook.SaveAs(Target, format, Unknown, Unknown, Unknown, Unknown,

Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,

Unknown, Unknown, Unknown, Unknown, Unknown);

}

finally

{

if (oBook != null)

{

oBook.Close(false, Unknown, Unknown);

}

excelApp.Quit();

GC.Collect();

}

}

将Word文档转换成HTML格式

Word文档格式

public static void WordToHtmlFile(string WordFilePath)

{

Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();

Microsoft.Office.Interop.Word.Document doc = null;

缺省参数

object Unknown = Type.Missing;

try

{

指定原文件和目标文件

object Source = WordFilePath;

object Target = WordFilePath.Substring(0, WordFilePath.LastIndexOf(".")) + ".html";

为了保险,只读方式打开

object readOnly = true;

指定另存为格式(html)

object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;

打开doc文件

doc = newApp.Documents.Open(ref Source, ref Unknown, ref readOnly,

ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown,

ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);

转换格式 doc.SaveAs(ref Target, ref format, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown); } finally { if (doc != null) { 关闭文档和Word程序 doc.Close(ref Unknown, ref Unknown, ref Unknown); } newApp.Quit(ref Unknown, ref Unknown, ref Unknown); GC.Collect(); } }

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。