Delphi Controlling Excel - Creating Pivot Tables and Charts -


delphi 10 / seattle, excel 2013. writing plugin (using addin express) excel. 1 of things need create series of excel pivot tables/pivot charts. have recorded macros within excel, have vba code want. challenge porting delphi.

my code compiles, , when step through it, last line gives me error .. method 'setsourcedata' not supported automation object. fyi - xlapp variable point excel application.

procedure  tmytemplateform.pivot_touchesbyquarter; var mypivotcache: olevariant; myactive_wb : olevariant; mychart : olevariant; chartsourcerange : olevariant; tabdestination : string; begin   // add new sheet   xlapp.connect;   myactive_wb := xlapp.activeworkbook;   xlapp.worksheets.add(emptyparam, emptyparam,1, xlworksheet, locale_user_default );    // handle new sheet , set sheet name   sheet_graph1 := xlapp.activesheet;   sheet_graph1.name := 'graph1'; // cannot contain spaces.. ?????    // parameters: sourcetype, sourcedata, version   // doc at:  https://msdn.microsoft.com/en-us/library/office/ff839430.aspx   mypivotcache := myactive_wb.pivotcaches.create(xldatabase,'raw data!r1c1:r1048576c36',xlpivottableversion15);    // parameters: tabledestination, tablename, defaultversion   tabdestination := 'graph1!r3c1';   mypivotcache.createpivottable(tabdestination, 'pivottable1',xlpivottableversion15);    // select want placed...   sheet_graph1.cells.item[3, 1].select;    // https://msdn.microsoft.com/en-us/library/office/jj228277.aspx   // create chart object   mychart := sheet_graph1.shapes.addchart2(201, xlcolumnclustered);    // define range source chart.  pivot table created above   chartsourcerange := sheet_graph1.range['graph1!$a$3:$c$20'];   // tell pivot chart use chart range   mychart.setsourcedata(chartsourcerange);   end; 

why getting error? related question, can point chart source pivottable1 object? right now, hard coded specific cell locations, depending on data, pivot table can bigger row3 row20.

if helps any, vba macro code (last 2 lines) is..

 activesheet.shapes.addchart2(201, xlcolumnclustered).select  activechart.setsourcedata source:=range("sheet1!$a$3:$c$20") 

i found answer. instead of

  // tell pivot chart use chart range   mychart.setsourcedata(chartsourcerange) 

the code should be

 mychart.chart.setsourcedata(chartsourcerange); 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -