我们如何从c#将Excel单元格的数据类型更改为CellValues.String

时间:2016-09-18 06:26:29

标签: c# excel c#-4.0 excel-2007

如何从c#更改每个excel列的DataType = CellValues.String。

for (int index = 0; index < NoOfRecords; index++)
 {
   for (int j = 0; j < colCount; j++)
    {                            
      mWSheet1.Cells[(rowCount) + index, j + 1] =Convert.ToString(ResultsData.Rows[index][j].ToString());
    }
}

1 个答案:

答案 0 :(得分:1)

在每个集合中添加字符串格式(“'”+)

for (int index = 0; index < NoOfRecords; index++)
 {
   for (int j = 0; j < colCount; j++)
    {                            
      mWSheet1.Cells[(rowCount) + index, j + 1] ="'"+Convert.ToString(ResultsData.Rows[index][j].ToString());
    }
}