c# 操作excel生成pdf
来源:互联网 发布:知乎 怪异故事和acfun 编辑:程序博客网 时间:2024/05/22 11:57
//将excel文档转换成PDF格式
private bool Convert2PDF(string sourcePath, string targetPath, XlFixedFormatType targetType)
{
bool result;
object missing = Type.Missing;
Excel.ApplicationClass application = null;
Workbook workBook = null;
try
{
application = new Excel.ApplicationClass();
object target = targetPath;
object type = targetType;
workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing);
workBook.ExportAsFixedFormat(targetType, target, XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
result = true;
}
catch
{
result = false;
}
finally
{
if (workBook != null)
{
workBook.Close(true, missing, missing);
workBook = null;
}
if (application != null)
{
application.Quit();
application = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
return result;
private bool Convert2PDF(string sourcePath, string targetPath, XlFixedFormatType targetType)
{
bool result;
object missing = Type.Missing;
Excel.ApplicationClass application = null;
Workbook workBook = null;
try
{
application = new Excel.ApplicationClass();
object target = targetPath;
object type = targetType;
workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing);
workBook.ExportAsFixedFormat(targetType, target, XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
result = true;
}
catch
{
result = false;
}
finally
{
if (workBook != null)
{
workBook.Close(true, missing, missing);
workBook = null;
}
if (application != null)
{
application.Quit();
application = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
return result;
}
调用
XlFixedFormatType parameter = XlFixedFormatType.xlTypePDF;
Convert2PDF(@"D://1.xls", @"D://1.pdf",parameter);
附大神原地址:
http://www.cnblogs.com/bayes/articles/DocToPdfCode.html
0 0
- c# 操作excel生成pdf
- VS+C#由创建的Excel生成PDF文档
- java 生成 pdf excel
- pdf如何生成excel
- C#对word、excel、pdf等格式文件的操作总结
- C#对word、excel、pdf等格式文件的操作总结
- c# excel转PDF
- C# 操作EXCEL样式 示例 --生成EXCEL审计表
- C#生成PDF文档
- c#生成pdf文件
- C#生成PDF文档
- C#生成PDF
- C#生成PDF表格
- C# HTML生成PDF
- C#生成PDF总结
- C#生成PDF总结
- C#生成PDF总结
- jsp 生成 word excel pdf
- Java基础中的一些知识点(二)
- android studio logger打印工具
- celert最佳实践
- WebApp开发之Cordova安装教程
- spring 启动打印所有beans
- c# 操作excel生成pdf
- Elasticsearch 在Windows下的安装
- python之socket编程
- Retrofit学习教程(4)-OAuth on Android
- 用mysql的十大理由
- oracle shutdown到nomount
- http 和 https 总结
- 使用 Tkprof 分析 ORACLE 跟踪文件
- 北大青鸟怎么样???是骗子吗??