在Excel中,如何在隐藏的行和列中显示数据

时间:2018-09-18 17:39:04

标签: c# excel-interop

这是我试图使图表在隐藏的列中显示数据的方法:

Excel.Application oExcelApp = new Excel.Application;
Excel._Workbook oWB = oExcelApp.Workbooks.Add();
Excel._Worksheet oWS = oWB.ActiveSheet;

Excel.ChartObjects oCharts = (Excel.ChartObjects)oWS.ChartObjects();
Excel.ChartObject oChart = oCharts.Add(10, 80, 300, 250);
Excel.Chart chart = oChart.Chart;

// these three lines work
chart.HasTitle = true;
chart.ChartTitle.Text = "Chart Title";
chart.HasLegend = false;

// I get a compile error for this line
// because the HasHiddenContent property is read-only
chart.HasHiddenContent = true;

HasHiddenContent属性是我发现的唯一一个属性,它看起来可能是我要查找的属性,但是它是只读的。我可以使用哪个属性告诉图表在隐藏的列(和行)中显示数据?

1 个答案:

答案 0 :(得分:3)

完成“记录要执行的宏,然后将VBA转换为c#”后,我找到了问题的答案。

切换显示隐藏列和行中数据的正确属性是:

chart.PlotVisibleOnly = false;