English 中文(简体)
C# Excel UDF range核销有误,但HRESult除外:0x800A03EC
原标题:C# Excel UDF range write back get an error, Exception from HRESULT: 0x800A03EC
  • 时间:2012-04-25 11:56:22
  •  标签:
  • c#
  • excel
public string Name(string code)
    {
        MyExcelAppInstance.Volatile(true);

        MsExcel.Application oApp = new MsExcel.Application();
        oApp.Visible = true;
        oApp.UserControl = true;
        Object oBooks = oApp.Workbooks;
        System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
        oBooks.GetType().InvokeMember("Add", System.Reflection.BindingFlags.InvokeMethod, null, oBooks, null, ci);

        oApp.Visible = true;
        oApp.UserControl = true;
        System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
        System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
        oApp.Workbooks.Add();
        System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;

        MsExcel.Range rng = MyExcelAppInstance.get_Range("A1:D4", Type.Missing);
        //Get a 2D Array of values from the range in one shot: 
        object[,] myArray = (object[,])rng.get_Value(Type.Missing);

        // Process  myArray  however you want here. 
        // Note that the Array returned from Excel is base 1, not base 0. 
        // To be safe, use GetLowerBound() and GetUpperBound: 
        for (int row = myArray.GetLowerBound(0); row <= myArray.GetUpperBound(0); row++)
        {
            for (int column = myArray.GetLowerBound(1); column <= myArray.GetUpperBound(1); column++)
            {
                if (myArray[row, column] is double)
                {
                    myArray[row, column] = (double)myArray[row, column] * 2;
                }
            }
        }

        // Pass back the results in one shot: 
        rng.set_Value(Type.Missing, myArray);  // where gets an error

        return code + code;
    }

我发现了一个错误,即“从温和派接受:0x800A03EC”。 我试图确定当地人,但确实没有工作。 如果没有固定价值,它就进行罚款。 为什么没有工作?

问题回答

我曾经有过同样的问题,而错误却被一个无效的论点所造成(我通过的是以无效格式划定的范围)。 确保在你打电话<代码>_Value时,范围及所有阵列均有效。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签