【问题标题】:Convert excel file to jpg in c#在c#中将excel文件转换为jpg
【发布时间】:2015-07-12 17:53:59
【问题描述】:

我正在尝试使用 Spire dll 将 excel 文件转换为 jpg 。

所以我有一个这样的 xlsm 文件:

我使用此代码将其转换为 jpg :

    Workbook workbook = new Workbook();
    workbook.LoadFromFile(@"D:\a.xlsm");
    Worksheet sheet = workbook.Worksheets[1];
    sheet.SaveToImage("exceltoimage.jpg");
    System.Diagnostics.Process.Start("exceltoimage.jpg");

但是输出是这样的,有些单元格无法转换,为什么我的意思是(#name)?

我的页面中有这个警告:

【问题讨论】:

  • 产生#name错误的单元格的内容(公式)是什么?
  • @Stewart_R 第一行有这样的公式:=IF(I5>0,(F5/$N$2)*I5,0)
  • 该文件中是否有任何敏感内容,或者您​​能否将其发布(或精简版)某处?
  • @Stewart_R 我添加了一些细节,请你看一下
  • 您可以在某处发布该文件的副本(或另一个出现相同问题的文件)吗?

标签: c# excel converter spire


【解决方案1】:

我终于用 Aspose 了:

http://www.aspose.com/community/files/51/.net-components/aspose.cells-for-.net/category1129.aspx

示例:

http://www.aspose.com/docs/display/cellsnet/Converting+Worksheet+to+Image

我的示例代码:

 Workbook workbook = new Workbook(@"D:\a.xlsm");
            //Get the first worksheet.
            Worksheet sheet = workbook.Worksheets[12];

            //Define ImageOrPrintOptions
            ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
            //Specify the image format
            imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
            //Only one page for the whole sheet would be rendered
            imgOptions.OnePagePerSheet = true;

            //Render the sheet with respect to specified image/print options
            SheetRender sr = new SheetRender(sheet, imgOptions);
            //Render the image for the sheet
            Bitmap bitmap = sr.ToImage(0);

            //Save the image file specifying its image format.
            bitmap.Save(@"d:\SheetImage.jpg");

它对我很有用。

【讨论】:

  • 你能分享我 Aspose.dll 吗?请!
  • @AIVN just in first link in my post 下载第一个 Aspose.Cells for .NET 17.7(仅限 DLL)
猜你喜欢
  • 1970-01-01
  • 2020-06-25
  • 2012-06-14
  • 1970-01-01
  • 2014-10-31
  • 2019-06-05
  • 1970-01-01
  • 1970-01-01
  • 2023-04-08
相关资源
最近更新 更多