gpt4 book ai didi

c# - 在C#中将excel文件转换为jpg

转载 作者:太空宇宙 更新时间:2023-11-03 15:41:49 24 4
gpt4 key购买 nike

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

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

enter image description here

我使用此代码将其转换为 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)?

enter image description here

我的页面中有此警告:

enter image description here

最佳答案

我终于使用了 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");

对我来说效果很好。

关于c# - 在C#中将excel文件转换为jpg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30011614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com