C# COMException异常排除

C#引用Microsoft.Office.Interop.Excel.dll版本是15.0.0.0,我想用求逆矩阵,3阶和3阶以下都是正常的,和excel表格里求出来一样,官方说这个最大支持52阶矩阵,但是大于3阶就老出现这个异常,:

请输入图片描述

代码如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace Matrix

{

class Program

{

static void Main(string[] args)

{

// Object[,] a = new Object[3, 3] {{1,2,3},{4,5,6},{7,8,9} };

// Object[,] a = new Object[2, 2] { { 1, 2 }, { 4, 5 } };

Object[,] a = new Object[4, 4] { { 1, 2, 3, 4 }, { 4, 5, 6, 7 }, { 7, 8, 9, 10 }, { 1, 1, 1, 1 } };

getMInverse(a);

Console.ReadLine();

}

public static Object[,] getMInverse(Object[,] o)

{

Object[,] result = null;

try

{

Microsoft.Office.Interop.Excel.ApplicationClass excel = new Microsoft.Office.Interop.Excel.ApplicationClass();

result = (System.Object[,])excel.WorksheetFunction.MInverse(o);

Console.WriteLine("逆矩阵为:");

for (int i = 1; i < result.GetLength(0) + 1; i++)

{

for (int j = 1; j < result.GetLength(1) + 1; j++)

{

Console.Write(result[i, j] + "\t");

}

Console.WriteLine(" ");

}

}

catch (Exception e)

{

Console.WriteLine(e);

}

return result;

}

}

}

以上是 C# COMException异常排除 的全部内容, 来源链接: utcz.com/p/189765.html

回到顶部