473,388 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Excel Interops - Want multiple datasources on one chart

This c# program allows you to select multiple items from a listbox.
For each selected item, a worksheet is created in the workbook with
some information. Right now I create a chart that plots some
information from one of the sheets. What I want to do is have a line
on the graph for every sheet. I assume I use multiple datasources to
do this, but I don't know how to use the SeriesCollection class to
accomplish this.

Here's my code. Thanks in advance.
excel = new office.Application();
workbook = excel.Workbooks.Add(missing);
worksheet = (office.Worksheet)workbook.ActiveSheet;

office.ChartObjects charts =
(office.ChartObjects)worksheet.ChartObjects(missin g);
office.ChartObject chartObj = charts.Add(200,20,800,300);
chartObj.Chart.ChartType = office.XlChartType.xlLine;
chartObj.Chart.HasLegend = true;

int counter=0;
foreach(ListItem item in individualsList.Items)
{
if (item.Selected)
{
worksheet = (office.Worksheet)workbook.Worksheets.Add(missing,
missing, missing, missing);

System.Diagnostics.Trace.WriteLine("worksheet created");
string selectedItem = item.Text;
string selectedValue = item.Value;

// get the DataTable with the employees information
utilizationInfo = reportLogic.GetUtilizationTable(selectedValue);

// fill in the information
for (int p=0; p<utilizationInfo.Rows.Count; p++)
{
worksheet.get_Range("A" + (p+2), missing).Value2 =
utilizationInfo.Rows[p]["Date"].ToString();
double utilization = Double.Parse(utilizationInfo.Rows[p]
["Utilization"].ToString()) * 100;
worksheet.get_Range("B" + (p+2), missing).Value2 = (int)
(utilization + 0.5);
worksheet.get_Range("C" + (p+2), missing).Value2 =
utilizationInfo.Rows[p]["TotalBillableHours"].ToString();
worksheet.get_Range("D" + (p+2), missing).Value2 =
utilizationInfo.Rows[p]["AvailableHours"].ToString();
}
range = worksheet.get_Range("A1", "B1");
range.ColumnWidth = 12;

office.Range chartRange = worksheet.get_Range("B2", "B40");
chartObj.Chart.SetSourceData(chartRange, missing);
seriesCollection =
(office.SeriesCollection)chartObj.Chart.SeriesColl ection(missing);

counter++;
}
}

/
************************************************** ************************************************** **/
// configure chart
/
************************************************** ************************************************** **/
// set the x-axis to be the period end dates
axis = (office.Axis)chartObj.Chart.Axes(office.XlAxisType .xlCategory,
office.XlAxisGroup.xlPrimary);
axis.HasTitle = true;
axis.AxisTitle.Text = "Timesheet Period Date";
office.Range axisRange = worksheet.get_Range("A2", "A40");
axis.CategoryNames = axisRange;

series = seriesCollection.Item(seriesCollection.Count);

// show excel
excel.Visible = true;
workbook.Activate();

Mar 1 '07 #1
0 3619

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
0
by: mscir | last post by:
Date: Thu, 08 Jul 2004 17:02:27 -0700 Organization: Posted via Supernews, http://www.supernews.com Message-ID: <10ero4l3kp2qa65@corp.supernews.com> Reply-To: mscir@usa.com User-Agent: Mozilla/5.0...
0
by: ghanley | last post by:
I have searched the web all day for a lead on this. I have found how to control the Graph object mut not the embedded excel unbound object frame. I am trying to chart the data below on one...
1
by: Robin Tucker | last post by:
Heres and interesting problem: I have a VB.NET program that creates reports via. Word Automation. This all works fine. What I want to do as part of this report generation process is to embed a...
1
by: Jaime Lucci | last post by:
Hi everyone! I need to show an excel chart in my application. I can open an excel file and make the chart, but I want to show the chart inside my form insted of the excel GUI. I use the...
6
by: Thelma Lubkin | last post by:
I am trying to modify an Access form that allows a user to specify the information s/he needs from a census-type database. The form's code builds a SQL statement from the user's request, and...
3
by: toffee | last post by:
Hi all, I got a pre-formatted spreadsheet. would it be possible using js to copy the data from a table on the current webpage, open the spreadsheet and paste the content ? if so, anyone got any...
6
by: Kuldeep | last post by:
Framework: Visual Studio 2005 Technology: ASP.NET 2.0 Language: C#.NET 2.0 Hi All, How can we generate an Excel File through C#.NET without using Interops or XML ? Any leads on this would...
9
by: AGP | last post by:
I have a VB6 application that has an OLE container with an embedded Excel chart. Our office updated to Excel 2007 and now although the app works the charts looks like crap. Since the app is fairly...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.