Spire.XLS支持将Excel工作表转换为常见的图片格式, 如JPEG, PNG, BMP, WMF, EMF 和TIFF等。当Excel工作表中含有Excel图表时,Spire.XLS也支持仅将excel图表保存为图片格式。下面将介绍如何使用Spire.XLS将 Excel 工作表 和Excel图表保存为图片格式。
Excel工作表转图片
C#
//初始化workbook实例
Workbook workbook = new Workbook();
//加载Excel文档
workbook.LoadFromFile("Sample.xlsx");
//获取第一个工作表
Worksheet sheet = workbook.Worksheets[0];
//将工作表保存为图片
sheet.SaveToImage("ExceltoImage.png", ImageFormat.Png);
VB.NET
Dim workbook As New Workbook()
workbook.LoadFromFile("Sample.xlsx")
Dim sheet As Worksheet = workbook.Worksheets(0)
sheet.SaveToImage("ExceltoImage.png", ImageFormat.Png)
Excel工作表中的图表转图片
C#
//初始化workbook实例
Workbook workbook = new Workbook();
//加载Excel文档
workbook.LoadFromFile("Sample.xlsx");
/获取第一个工作表
Worksheet sheet = workbook.Worksheets[0];
//将图表保存为图片
Image[] imgs = workbook.SaveChartAsImage(sheet);
for (int i = 0; i < imgs.Length; i++)
{
imgs[i].Save(string.Format("img-{0}.png", i), ImageFormat.Png);
}
VB.NET
Dim workbook As New Workbook()
workbook.LoadFromFile("Sample.xlsx")
Dim sheet As Worksheet = workbook.Worksheets(0)
Dim imgs As Image() = workbook.SaveChartAsImage(sheet)
For i As Integer = 0 To imgs.Length - 1
imgs(i).Save(String.Format("img-{0}.png", i), ImageFormat.Png)
Next
Excel工作表中的两个图表存为两张图片: