For our example, we use an Excel file that contains a number of data on
product sales in different market segments. We want to display on the
SAP screen the profit per segment in the yearly comparison.
Solution
- Use "callVB" in a GuiXT script to export the excel diagram to an image file
- Embed the diagram with the "image" keyword
Excel file "financial_sample.xlsx":
To do this, we first need a GuiXT script with the file and diagram names
as well as the name of the image file to be generated.
Class "guixtexcel" and method "saveExcelDiagram" in VB.NET:
VB.NET
Imports guinet
Imports Microsoft.Office.Interop.Excel
Imports System.IO
Public Class guixtexcel
Public Sub SaveExcelDiagram(inputFile As String, _
diagamName As String, _
outputFile As String)
Dim oXL As New Application
Dim g As New guixt
If Not File.Exists((inputFile)) Then
MsgBox("File not found: " & inputFile)
Return
End If
Try
Dim oWB As Workbook
Dim oSheet As Worksheet
oXL = CreateObject("Excel.Application")
oXL.Visible = False
oWB = oXL.Workbooks.Open(inputFile)
oSheet = oWB.Sheets(1)
oSheet.ChartObjects(diagamName).Chart.Export(outputFile)
Catch ex As Exception
MsgBox(ex.Message)
oXL.ActiveWorkbook.Close(False)
oXL.Quit()
End Try
oXL.ActiveWorkbook.Close(False)
oXL.Quit()
End Sub
End Class