2

I have a graph (x y graph) with several curves on it in an excel file.
How can i access this graph in a c# application and extract values from the graph?

As an example, given curve 1 and an x value on an excel graph, i want to get the y value on the corresponding curve using a c# windows application. is this possible?

4

2 回答 2

0

你必须创建一个宏——与图形通信,然后创建你的 csharp 应用程序来与宏通信——你必须使用 excel 的互操作库 ..

于 2012-06-01T11:18:53.580 回答
0

您可以使用EPPlus并获取图表系列的 excel 范围,然后从范围中获取图表数据,如下所示:

private List<double> ExtractChartValues(FileInfo excelFile, string sheetName, int drawing, int chartSerie)
{
  ExcelPackage ePack = new ExcelPackage(excelFile);
  ExcelWorksheet ws = ePack.Workbook.Worksheets[sheetName];

  List<double> result = new List<double>();
  ExcelChart ec = (ExcelChart)ws.Drawings[drawing];
  ExcelRange dataRange = ws.Cells[ec.Series[chartSerie].Series];
  foreach (ExcelRangeBase data in dataRange)
  {
    if (data.Value != null)
      result.Add((double)data.Value);
  }
  return result;
}
于 2012-05-31T09:17:55.233 回答