以编程方式设置Excel图表标题
如何用C#和Interop设置图表标题?
其实尝试:
Excel.Range chartRange; Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlsSheet.ChartObjects(Type.Missing); Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10, 80, 300, 250); Excel.Chart chartPage = myChart.Chart; chartRange = xlsSheet.Range[xlsSheet.Cells[1, 1], xlsSheet.Cells[ar.GetLength(0), ar.GetLength(1)]]; chartPage.SetSourceData(chartRange, Excel.XlRowCol.xlRows); chartPage.ChartType = Excel.XlChartType.xl3DColumn; chartPage.Location(Excel.XlChartLocation.xlLocationAsNewSheet, oOpt); chartPage.HasTitle = true; chartPage.ChartTitle.Text = "HeaderText";
甜美
“System.Runtime.InteropServices.COMException”
错误HRESULT E_FAIL已经从对COM组件的调用中返回
find自己的答案。
只需在chartPage填充信息之前设置标题即可。
而不是chartPage.HasTitle = true;
另一种方法是在设置标题之前应用包含标题字段的图表布局。 在xl3DColumn的情况下:
chartPage.ApplyLayout (1) chartPage.ChartTitle.Text = "HeaderText"