c# 操作excel生成pdf
2017-01-06 14:50
519 查看
//将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;
}
调用
XlFixedFormatType parameter = XlFixedFormatType.xlTypePDF;
Convert2PDF(@"D://1.xls", @"D://1.pdf",parameter);
附大神原地址:
http://www.cnblogs.com/bayes/articles/DocToPdfCode.html
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
相关文章推荐
- C#生成(操作)PDF
- 关于C#操作EXCEL,生成图表的全面应用之一(利用Microsoft.Office.Interop.Excel)【转载】
- c#生成Excel操作字体合并行等
- 用C#生成Excel文件的方法,Excel.dll组件生成的方法和设置用ASP.NET操作访问权限
- C# Spire操作Word文档生成PDF或JPG格式
- VS+C#由创建的Excel生成PDF文档
- C#对word、excel、pdf等格式文件的操作总结 .
- C#对word、excel、pdf等格式文件的操作总结
- 关于C#操作EXCEL,生成图表的全面应用之一(利用Microsoft.Office.Interop.Excel)
- C#对word、excel、pdf等格式文件的操作总结
- jfreechart,pdf生成组件iText,jasper report报表组件及POI操作excel等在企业软件开发中常遇到的第三方应用
- C#操作PDF文档--PDFBox读取pdf文档,O2S.Components.PDFRender4NET生成缩略图
- [转] C#操作EXCEL,生成图表的全面应用
- C#对word、excel、pdf等格式文件的操作总结
- C#对word、excel、pdf等格式文件的操作总结
- 关于C#操作EXCEL,生成图表的全面应用之一(利用Microsoft.Office.Interop.Excel) 收藏
- 关于C#操作EXCEL,生成图表的全面应用之二(利用Microsoft.Office.Interop.OWC11)
- C#对word、excel、pdf、csv等格式文件的操作总结
- C# 操作EXCEL样式 示例 --生成EXCEL审计表
- 用C#实现生成PDF文档(原码)