[英]Convert Excel Chart to Image in VB.Net
I have a question about converting a chart in a excel sheet. 我有一个关于在Excel工作表中转换图表的问题。 I try the library NPOI which is very powerful about importing data etc. But I haven't seen a method like chart.toImage or something.
我尝试了NPOI库,它在导入数据等方面非常强大。但是我还没有看到诸如chart.toImage之类的方法。
Dim hssfworkbook As HSSFWorkbook = InitializeWorkbook(lblExcelPath.Text)
Dim sheet As HSSFSheet = hssfworkbook.GetSheet(txtTableName.Text)
Dim chart As HSSFChart() = HSSFChart.GetSheetCharts(sheet)
As you see I got the chart from the sheet but I can't export it. 如您所见,我从工作表中获取了图表,但无法导出。 My Problem is also that the library should not use the excel application.
我的问题还在于该库不应使用excel应用程序。 I mean the installed office excel.
我的意思是已安装Office excel。 The problem is that the diffrent version of excel could may a problem.
问题是excel的不同版本可能会出现问题。 Because of that
Microsoft.Office.Interop
library is not a solution. 因此,
Microsoft.Office.Interop
库不是解决方案。 I found the aspose library which cost a bit. 我发现了一个aspose库,它花了一点钱。 So first of all I try to search a free cost library for this little problem.
因此,我首先尝试为这个小问题搜索免费的成本库。
Update: 更新:
A possible solution could be convert the excel sheet in html and extract the image of the chart as a image. 可能的解决方案是将excel工作表转换为html,然后将图表的图像提取为图像。 When i open the excel file and save it as html it works.
当我打开excel文件并将其另存为html时,它可以工作。 Does anyone test a library which convert Excel to HTML and have success with converting the chart in it?
是否有人测试将Excel转换为HTML并成功转换图表的库?
I hope everyone understands me, my english is bad ): 我希望每个人都能理解我,我的英语不好():
Thank you in advance 先感谢您
Check out the Chart.Export method in Excel's object model. 在Excel的对象模型中签出Chart.Export方法。 It's present and works the same in Excel 97 through Excel 2013. Syntax is like:
它存在并且在Excel 97到Excel 2013中都相同。语法类似于:
Chart.Export Filename, Filter Chart.Export文件名,过滤器
or 要么
ActiveChart.Export "C:\\users\\Fred\\Documents\\Charts\\MyExcelChart.png", "PNG" ActiveChart.Export“ C:\\ users \\ Fred \\ Documents \\ Charts \\ MyExcelChart.png”,“ PNG”
Use "PNG" for charts, not "JPG". 对于图表,请使用“ PNG”,而不是“ JPG”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.