工作遇到一个问题,代码缩减如下:
  this.axSpreadsheet2.Cells.Clear();//将单元格设为文本格式
  foreach(DataRow dr in table.Rows)
{
for(col = 1; col <= COL_COUNT; col++)
{

((OWC.Range)axSpreadsheet2.Cells[row, col]).Value = dr[col - 1].ToString();
}
row++;
}
其中当col==2时,dr[col-1].ToString()是字符串"07206812"之类,前面这个"0"是代表年份的。现在到axSpreadsheet2中时却将"0"截走了,就像是单元格被设为常规类型一样的。直接在axSpreadsheet2中第二列的单元格中将零补上,又会被系统自动截去"0",这样验证了在控件上单元还是当作常规处理了。
但从axSpreadsheet2导出到Excel中该列(也就是第二列)的单元格又是文本格式的。
请问大侠们现在怎么办,在线急等,解决了马上放分!

解决方案 »

  1.   

    this.axSpreadsheet2.Cells.set_NumberFormat("@");对了让面有句错了.设置文本格式的代码应是这样,太急了啊
      

  2.   

    this.axSpreadsheet2.Cells.Clear();
    this.axSpreadsheet2.Cells.set_NumberFormat("@");//将单元格设为文本格式
    int row = 1;
      foreach(DataRow dr in table.Rows)
    {
    for(int col = 1; col <= COL_COUNT; col++)
    {((OWC.Range)axSpreadsheet2.Cells[row, col]).Value = dr[col - 1].ToString();
    }
    row++;
    }
      

  3.   

    十二天后来了个正确的答复.
    我仿佛听到<迟来的爱>这首歌.
    小生这厢有礼了!