Excel管理控件Aspose.Cells功能教程——使用C#将Excel文件转换为图像

在各种情况下,当需要将电子表格内容嵌入到Web或桌面应用程序中时,可能希望将Excel电子表格转换为高分辨率图像。在本文中,将学习如何从.NET应用程序中使用C#将Excel文件转换为图像格式。

在各种情况下,当需要将电子表格内容嵌入到Web或桌面应用程序中时,可能希望将Excel电子表格转换为高分辨率图像。

在本文中,将学习如何从.NET应用程序中使用C#将Excel文件转换为图像格式。

  • Excel到图像C#的转换

整合所有格式的Aspose.Total永久授权正在火热促销中,联系客服立马1分钟了解全部咨询!


Excel到图像C#的转换

.NET的Aspose.Cells允许将Excel文件转换成各种流行的图像格式。该列表包括:EMF、WMF、JPEG、PNG、BMP、GIF、TIFF、SVG、GLTF、PICT、SVM、Office Compatible EMF。

以下是将Excel文件转换为图像格式的步骤。

  1. 使用Workbook类加载Excel文件。
  2. 创建ImageOrPrintOptions类的实例。
  3. 使用ImageOrPrintOptions.ImageType属性设置图像类型。
  4. 使用ImageType枚举选择输出图像的格式,例如JPEG,PNG等。
  5. 选择要在工作表对象中呈现的工作表。
  6. 创建一个SheetRender对象,并将Worksheet和ImageOrPrintOptions对象传递给其构造函数。
  7. 使用SheetRender.PageCount属性循环浏览页面,以使用SheetRender.ToImage(Int32,String)方法将每个页面另存为图像。

下面的代码示例演示如何使用C#将Excel文件转换为图像格式。

//Source directorystring sourceDir = RunExamples.Get_SourceDirectory();//Output directorystring outputDir = RunExamples.Get_OutputDirectory();Workbook book = new Workbook(sourceDir + "sampleConvertWorksheetToImageByPage.xlsx");Worksheet sheet = book.Worksheets[0];Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();options.HorizontalResolution = 200;options.VerticalResolution = 200;options.ImageType = Drawing.ImageType.Tiff;// Sheet2Image By Page conversionSheetRender sr = new SheetRender(sheet, options);for (int j = 0; j < sr.PageCount; j++) { sr.ToImage(j, outputDir + "outputConvertWorksheetToImageByPage_" + (j + 1) + ".tif"); }


还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年1月3日
下一篇 2021年1月3日

相关推荐

发表回复

登录后才能评论