Aspose.Cells for .NET(点击下载)是Excel电子表格编程API,可加快电子表格管理和处理任务,支持构建具备生成,修改,转换,呈现和打印电子表格功能的跨平台应用程序。编程
PDF文件普遍用于在组织,政府部门和我的之间交换文档。它是一种标准文档格式,软件开发人员常常被要求找到将Microsoft Excel文件转换为PDF文档的方法。Aspose.Cells支持将Excel文件转换为PDF并在转换中保持高视觉保真度。安全
Aspose.Cells for .NET支持独立于其余软件从电子表格转换为PDF。只需使用Workbook类' Save方法将Excel文件保存为PDF 。该Save方法提供SaveFormat.Pdf枚举成员,将原生Excel文件转换为PDF格式。函数
文件格式应为PDF,所以Pdf从SaveFormat枚举中选择(预约义值)以生成最终的PDF文档。测试
//文档目录的路径 string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //实例化Workbook对象 //打开Excel文件 Workbook workbook = new Workbook(dataDir + "Book1.xls"); //以PDF格式保存文档 workbook.Save(dataDir + "output.pdf", SaveFormat.Pdf);
使用PdfSaveOptions该类为转换设置不一样的属性。经过设置PdfSaveOptions类的不一样属性,您能够控制输出PDF的打印、字体、安全性和压缩设置。最重要的属性是Compliance,能够将Excel文件保存为PDF / A兼容的PDF文件。字体
将工做簿保存为PDF / A编译文件spa
//文档目录的路径 string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //实例化新工做簿 Workbook workbook = new Workbook(); //将值插入第一个工做表中的A1单元格 workbook.Worksheets[0].Cells[0, 0].PutValue("Testing PDF/A"); //定义PdfSaveOptions PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); //设置合规性类型 pdfSaveOptions.Compliance = PdfCompliance.PdfA1b; //保存文件 workbook.Save(dataDir + "output.pdf", pdfSaveOptions);
设置PDF建立时间excel
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); string inputPath = dataDir + "Book1.xlsx"; //加载包含图表的excel文件 Workbook workbook = new Workbook(inputPath); //建立PdfSaveOptions的实例并将SaveFormat传递给构造函数 PdfSaveOptions options = new PdfSaveOptions(SaveFormat.Pdf); options.CreatedTime = DateTime.Now; //在传递PdfSaveOptions对象时将工做簿保存为PDF格式 workbook.Save(dataDir + "output.pdf", options);
将自定义属性导出为PDForm
使用PdfSaveOptions 该类,能够将源工做簿中的自定义属性导出到PDF。PdfCustomPropertiesExport枚举器用于指定导出属性的方式。经过单击“文件”,而后单击“属性”选项,能够在Adobe Acrobat Reader中观察这些属性,以下图所示。模板文件“sourceWithCustProps.xlsx”能够在这里下载 用于测试和输出Pdf文件“outSourceWithCustProps”可在此处进行分析。对象
//加载包含自定义属性的excel文件 Workbook workbook = new Workbook("sourceWithCustProps.xlsx"); //建立PdfSaveOptions的实例并将SaveFormat传递给构造函数 Aspose.Cells.PdfSaveOptions pdfSaveOptions = new Aspose.Cells.PdfSaveOptions(Aspose.Cells.SaveFormat.Pdf); // 将CustomPropertiesExport属性设置为PdfCustomPropertiesExport.Standard pdfSaveOptions.CustomPropertiesExport = Aspose.Cells.Rendering.PdfCustomPropertiesExport.Standard; //在传递PdfSaveOptions对象时将工做簿保存为PDF格式 workbook.Save("outSourceWithCustProps.pdf", pdfSaveOptions);