簡體   English   中英

如何使用矢量 + Ms Graph 和 C# office interop 詞庫在詞自動化中繪制圖表(圖表)

[英]How to Draw diagrams (Charts) in word automation using vectors + Ms Graph with C# office interop word library

所以這里是微軟發布的代碼,我想知道在這個過程中從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);

完畢!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM