Search code examples
c#excelc#-4.0excel-2007

How can we change the Datatype of the Excel cell to CellValues.String from c#


how can we change the DataType = CellValues.String, of each excel column from c#.

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());
    }
}

Solution

  • put a string format("'"+) in frond of each collection

    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());
        }
    }