c# - 如何使用向量 + Ms Graph 与 C# office interop 词库在文字自动化中绘制图表(图表)
问题描述
所以这里是微软发布的代码,我想知道在这个过程中从svg文件中获取向量到 word时如何插入图表?
//Insert a chart.
Word.InlineShape oShape;
object oClassType = "MSGraph.Chart.8";
wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oShape = wrdRng.InlineShapes.AddOLEObject(ref oClassType, ref oMissing,
ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing);
//Demonstrate use of late bound oChart and oChartApp objects to
//manipulate the chart object with MSGraph.
object oChart;
object oChartApp;
oChart = oShape.OLEFormat.Object;
oChartApp = oChart.GetType().InvokeMember("Application",
BindingFlags.GetProperty, null, oChart, null);
//Change the chart type to Line.
object[] Parameters = new Object[1];
Parameters[0] = 4; //xlLine = 4
oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty,
null, oChart, Parameters);
//Update the chart image and quit MSGraph.
oChartApp.GetType().InvokeMember("Update",
BindingFlags.InvokeMethod, null, oChartApp, null);
oChartApp.GetType().InvokeMember("Quit",
BindingFlags.InvokeMethod, null, oChartApp, null);
//... If desired, you can proceed from here using the Microsoft Graph
//Object model on the oChart and oChartApp objects to make additional
//changes to the chart.
//Set the width of the chart.
oShape.Width = oWord.InchesToPoints(6.25f);
oShape.Height = oWord.InchesToPoints(3.57f);
那么如何使用 office interop word 插入图表(带向量)?一些帮助亲爱的开发人员,谢谢;)
解决方案
好吧,只要有一个现有的 .svg 文件,就不需要使用 MsGraph,你可以像图片一样接近它并将其添加到文档中,如下所示:
//define a range with the assigned value of end of doc
Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
//add image path
string img = "C:\\Users\\a_shi\\Desktop\\svgsample.svg";
// add a picture by passing the image path, using AddPicture method of InlineShapes interface
wrdRng.InlineShapes.AddPicture(imgpath);
完毕!
推荐阅读
- pyspark - 如何从pyspark中具有json类型字符串的列中提取数据?
- java - 我在运行 c# 和 c++ 程序时遇到问题
- mysql - 如何从 mysql DB 中搜索与 mojolicious perl 中选定的下拉列表相关的内容
- javascript - React-Redux:在“Connect(UploadInternal)”的上下文中找不到“store”
- python - Python - 如何将前 3 行文本块转换为字典值?
- php - PHP 自定义命令解析器
- php - 无法安装 Symfony Datafixture 并显示与最低稳定性的冲突
- javascript - 如何在谷歌应用脚本中使用节点 js(缓冲区)
- python - django - 使用 mock 测试 django-admin 命令
- lua - 没有找到 'bit' 的 LuaRocks 模块