尝试在 Excel 中绘制一个简单的 csv 文件:
1,2,3
4,5,6
7,8,9
如何以编程方式将图形范围确定为 A1:C3?
我努力了
var lastCell = worksheet.Cells.get_End(XlDirection.xlUp);
确定最后一列,但它似乎不起作用。
以下是我用来绘制文件的代码,我只需要确定范围。
using Microsoft.Office.InteropServices.Excel;
Application application = new Application();
Workbook workbook = application.Workbooks.Open(fileName);
var worksheet = workbook.Worksheets[1] as
Microsoft.Office.Interop.Excel.Worksheet;
// Add chart.
var charts = worksheet.ChartObjects() as
Microsoft.Office.Interop.Excel.ChartObjects;
var chartObject = charts.Add(60, 10, 300, 300) as
Microsoft.Office.Interop.Excel.ChartObject;
var chart = chartObject.Chart;
// Set chart range.
var range = worksheet.get_Range( ); // ????????
chart.SetSourceData(range);
// Set chart properties.
chart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlLine;
chart.ChartWizard(Source: range,
Title: graphTitle,
CategoryTitle: xAxis,
ValueTitle: yAxis);
// Save.
workbook.Save();
workbook.Close();