Excel 2007 C# Charting problem

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;

}
}
}
 
H

Helen Hosein \(MS\)

This should be fixed in the final version of Excel 2007.

-Helen (Excel PM)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top