【问题标题】:Excel Chart export into PowerPoint exportExcel 图表导出到 PowerPoint 导出
【发布时间】:2010-12-03 14:56:21
【问题描述】:

我在尝试通过 使用 C# 的互操作 API。我需要让它为 Office2003 工作。

我遵循的过程是从模板创建 PowerPoint 使用互操作 API。然后我为每个图表插入一张新幻灯片,然后 这些幻灯片我添加了一个 Excel.Chart OLE 对象。到目前为止一切都很好。那我去 进入该工作簿,更改数据,并使用图表向导更新 图表在第一张纸上。最后我关闭了 excel 工作簿。

问题是图表在生成的 幻灯片。该图表已根据更改的数据进行了调整,但所有 对图表本身的操作,例如更改标题、数据范围、 图表类型等不显示。

它变得陌生。在 PowerPoint 中时,我单击(错误呈现) 生成图表并选择打开或编辑,图表将立即刷新到 正确的设置。当我关闭图表并返回到PowerPoint时, 图表已正确呈现。

我花了好几个小时来弄清楚发生了什么,但不知何故 似乎没有任何效果。我试过打电话:

  • PowerPoint.Application.ActivePresenation.UpdateLinks() 在所有图表之后 生成(是 OLE 问题吗?)。
  • Chart.Refresh();
  • Workbook.RefreshAll();

有人可以告诉我需要做什么吗?我会发布我的代码 插入下面的图表。

//Add the Workbook
Excel.Workbook workbook =
(Excel.Workbook)slide.Shapes.AddOLEObject(basePoint.X, basePoint.Y,
chartSize.Width, chartSize.Height,
MsoTriState.msoFalse).OLEFormat.Object;

//update the worksheet with data
Excel.Worksheet datasheet =
(Excel.Worksheet)workbook.Worksheets["Sheet1"];
datasheet.Cells.ClearContents();

//set table contents
//<<SNIP code that fills data sheet with contents from our custom
dataTable object>>

//fetch chart
Excel.Chart chart = (Excel.Chart)workbook.Charts["Chart1"];
Excel.Range range = datasheet.get_Range(datasheet.Cells[1, 1],
datasheet.Cells[dataTable.RowCount + 1, dataTable.ColumnCount + 1]);
chart.ChartWizard(range, Excel.XlChartType.xlBarStacked, Type.Missing,
Excel.XlRowCol.xlRows, 1, 1, true, dataTable.ChartTitle, "", "", "");

//release objects
datasheet = null;
chart = null;
range = null;
workbook.Close(false, Type.Missing, Type.Missing);
workbook = null;

【问题讨论】:

  • 你有没有得到这个工作?
  • 试试 www.pptxbuilder.com

标签: .net excel export powerpoint


【解决方案1】:

更新现有图表时,这似乎对我有用:

Chart.Application.Update();

我很想看看在插入新图表时这是否适合您。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多