Change excel sheet column in a "Text" Format
Hi,I am creating a excel sheet and i want to change a particular column format into "Text" so i used below code but its giving me error.
In below code i am getting error "System.InvalidCastException" on this below line
((Microsoft.Office.Interop.Excel.IRange)(excelWorkSheet.Cells[1, i])).EntireColumn.NumberFormat = "Text";
Please help me how to resolve this. I am using .net framework 4.0 and 3.5 framework i was getting a diffrent error "Csharp.RuntimeBinder is not predefined".
for (int i = 1; i < table.Columns.Count; i++)
{
excelWorkSheet.Cells[1, i] = table.Columns[i].ColumnName;
if (table.Columns[i].ColumnName.Trim() == "ID1")
{
((Microsoft.Office.Interop.Excel.IRange)(excelWorkSheet.Cells[1, i])).EntireColumn.NumberFormat = "Text";
}
if (filetype == "PID")
{
//excelWorkSheet.Columns.NumberFormat = "0";
excelWorkSheet.get_Range("T:T",Type.Missing).NumberFormat = "0";
excelWorkSheet.get_Range("AA:AA", Type.Missing).NumberFormat = "0";
excelWorkSheet.get_Range("AH:AH", Type.Missing).NumberFormat = "0";
}
}