導出excel時因字段過長導致的hresult:0x800a03ec錯誤解決辦法

          <pre name="code" class="csharp">               range = xlSheet.get_Range(app.Cells[1, 1], app.Cells[RowCount + 2, colCount]);
               
               objData[RowCount + 1, 0] = "合計:" + gridView.Rows.Count.ToString();

                range.Value2 = objData;//我是這句出的錯

                app.Visible = true;


            

                               解決辦法:

                             把

               range.Value2 = objData;
</pre>                              改成<pre name="code" class="csharp"> <pre name="code" class="csharp">                 for (int r = 1; r <= RowCount + 2; r++)
                {
                    for (int c = 1; c <= colCount; c++)
                    {

                        xlSheet.get_Range(app.Cells[r, c], app.Cells[r, c]).Value2 = objData[r - 1, c - 1];
                    }
                }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章