Charu

Charu

  • 2k
  • 128
  • 6.1k

How to update Series.values in C#?

Oct 14 2016 5:01 AM
I have an issue with the excel , please let me help how can i solve it. Below is the code which is i'm using now , but its not working .
at last side code series.values should update excel file as recently updated , so how can i use it. i'm doing this to increase the chart range.
 
Excel.Application app = new Excel.Application();
// Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel._Worksheet sheet;
Excel.ChartObject chartObj;
Excel._Chart chart;
Excel.Series series;
object useDefault = Type.Missing;
Excel.Workbook book;
Excel.ChartObjects grph;
xlWorkBook = app.Workbooks.Open(@"E:\\test\\DTS-CODE");//Open the work book
sheet = xlWorkBook.Sheets["Trend_NCM"];//Select the sheet the chart is on
char oldformula , newformula;
long i, s;
Excel.Range orng = null;
string[] stmp, sbase;
string cha, rta;
string startingpoint, endpoint;
chart = sheet.ChartObjects("Chart 1").chart;
chart.SetSourceData(sheet.Range["A2:A7"], Excel.XlRowCol.xlRows);
for (s = 1; s < chart.SeriesCollection().count;s++)
{
string sting = "=SERIES(Trend_NCM!$A$3,Trend_NCM!$B$2:$AH$2,Trend_NCM!$B$3:$AH$3,1)";
//series.Values
rta = chart.SeriesCollection(s).Formula;
// foreach(sbase in chart.SeriesCollection().count)
//series = rta.Chart.SeriesCollection();
// series = chart.SeriesCollection(s).Formula;
series= null ;
cha = chart.SeriesCollection(s).Formula;
string[] cha1 = cha.Split(',');
string[] cha2 = cha1[2].Split(':');
startingpoint = cha2[0];
//endpoint = cha2[1];
Range xlrange = null;
Excel.Range last = sheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
Excel.Range range = sheet.get_Range("A1", last);
int iTotalColumns = sheet.UsedRange.Columns.Count;
// Excel.Range xlRange = sheet.UsedRange;
// xlrange = sheet.get_Range(xlrange.EntireRow.Address, useDefault);
// endpoint = iTotalColumns.ToString();
endpoint = "Trend_NCM!$AH$5";
**series.Values = startingpoint+ "&"+ ":" +"&"+ endpoint;**
}

Answers (2)