Excel转PDF文件,Excel转TIF文件

Excel文件转PDF文件,可以利用Excel对象的另存为函数,C#代码如下:

 1 //打开excel文件
 2                 Excel.Workbook xBook = xApp.Workbooks.Open(psExcelName,...);
 3 
 4 
 5 //创建Excel文件对应的PDF文件
 6                     xBook.ExportAsFixedFormat(XlFixedFormatType.xlTypePDF,
 7                             PDFPathAndName, XlFixedFormatQuality.xlQualityStandard,
 8                             truetrue, Missing.Value,
 9                             Missing.Value, false,
10                             Missing.Value);

 

ExprotAsFixedFormat函数原型如下:

 

void ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType Type, object Filename, object Quality, object IncludeDocProperties, object IgnorePrintAreas, object From, object To, object OpenAfterPublish, object FixedFormatExtClassPtr)

 

XlFixedFormatType: 指定excel另存为文件类型。可以为xlTypePDF 和xlTypeXPS

Filename: 指定另存为文件名,完整路径。

Quality: 指定文件质量,可以为xlQualityStandard,xlQualityMinimum

IncludeDocProperties: true或者false

IngorePrintAreas: true或者false

From: 指定起始页

To: 指定终止页

OpenAfterPublish: 指示生成文件后,是否马上显示出来,true或者false

FixedFormatExtCalssPtr:  Pointer to the FixedFormatExt class

 

 



Excel文件转TIF文件,可以利用printer,把Excel文件打印成TIF文件,并在本地保存

 

1 //创建Excel文件对应的TIF文件
2                     string printerName = "Microsoft Office Document Image Writer";
3                     xBook.PrintOutEx(Missing.Value, Missing.Value, 1false, printerName, truetrue, TIFPathAndName, true);

 

PrintOutEx函数原型:

void PrintOutEx(object From, object To, object Copies, object Preview, object ActivePrinter, object PrintToFile, object Collate, object PrToFileName, object IgnorePrintAreas)

 

From : 打印起始页

To: 打印终止页

Copies : 打印份数

Preview: 是否预览,true,false

ActivePrinter : 默认打印机名

PrintToFile : 指定是否打印到文件, true ,false 

Collate : 是否自动分页,true,false 

 PrToFileName : 指定文件路径

IngorePrintAreas : 是否忽略打印区域,true,false 

 

 这里的前提是能够找到名为“Microsoft Office Document Image Writer”的打印机


参考:

http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.printoutex.aspx 

http://msdn.microsoft.com/en-us/library/bb238907(v=office.12).aspx 


posted on 2011-11-10 13:59  CQU  阅读(2991)  评论(1编辑  收藏  举报

导航