Excel Automation

ta5
Member Posts: 1,164
Hi
I have 2 problems with the ffw Code.
1): How the graph is inserted in Sheet "Table Sheet", not in sheet "Graph Sheet". The Location-Method seems not to work this way...
I also tried to insert more sheets, the graph is always placed on the last inserted sheet.
2): Its not possible to use the .hasTitle-property (see deactivated code; if activated a runtime-error occurs).
Any tips?
Thank you in advance.
H
CREATE(xlApp,FALSE);
xlBook := xlApp.Workbooks.Add(-4167);
xlSheet2:= xlApp.ActiveSheet;
xlSheet2.Name := 'Graph Sheet';
xlSheet1 := xlBook.Sheets.Add;
xlSheet1.Name := 'Table Sheet';
xlSheet1.Range('A3').Value := 'Item 1';
xlSheet1.Range('A4').Value := 'Item 2';
xlSheet1.Range('A5').Value := 'Item 3';
xlSheet1.Range('A6').Value := 'Item 4';
xlSheet1.Range('B2').Value := 'Budget 2004';
xlSheet1.Range('B3').Value := 150;
xlSheet1.Range('B4').Value := 140;
xlSheet1.Range('B5').Value := 100;
xlSheet1.Range('B6').Value := 200;
xlSheet1.Range('C2').Value := 'Budget 2003';
xlSheet1.Range('C3').Value := 20;
xlSheet1.Range('C4').Value := 200;
xlSheet1.Range('C5').Value := 30;
xlSheet1.Range('C6').Value := 90;
xlSheet1.Range('D2').Value := 'Budget 2002';
xlSheet1.Range('D3').Value := 300;
xlSheet1.Range('D4').Value := 400;
xlSheet1.Range('D5').Value := 500;
xlSheet1.Range('D6').Value := 100;
xlRange := xlSheet1.Range('A2:D6');
xlChart := xlBook.Charts.Add;
xlChart.ChartType := 51; //Column
xlChart.SetSourceData(xlRange,2);
xlChart.Location(2,'Graph Sheet');
//xlChart.HasTitle(TRUE);
xlApp.Visible := TRUE;
I have 2 problems with the ffw Code.
1): How the graph is inserted in Sheet "Table Sheet", not in sheet "Graph Sheet". The Location-Method seems not to work this way...
I also tried to insert more sheets, the graph is always placed on the last inserted sheet.
2): Its not possible to use the .hasTitle-property (see deactivated code; if activated a runtime-error occurs).
Any tips?
Thank you in advance.
H
CREATE(xlApp,FALSE);
xlBook := xlApp.Workbooks.Add(-4167);
xlSheet2:= xlApp.ActiveSheet;
xlSheet2.Name := 'Graph Sheet';
xlSheet1 := xlBook.Sheets.Add;
xlSheet1.Name := 'Table Sheet';
xlSheet1.Range('A3').Value := 'Item 1';
xlSheet1.Range('A4').Value := 'Item 2';
xlSheet1.Range('A5').Value := 'Item 3';
xlSheet1.Range('A6').Value := 'Item 4';
xlSheet1.Range('B2').Value := 'Budget 2004';
xlSheet1.Range('B3').Value := 150;
xlSheet1.Range('B4').Value := 140;
xlSheet1.Range('B5').Value := 100;
xlSheet1.Range('B6').Value := 200;
xlSheet1.Range('C2').Value := 'Budget 2003';
xlSheet1.Range('C3').Value := 20;
xlSheet1.Range('C4').Value := 200;
xlSheet1.Range('C5').Value := 30;
xlSheet1.Range('C6').Value := 90;
xlSheet1.Range('D2').Value := 'Budget 2002';
xlSheet1.Range('D3').Value := 300;
xlSheet1.Range('D4').Value := 400;
xlSheet1.Range('D5').Value := 500;
xlSheet1.Range('D6').Value := 100;
xlRange := xlSheet1.Range('A2:D6');
xlChart := xlBook.Charts.Add;
xlChart.ChartType := 51; //Column
xlChart.SetSourceData(xlRange,2);
xlChart.Location(2,'Graph Sheet');
//xlChart.HasTitle(TRUE);
xlApp.Visible := TRUE;
0
Comments
-
Have you tried a xlsheet1.activate; after inserting this new sheet?
Greetings,
Frank0 -
Hi Frank
Thanks for your answer. xlsheet1.activate did not work, but I've found a workaround for both now:
1) Add the Data Sheet, then create the graph on a separate sheet, add a temporary sheet, move sheet to position 1, delete temporary sheet.
2) This works
xlBook.ActiveChart.HasTitle := TRUE;
Regards
H0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions