If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Excel 2007 C# Charting problem
Hi
I'm having a problem with Excel 2007 and changing the colour of a series of data in a chart. If a create a windows form app with code as below I don't understand why myinterior.ColorIndex = 5 throws an exception nor why if I look at s in the watch window, why half it's entries are throwing exceptions. If I change excelApp.Visible = true it works fine - why would this be? Can anyone shed any light on this? Cheers Dave (email me at D . S . Jenkins at gmail . com) using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Excel = Microsoft.Office.Interop.Excel; using Microsoft.Office.Core; namespace WindowsApplication4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { Excel.Application excelApp = new Excel.Application(); excelApp.Visible = false; Excel.Workbook newWorkbook = excelApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATW orksheet); Excel.Worksheet xlSheet = (Excel.Worksheet)excelApp.Workbooks[1].Sheets[1]; Excel.Range c = (Excel.Range)xlSheet.Cells[1, 1]; Excel.Range d = (Excel.Range)xlSheet.Cells[2, 1]; c.Value2 = "A"; d.Value2 = 1; Excel.Range i; Excel.Range j; Excel.Range xlrange; i = (Excel.Range)xlSheet.Cells[1, 1]; j = (Excel.Range)xlSheet.Cells[2, 1]; xlrange = xlSheet.get_Range(i, j); Excel.Chart g1 = (Excel.Chart)newWorkbook.Sheets.Add(Type.Missing, Type.Missing, Type.Missing, Excel.XlSheetType.xlChart); g1.ChartType = Excel.XlChartType.xlColumnStacked; Excel.Series s = g1.SeriesCollection(1) as Excel.Series; Excel.Interior myinterior = s.Interior; myinterior.ColorIndex = 5; } } } |
#2
|
|||
|
|||
Excel 2007 C# Charting problem
This should be fixed in the final version of Excel 2007.
-Helen (Excel PM) wrote in message ups.com... Hi I'm having a problem with Excel 2007 and changing the colour of a series of data in a chart. If a create a windows form app with code as below I don't understand why myinterior.ColorIndex = 5 throws an exception nor why if I look at s in the watch window, why half it's entries are throwing exceptions. If I change excelApp.Visible = true it works fine - why would this be? Can anyone shed any light on this? Cheers Dave (email me at D . S . Jenkins at gmail . com) using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Excel = Microsoft.Office.Interop.Excel; using Microsoft.Office.Core; namespace WindowsApplication4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { Excel.Application excelApp = new Excel.Application(); excelApp.Visible = false; Excel.Workbook newWorkbook = excelApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATW orksheet); Excel.Worksheet xlSheet = (Excel.Worksheet)excelApp.Workbooks[1].Sheets[1]; Excel.Range c = (Excel.Range)xlSheet.Cells[1, 1]; Excel.Range d = (Excel.Range)xlSheet.Cells[2, 1]; c.Value2 = "A"; d.Value2 = 1; Excel.Range i; Excel.Range j; Excel.Range xlrange; i = (Excel.Range)xlSheet.Cells[1, 1]; j = (Excel.Range)xlSheet.Cells[2, 1]; xlrange = xlSheet.get_Range(i, j); Excel.Chart g1 = (Excel.Chart)newWorkbook.Sheets.Add(Type.Missing, Type.Missing, Type.Missing, Excel.XlSheetType.xlChart); g1.ChartType = Excel.XlChartType.xlColumnStacked; Excel.Series s = g1.SeriesCollection(1) as Excel.Series; Excel.Interior myinterior = s.Interior; myinterior.ColorIndex = 5; } } } |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Excel 2007 Beta Charting Problem/Question | kevjoh | Charts and Charting | 2 | June 22nd, 2006 07:18 PM |
Excel 2007 chart problem with existing spreadsheet | Mark | General Discussion | 3 | June 19th, 2006 12:51 PM |
2007 Excel Chart Problem | YokohamaGaijin | General Discussion | 0 | June 7th, 2006 02:56 AM |
TRYING TO SET UP EXCEL SPREADSHEET ON MY COMPUTER | MEGTOM | New Users | 5 | October 27th, 2005 03:06 AM |
Windows in Taskbar | Chevy | General Discussion | 8 | October 15th, 2004 03:57 PM |