D
D.S.Jenkins
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.xlWBATWorksheet);
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;
}
}
}
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.xlWBATWorksheet);
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;
}
}
}