Purpose Embed diagrams from an excel worksheet 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
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. GuiXT Script:
Box
(14,0)
(30,60)
"Visualize profit per segment:" The InputScript then creates the diagram using the "callVB" statement. InutScript "create_diagram_profit_per_segment.txt":
callvb
tutorials.excel.saveexceldiagram
_ Class "guixtexcel" and method "saveExcelDiagram" in 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 Result:
|
Components |