我们可以将Excel图表转换为图像并将其另存为图像文件吗?
答案 0 :(得分:0)
我必须在我的一个项目中找到类似的东西。它是关于将图表从应用程序转换为运行实时数据的仪表板。 我的解决方案最终通过ODBC连接到应用程序的数据库,并使用VBA逆向工程生成图表(报告)
一步一步:
1. do an automatic refresh of data by setting a refresh interval in the Excel Data Query
2. extract the information from the Excel worksheet with VBA
3. generate Pivot Tables and Pivot Charts upon the information extracted with VBA
4. convert the Pivot Charts or Range of Cells(=Tables) to Images and Paste them above the Chart Objects in the Excel Worksheets
5. cut area(s) from the Worksheets (that contained the chart or tables) by giving dimensions and save these as images
6. read the images saved at the previous stage via a webpage ( depending on its additional content either static-.html or dynamic
.aspx )
7. set a refreshment time in the webpage source, and there is the dashboard
正如您在上面所看到的,我没有将图表转换为图像,而是将图表中包含图表的工作表区域转换为图像。
这是可能对您有帮助的VBA代码:
Sub Pivot_Chart_And_Table_of_Auftragsart_To_Image()
'the code for selecting successively the areas of Pivot Table and Pivot Chart and save them as image file types .jpg to a defined directory path
'below you set the Range(=Area in the Worksheet) you want to export to file
Dim rgExp As Range
Set rgExp = Range("A1:E5")
''' Copy range as picture onto Clipboard
rgExp.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
''' Create an empty chart with exact size of range copied
With ActiveSheet.ChartObjects.Add(Left:=rgExp.Left, Top:=rgExp.Top, _
Width:=rgExp.Width, Height:=rgExp.Height)
.Name = "nameOfTheObjectHerewithGenerated"
.Border.LineStyle = xlNone 'this removes the border line of the temporary Chart Object
.Activate
End With
''' Paste into chart area, export to file
ActiveChart.Paste
ActiveSheet.ChartObjects("nameOfTheObjectHerewithGenerated").Chart.Export "C:\whateverDirectoryYouWish\nameOfImage.jpg"