简体   繁体   中英

Excel-DNA, The displayed array is an array full of #VALUE!, how to resolve this

I am trying to use Excel-DNA and ArrayResizer to display an 54x4 array in excel. I have set up a breakpoint at the return value in my C# code. and can see the return value is good.

{object[54, 4]}
[0, 0]: "000001"
[0, 1]: "One "
[0, 2]: 12
[0, 3]: "OK"
[1, 0]: "000002"
[1, 1]: "Two "
[1, 2]: 21
[1, 3]: "Ok"
[2, 0]: "000003"
[2, 1]: "3"
......

The displayed array on excel is in the right size, but is filled with #VALUE! 在此处输入图片说明

May know what am I doing wrong here?

Microsoft Excel may display the #VALUE! error if your formula includes cells that contain different data types.

https://support.office.com/en-us/article/Correct-a-VALUE-error-cec24732-88fc-4b76-945c-32fd4e847573

My thought is that the cause is your array, which is of type object has both strings and integer types in it and this is confusing XL. With the information provided, my recommendation is to convert all values in your source array to string type instead of using object type-

    Object[] objArr = {"a", "b", "c"};
    String[] strArr = Array.ConvertAll<Object, string>(objArr, x => x.ToString());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM