/* This sample extracts data from an OpenEdge database and graphs the
information using the Automation Objects from the Excel server in Microsoft Office. You must connect to a sports2000 database before running this. This sample program leaves Excel open. You should close it manually when the program completes. */ DEFINE VARIABLE chExcelApplication AS COM-HANDLE NO-UNDO. DEFINE VARIABLE chWorkbook AS COM-HANDLE NO-UNDO. DEFINE VARIABLE chWorksheet AS COM-HANDLE NO-UNDO. DEFINE VARIABLE chChart AS COM-HANDLE NO-UNDO. DEFINE VARIABLE chWorksheetRange AS COM-HANDLE NO-UNDO. DEFINE VARIABLE iCount AS INTEGER NO-UNDO. DEFINE VARIABLE iIndex AS INTEGER NO-UNDO. DEFINE VARIABLE iTotalNumberOfOrders AS INTEGER NO-UNDO. DEFINE VARIABLE iMonth AS INTEGER NO-UNDO. DEFINE VARIABLE dAnnualQuota AS DECIMAL NO-UNDO. DEFINE VARIABLE dTotalSalesAmount AS DECIMAL NO-UNDO. DEFINE VARIABLE iColumn AS INTEGER NO-UNDO INITIAL 1. DEFINE VARIABLE cColumn AS CHARACTER NO-UNDO. DEFINE VARIABLE cRange AS CHARACTER NO-UNDO. /* create a new Excel Application object */ CREATE "Excel.Application" chExcelApplication. /* launch Excel so it is visible to the user */ chExcelApplication:Visible = TRUE. /* create a new Workbook */ chWorkbook = chExcelApplication:Workbooks:Add(). /* get the active Worksheet */ chWorkSheet = chExcelApplication:Sheets:Item(1). /* set the column names for the Worksheet */ chWorkSheet:Columns("A"):ColumnWidth = 18. chWorkSheet:Columns("B"):ColumnWidth = 12. chWorkSheet:Columns("C"):ColumnWidth = 12. chWorkSheet:Range("A1:C1"):Font:Bold = TRUE. chWorkSheet:Range("A1"):Value = "SalesRep". chWorkSheet:Range("B1"):Value = "Total Sales". chWorkSheet:Range("C1"):Value = "Annual Quota". /* Iterate through the SalesRep table, populate the Worksheet appropriately */ FOR EACH SalesRep NO-LOCK: ASSIGN dAnnualQuota = 0 iTotalNumberOfOrders = 0 dTotalSalesAmount = 0 iColumn = iColumn + 1. FOR EACH Order OF SalesRep NO-LOCK: iTotalNumberOfOrders = iTotalNumberOfOrders + 1. FIND Invoice WHERE Invoice.OrderNum = Order.OrderNum NO-ERROR. IF AVAILABLE Invoice THEN dTotalSalesAmount = dTotalSalesAmount + Invoice.Amount. END. DO iMonth = 1 TO 12: dAnnualQuota = dAnnualQuota + Salesep.MonthQuota[iMonth]. END. ASSIGN cColumn = STRING(iColumn) cRange = "A" + cColumn chWorkSheet:Range(cRange):Value = SalesRep.RepName cRange = "B" + cColumn chWorkSheet:Range(cRange):Value = dTotalSalesAmount cRange = "C" + cColumn chWorkSheet:Range(cRange):Value = dAnnualQuota. END. chWorkSheet:Range("B2:C10"):Select(). chExcelApplication:Selection:Style = "Currency". /* create embedded chart using the data in the Worksheet */ chWorksheetRange = chWorksheet:Range("A1:C10"). chWorksheet:ChartObjects:Add(10,150,425,300):Activate. chExcelApplication:ActiveChart:ChartWizard(chWorksheetRange, 3, 1, 2, 1, 1, TRUE, "1996 Sales Figures", "Sales Person", "Annual Sales"). /* create chart using the data in the Worksheet */ chChart=chExcelApplication:Charts:Add(). chChart:Name = "Test Chart". chChart:Type = 11. /* release com-handles */ RELEASE OBJECT chExcelApplication. RELEASE OBJECT chWorkbook. RELEASE OBJECT chWorksheet. RELEASE OBJECT chChart. RELEASE OBJECT chWorksheetRange. |