You got it right Phishguy, you just missed the initialization of xlCells and xlSheet
Code: Select all
#define UNICODE
#include "disphelper/disphelper.bi"
Dim As Integer i
'int ExcelSample1(void)
'{
DISPATCH_OBJ(xlApp)
DISPATCH_OBJ(xlRange)
DISPATCH_OBJ(xlChart)
DISPATCH_OBJ(xlCells)
DISPATCH_OBJ(xlSheet)
Dim As String Headings(1 To 5) = { "Mammals", "Birds", "Reptiles", "Fishes", "Plants" }
dhInitialize(TRUE)
dhToggleExceptions(TRUE)
dhCreateObject("Excel.Application", NULL, @xlApp)
dhPutValue(xlApp, ".DisplayFullScreen = %b", TRUE)
dhPutValue(xlApp, ".Visible = %b", TRUE)
'/* xlApp.Workbooks.Add */
dhCallMethod(xlApp, ".Workbooks.Add")
'/* Set the worksheet name */
dhPutValue(xlApp, ".ActiveSheet.Name = %T", wstr("Critically Endangered"))
' /* Add the column headings */
For i=1 To 5
dhPutValue(xlApp, ".ActiveSheet.Cells(%d, %d) = %S", 1, i, wstr(headings(i)))
Next i
'/* Format the headings */
'WITH1(xlCells, xlApp, ".ActiveSheet.Range(%S)", "A1:E1")
' {
dhGetValue("%o",@xlSheet,xlApp,"ActiveSheet")
dhGetValue("%o",@xlCells,xlSheet,"Range(%s)","A1:E1")
dhPutValue(xlCells, ".Interior.Color = %d", RGB(&hee,&hdd,&h82))
dhPutValue(xlCells, ".Interior.Pattern = %d", 1) ' /* xlSolid */
dhPutValue(xlCells, ".Font.Size = %d", 13)
dhPutValue(xlCells, ".Borders.Color = %d", RGB(0,0,0))
dhPutValue(xlCells, ".Borders.LineStyle = %d", 1)' /* xlContinuous */
dhPutValue(xlCells, ".Borders.Weight = %d", 2) ' /* xlThin */
'}
' END_WITH(xlCells)
'WITH(xlSheet, xlApp, ".ActiveSheet")
'{
' /* Set some values */
dhPutValue(xlSheet, ".Range(%s).Value = %d", "A2", 184)
dhPutValue(xlSheet, ".Range(%s).Value = %d", "B2", 182)
dhPutValue(xlSheet, ".Range(%s).Value = %d", "C2", 57)
dhPutValue(xlSheet, ".Range(%s).Value = %d", "D2", 162)
dhPutValue(xlSheet, ".Range(%s).Value = %d", "E2", 1276)
'/* Output data source */
dhCallMethod(xlSheet, ".Range(%s).Merge", "A4:E4")
dhPutValue(xlSheet, ".Range(%s).Value = %s", "A4", "Source: IUCN Red List 2003 (http://www.redlist.org/info/tables/table2.html)")
' /* Apply a border around everything. Note '%m' means missing. */
dhCallMethod(xlSheet, ".Range(%s).BorderAround(%d, %d, %m, %d)", "A1:E2", 1, 2, RGB(0,0,0))
' /* Set column widths */
dhPutValue(xlSheet, ".Columns(%s).ColumnWidth = %e", "A:E", 12.5)
' }
' END_WITH(xlSheet)
'/* Set xlRange = xlApp.ActiveSheet.Range("A1:E2") */
dhGetValue("%o", @xlRange, xlApp, ".ActiveSheet.Range(%s)", "A1:E2")
'/* Set xlChart = xlApp.ActiveWorkbook.Charts.Add */
dhGetValue("%o", @xlChart, xlApp, ".ActiveWorkbook.Charts.Add")
'/* Set up the chart */
dhCallMethod(xlChart, ".ChartWizard(%o, %d, %d, %d, %d, %d, %b, %s)",xlRange, -4100, 7, 1, 1, 0, FALSE, "Critically Endangered Plants and Animals")
dhPutValue(xlChart, ".HasAxis(%d) = %b", 3, FALSE) ' /* xlSeries */
' /* Put the chart on our worksheet */
dhCallMethod(xlChart, ".Location(%d,%s)", 2, "Critically Endangered")
'cleanup:
dhToggleExceptions(FALSE)
dhPutValue(xlApp, ".ActiveWorkbook.Saved = %b", TRUE)
SAFE_RELEASE(xlRange)
SAFE_RELEASE(xlChart)
SAFE_RELEASE(xlApp)
dhUninitialize(TRUE)
' return 0;
'}