2011-02-23 3 views
1

워크 시트에서 최소값을 얻으 려하지만 셀을 배치 한 다음 그 값을 추출하면 전체 수식이 아닌 셀의 이중 값 .... 내가 뭘 잘못하고 있니? 아래 그래프 생성 방법입니다.값을 얻는 방법 및 수식이 아닙니다.

또 다른 것은, 내가 .delete을 (시도를 저장 한 후 나는 또한 그래프를 삭제하려면)하지만 그건 그냥 던져 버리고 오류가, 어떻게

private void GenerateGraph(Worksheet worksheet, int lastRow, int lastColumn, string filename) 
     { 
      string topLeft = ToCell(0, 0); 
      string bottomRight = ToCell(lastRow - 1, lastColumn - 1); 



     worksheet.get_Range(ToCell(0, 0), missing).Formula = "Max(B2:" + bottomRight + ")"; 
     worksheet.get_Range(ToCell(0, 0), missing).FormulaHidden = true; 
     worksheet.get_Range(ToCell(0, 0), missing).Calculate(); 
     Range range = (Range)worksheet.Cells[1,1]; 

     // 
     //here is where my problem is, small is being given the formula from above 
     // 

     string small = (string)range.Value2; 
     double min = Convert.ToDouble(small); 
     worksheet.get_Range(ToCell(0,0),missing).Formula = ""; 

     //Generates the graph 
     range = worksheet.get_Range(topLeft, bottomRight); 
     ChartObjects Xlchart = (ChartObjects)worksheet.ChartObjects(missing); 
     ChartObject chart = (ChartObject)Xlchart.Add(20, 160, 600, 500); 
     Excel.Chart myChart = chart.Chart; 
     myChart.SetSourceData(range, missing); 

     //sets the y axis 
     Axis axis = (Axis)myChart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary); 
     axis.MinimumScaleIsAuto = true; 
     axis.MaximumScaleIsAuto = true; 
     axis.HasTitle = true; 
     axis.AxisTitle.Text = "Measure (m)"; 
     axis.CrossesAt = (int)(min-1); 

     //sets the x axis 
     Axis xAxis = (Axis)myChart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary); 
     xAxis.HasTitle = true; 
     xAxis.AxisTitle.Text = "Position (m)"; 

     //makes the graph a line graph 
     myChart.ChartType = XlChartType.xlXYScatterLinesNoMarkers; 

     //titles the graph 
     myChart.HasTitle = true; 
     myChart.ChartTitle.Text = "Profiles"; 

     //saves the graph 
     myChart.Export(filename, "JPG", missing); 

     // 
     //here is where I would like to delete the graph 
     // 
    } 

답변

1

당신이 필요하고 가야합니까 :

Formula = "=Max(B2:" + bottomRight + ")" 

수식에 등호가 누락되었습니다.

+0

내가 그 문제의 첫 번째 부분을 해결했다면, 어떻게 실제 엑셀 파일에서 그래프를 삭제할 수 있습니까? –

+0

@Bob 그것은 두 가지 질문을 하나의 질문으로 만나는 문제입니다. 나는 첫 번째에 대한 대답을 알고 있지만 두 번째에 대한 대답은 안다. 이 질문을 편집하여 삭제 부분을 제거한 다음 그 내용을 포함하는 새로운 질문을하는 것이 좋습니다. –