C# 办公室互操作图表自动缩放

C# 办公室互操作图表自动缩放,c#,graph,charts,interop,autoscaling,C#,Graph,Charts,Interop,Autoscaling,要在我的word interop文档中生成一个图形,我使用以下方法: public static void AddSimpleChart(Document WordDoc, Microsoft.Office.Interop.Word.Application WordApp, string[,] data) { object oMissing = System.Reflection.Missing.Value; Microsoft.Office.I

要在我的word interop文档中生成一个图形,我使用以下方法:

    public static void AddSimpleChart(Document WordDoc, Microsoft.Office.Interop.Word.Application WordApp, string[,] data)
    {

        object oMissing = System.Reflection.Missing.Value;
        Microsoft.Office.Interop.Word.InlineShape oShape;
        object oClassType = "MSGraph.Chart.8";
        object oEndOfDoc4 = "\\endofdoc";
        Microsoft.Office.Interop.Word.Range wrdRng = WordDoc.Bookmarks.get_Item(ref oEndOfDoc4).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] = 1; //xlLine = 4   
        oChart.GetType().InvokeMember("ChartType", BindingFlags.SetProperty,
            null, oChart, Parameters);



        Microsoft.Office.Interop.Graph.Chart objChart = (Microsoft.Office.Interop.Graph.Chart)oShape.OLEFormat.Object;

        objChart.ChartType = Microsoft.Office.Interop.Graph.XlChartType.xlLineMarkers;

        DataSheet dataSheet;
        dataSheet = objChart.Application.DataSheet;
        int rownum = data.GetLength(0);
        int columnnum = data.GetLength(1);
        for (int i = 1; i <= rownum; i++)
            for (int j = 1; j <= columnnum; j++)
            {
                dataSheet.Cells[i, j] = data[i - 1, j - 1];

            }

        objChart.Application.Update();
        oChartApp.GetType().InvokeMember("Update",
            BindingFlags.InvokeMethod, null, oChartApp, null);
        oChartApp.GetType().InvokeMember("Quit",
            BindingFlags.InvokeMethod, null, oChartApp, null);


        oShape.Width = WordApp.InchesToPoints(6.25f);
        oShape.Height = WordApp.InchesToPoints(3.57f);
        wrdRng = WordDoc.Bookmarks.get_Item(ref oEndOfDoc4).Range;
        wrdRng.InsertParagraphAfter(); 

    } 
public static void AddSimpleChart(文档WordDoc,Microsoft.Office.Interop.Word.Application WordApp,字符串[,]数据)
{
对象omising=System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.InlineShape oShape;
object oClassType=“MSGraph.Chart.8”;
对象oEndOfDoc4=“\\endofdoc”;
Microsoft.Office.Interop.Word.Range wrdRng=WordDoc.Bookmarks.get_项(参考oEndOfDoc4.Range);
oShape=wrdRng.InlineShapes.AddOLEObject(ref-oClassType,ref-omising,
引用引用,引用引用引用,引用引用引用,
参考信息,参考信息,参考信息);
//演示如何使用后期绑定的oChart和oChartApp对象
//使用MSGraph操作图表对象。
客体艺术;
对象oChartApp;
oChart=oShape.OLEFormat.Object;
oChartApp=oChart.GetType().InvokeMember(“应用程序”,BindingFlags.GetProperty,null,oChart,null);
//将图表类型更改为线条。
object[]参数=新对象[1];
参数[0]=1;//xlLine=4
oChart.GetType().InvokeMember(“ChartType”,BindingFlags.SetProperty,
null、oChart、参数);
Microsoft.Office.Interop.Graph.Chart objChart=(Microsoft.Office.Interop.Graph.Chart)oShape.OLEFormat.Object;
objChart.ChartType=Microsoft.Office.Interop.Graph.XlChartType.xlLineMarkers;
数据表数据表;
数据表=objChart.Application.dataSheet;
int rownum=data.GetLength(0);
int columnnum=data.GetLength(1);

对于(int i=1;i异常的消息是什么?嗨,这里是异常消息:message=notimplemented(来自HRESULT:0x80004001(E_NOTIMPL))的异常)Source=”“StackTrace:at Microsoft.Office.Interop.Word.InlineShape.get_Chart()Thk!我认为自动缩放适用于3d图表。同样,“太小”是指形状的高度和宽度减小或内部图表元素减小?我是指内部图表元素减小。但当我打开word文档并双击图表时,当我离开图表区时,它得到了正确的大小…奇怪。。。