Мне нужно было разработать нечто подобное в одном из моих проектов. Речь шла о переводе диаграмм из приложения на панель инструментов, на которой выполняются живые данные.
Мое решение закончилось подключением к базе данных приложения через 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"