I have one simple problem when trying to write List into the excel workbook. on string its work perfect but problem is how i can put list into excel
public List<string> _RoomType = new List<string>();
Excel.Range RoomType = (Excel.Range)_sheet.get_Range(_sheet.Cells[22, "B"] as Excel.Range, _sheet.Cells[25, "B"] as Excel.Range);
for (int i = 0; i < _RoomType.Count; i++)
开发者_运维问答 {
RoomType.set_Value(Type.Missing, _RoomType[i]);
if im using for loop it sets from 22B to 25B only first value which is in list and if i dont use 'for' visual studio gives me exception : Exception from HRESULT: 0x800A03EC can anyone help me?
You need to pass a 2-dimensional array to the set_Value method. You have to make sure though that number of items in your list equals the number of cells in your range.
Object[,] dataArray = new object[1, _RoomType.Count];
for (int i = 0; i < _RoomType.Count; i++)
{
dataArray[0, i] = _RoomType[i];
}
RoomType.set_Value(Type.Missing, dataArray);
精彩评论