John Walker John Walker - 2 months ago 7
C# Question

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

Answer

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