我有一个包含一系列图表的 Word 文档 (.docx)。我的代码成功更新了饼图后面的值,Word 会适当地显示结果(刷新图表的前端,无论您想如何称呼它)。
遗憾的是,对于集群条形图,情况并非如此。工作簿中的值会更新,但前端不会刷新以显示新值。
一旦我右键单击图表并选择编辑数据(我什至不需要编辑任何内容,只需在工作簿窗口打开时关闭它)然后刷新图表上显示的值。
有没有什么办法可以强制刷新前端而不经过它?关闭文件并重新打开没有效果。
我有的:
wordcon.Application wordapp = new wordcon.Application();
wordcon.Document docx = new wordcon.Document();
wordapp.ActiveDocument.InlineShapes[2].Chart.ChartData.Activate();
excelcon.Workbook excelwb = wordapp.ActiveDocument.InlineShapes[2].Chart.ChartData.Workbook;
excelcon.Worksheet excelws = excelwb.Worksheets[1];
excelws.Cells[1, 2] = reference.top_issues_1_name;
excelws.Cells[6, 1] = "a";
excelws.Cells[6, 2] = reference.top_issues_1;
excelws.Cells[5, 1] = "b";
excelws.Cells[5, 2] = reference.top_issues_2;
excelws.Cells[4, 1] = "c";
excelws.Cells[4, 2] = reference.top_issues_3;
excelws.Cells[3, 1] = "d";
excelws.Cells[3, 2] = reference.top_issues_4;
excelws.Cells[2, 1] = "e";
excelws.Cells[2, 2] = reference.top_issues_5;
excelwb.Close();
Marshal.ReleaseComObject(excelws);
Marshal.ReleaseComObject(excelwb);
docx.SaveAs2(reference.chart_file_forked_path + reference.chart_file_forked_file_name);
wordapp.Quit();
Marshal.ReleaseComObject(docx);
Marshal.ReleaseComObject(wordapp);