如何获得价值而不是公式
我试图从工作表中获得最小值,但是当我产生的最小值,并将其放置在一个单元格,然后提取该值我得到整个公式,而不是在单元格中的双倍值….我是什么做错了? 下面是我的生成图的方法。
另一件事,我也想删除图后,我已经试过.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 // }
你需要:
Formula = "=Max(B2:" + bottomRight + ")"
您错过了公式中的等号。
- 优化C#方法,比较和创build差异Excel文件
- 在Excel加载项安装程序中将VBA调用转换为C#
- 如何在Excel VSTO中获取单元格和对象(如图表,graphics和图片)的openxml?
- 通过OleDB读取Excel文件时,非空单元格中的DBNull
- 当源是QUERY TABLE(或ListObject)时EXCEL VBA VLOOKUP
- 在Excel中,使用OpenXML,你如何改变C#中checkbox的值?
- carlosAg Excel XML工作簿代码生成器和FlexCel APIMate有没有其他select?
- 使用Process.Start打开C#中的Excel文件
- 如何以编程方式保存OPEN Excel文档