2024年4月18日发(作者:)

计算机交流平台:计算机故障_计算机论坛 wy

C#实现Office文档转Pdf的方法

直接奉上源代码,运行环境:Office2010,Project2010(如果需要),Visio2010(如果需要),.net

framework2.0

[csharp]

using System;

using ;

namespace Office

{

class Util

{

private Util() { }

///

/// 把Word文件转换成为PDF格式文件

///

/// 源文件路径

/// 目标文件路径

/// true=转换成功

public static bool WordToPDF(string sourcePath, string targetPath)

{

bool result = false;

rtFormat exportFormat

rtFormatPDF;

ationClass application = null;

nt document = null;

try

{

application = new ationClass();

e = false;

document = (sourcePath);

2();

AsFixedFormat(targetPath, exportFormat);

result = true;

}

catch (Exception e)

{

ine(e);

result = false;

}

finally

{

=

计算机交流平台:计算机故障_计算机论坛 wy

if (document != null)

{

();

document = null;

}

if (application != null)

{

();

application = null;

}

t();

rPendingFinalizers();

t();

rPendingFinalizers();

}

return result;

}

///

/// 把文件转换成PDF格式文件

///

/// 源文件路径

/// 目标文件路径

/// true=转换成功

public static bool ExcelToPDF(string sourcePath, string targetPath)

{

bool result = false;

dFormatType targetType

PDF;

object missing = g;

ationClass application = null;

ok workBook = null;

try

{

application = new ationClass();

e = false;

workBook = (sourcePath);

();

AsFixedFormat(targetType, targetPath);

result = true;

}

catch (Exception e)

{

ine(e);

=