Write array to Excel range
You are trying to write data from an array to a range in an Excel workbook using a code snippet that contains an objData
array. However, you run into a problem where all cells in the range receive the value of the first item in the array.
Solution using intermediate objects:
A valid solution involves creating an intermediate object to store the data before writing it to the region. This technique eliminates the problem you are experiencing and ensures that each cell receives the correct value. Here is an example:
<code>object[,] arr = new object[objData.GetLength(0), 1]; Array.Copy(objData, arr, objData.GetLength(0)); Range rn_Temp = (Range)XlApp.get_Range(RangeName, m); rn_Temp.get_Resize(objData.GetLength(0), 1).Value2 = arr;</code>
The above is the detailed content of How to Write Array Data to Excel Ranges Correctly?. For more information, please follow other related articles on the PHP Chinese website!