日期:2014-05-17  浏览次数:20719 次

导出EXCEL 报异常
C# code

for (int i = 0; i < gridView.RowCount; i++)
{                                                                
      for (int j = 0; j < gridView.ColumnCount; j++)
      {
          excel.Cells[i + 2, j + 1] = gridView[j, i].Value.ToString();
          Range ra2;                                   
          ra2 = sheet.get_Range(excel.Cells[1,1]);
          ra2.Font.Bold = true;
          ra2 = null;
       }
}



我想根据条件设置单元格格式
实验了一下给每个单元格都设置粗体
结果报异常 HRESULT:0x800A03EC
如果把这段删除就没事了
C# code

          ra2 = sheet.get_Range(excel.Cells[1,1]);
          ra2.Font.Bold = true;


单独使用这两行不报错
C# code

          Range ra2;                                   
          ra2 = null;


谁帮我看看 那里的问题呀
不明白

------解决方案--------------------
Excel文件.Cells[1,1].Font.Bold = true;