For Reading excel file i use this code.i have abc.xls file
when i import abc.xls file excelSheet.get_Range("A1", "A1").Text read junck value
i copy all content of abc.xls to new file pqr.xls it show correct in
excelSheet.get_Range("A1", "A1").Text
Whats the probelm i am not able to figure out issue.any idea?
Microsoft.Office.Interop.Excel.Application excelApp = null;
Microsoft.Office.Interop.Excel.Workbook excelWrkBk = null;
Microsoft.Office.Interop.Excel.Worksheet excelSheet = null;
Microsoft.Office.Interop.Excel.Range excelRange = null;
try
{
excelApp = new Microsoft.Office.Interop.Excel.Application();
excelWrkBk = excelApp.Workbooks.Open(SourceFileName,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, true);
excelSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelWrkBk.Sheets[1];
while (true)
{
if (!Convert.ToString(excelSheet.get_Range("A1", "A1").Text).Contains("Sl No."))
{
excelRange = (Microsoft.Office.Interop.Excel.Range)excelSheet.get_Range("A1", "AG1");
excelRange.Delete(Microsoft.Office.Interop.Excel.XlDeleteShiftDirection.xlShiftUp);
}
else
{
break;
}
}
excelWrkBk.Save();
excelWrkBk.Close(true, true, Type.Missing);
return GetReadOtherExcelFile(SourceFileName);
}
catch
{
throw;
}
finally
{
excelRange = null;
excelSheet = null;
excelWrkBk = null;
if (excelApp != null) excelApp.Quit();
excelApp = null;
}