C# to generate automatically updating Excel charts -


i have windows form data grid view can input data. c# code reads these data data grid view, processes , needs plot results. in particular, results stored in list. there additional data (which intermediate results of calculations) stored in 2 dimensional arrays. point i'm stuck plotting. want in excel , want make update dynamically whenever change input in data grid view. code below open excel workbook , pastes data of list in column a.

  1. how can add 2 dimensional array in column b , c?
  2. how can plot these columns in line chart?
  3. how can make excel chart update automatically update value in data grid view (without opening every time new excel workbook)?

thank help.

            using system;             using system.collections.generic;             using system.linq;             using system.text;             using system.threading.tasks;             using system.io;             using excel = microsoft.office.interop.excel;              namespace newpoject             {                 class plotter                 {                        public void plotgraphexcel_2d(list<double> x, double[,] y, double[,] yup, double[,] ydown)                     {                         excel.application xlapp;                         excel.workbook workbook;                         excel.worksheet sheet;                         object misvalue = system.reflection.missing.value;                          xlapp = new excel.application();                         xlapp.visible = true;                         workbook = xlapp.workbooks.add(misvalue);                         sheet = (excel.worksheet)workbook.worksheets.get_item(1);                           var range = sheet.get_range("a1", "a1");                         range.value2 = "scores";                          //now list                         string cellname;                         int counter = 2;                         foreach (var item in x)                         {                             cellname = "a" + counter.tostring();                             var range2 = sheet.get_range(cellname, cellname);                             range2.value2 = item.tostring();                             ++counter;                         }                          // how can save results of array y in column b , c?                         // how can plot line chart values have pasted in column a, b , c?                         // how can make update automatically when change value in data grid view?                     }                 }             } 


Comments