Writing a large 2d array to Excel

前端 未结 2 1722
难免孤独
难免孤独 2021-02-10 02:48

I\'m looking to write a large 2d array to an Excel worksheet using C#. If the array is 500 x 500, the code that I would use to write this is as follows:

 var st         


        
2条回答
  •  醉梦人生
    2021-02-10 03:27

    I just wrote a small example that worked for me. Originally found at SO this answer. I had to adapt this answer as in my Interop assembly (Excel 14 Object Library) there is no more method Worksheet.get_Range(.., ..)

    var startCell = ws.Cells[1, 1];
    int row = 500, col = 500;
    var endCell = ws.Cells[row, col];
    try
    {
        // access range by Property and cells indicating start and end           
        var writeRange = ws.Range[startCell, endCell];
        writeRange.Value = myArray;
    }
    catch (COMException ex)
    {
        Debug.WriteLine(ex.Message);
        Debugger.Break();
    }
    

提交回复
热议问题