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
//
}
那我,那解決我的問題的前半部分,現在我該怎樣從實際Excel中刪除圖形文件? – 2011-02-23 14:54:59
@Bob這是有問兩個問題一個問題。我知道第一個答案,但不是第二個答案。你會更好編輯這個問題上的刪除部分,然後要求只包含一個新的問題! – 2011-02-23 15:02:49