Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 29, 2011 11:43 AM by hspatil
Member
97 Points
156 Posts
Jul 29, 2011 10:01 AM|LINK
Dear All,
I am using following code line for reading cell value from excel file, but when if the cell value is blank then its giving error, can anybody tell me how to resolve this issue ?
string strGetPhysicalCellValue = ((Microsoft.Office.Interop.Excel.Range)oWorkSheet.Cells[Row, intAnsValue]).Value2.ToString();
Error:
"'oWorkSheet.Cells' threw an exception of type 'System.Runtime.InteropServices.COMException' string "
For check the null value i tried if condition therefore also it's giving error,
if(((Microsoft.Office.Interop.Excel.Range)oWorkSheet.Cells[Row, intAnsValue]).Value2.ToString() != null )
{
strGetPhysicalCellValue = ((Microsoft.Office.Interop.Excel.Range)oWorkSheet.Cells[Row, intAnsValue]).Value2.ToString();
}
Thanks and Regard's
Harish Patil
Star
10258 Points
1760 Posts
Jul 29, 2011 10:35 AM|LINK
Try, Check for the given row and intAnsValue returns the cell or range.
if(((Microsoft.Office.Interop.Excel.Range)oWorkSheet.Cells[Row, intAnsValue]).Value2 != null ) { strGetPhysicalCellValue = ((Microsoft.Office.Interop.Excel.Range)oWorkSheet.Cells[Row, intAnsValue]).Value2.ToString(); }
Jul 29, 2011 11:43 AM|LINK
Thnks. I solved the issue.
hspatil
Member
97 Points
156 Posts
Error While read cell value from excel file.
Jul 29, 2011 10:01 AM|LINK
Dear All,
I am using following code line for reading cell value from excel file, but when if the cell value is blank then its giving error, can anybody tell me how to resolve this issue ?
string strGetPhysicalCellValue = ((Microsoft.Office.Interop.Excel.Range)oWorkSheet.Cells[Row, intAnsValue]).Value2.ToString();
Error:
"'oWorkSheet.Cells' threw an exception of type 'System.Runtime.InteropServices.COMException' string
"
For check the null value i tried if condition therefore also it's giving error,
if(((Microsoft.Office.Interop.Excel.Range)oWorkSheet.Cells[Row, intAnsValue]).Value2.ToString() != null )
{
strGetPhysicalCellValue = ((Microsoft.Office.Interop.Excel.Range)oWorkSheet.Cells[Row, intAnsValue]).Value2.ToString();
}
Thanks and Regard's
Harish Patil
chandrasheka...
Star
10258 Points
1760 Posts
Re: Error While read cell value from excel file.
Jul 29, 2011 10:35 AM|LINK
Try, Check for the given row and intAnsValue returns the cell or range.
if(((Microsoft.Office.Interop.Excel.Range)oWorkSheet.Cells[Row, intAnsValue]).Value2 != null ) { strGetPhysicalCellValue = ((Microsoft.Office.Interop.Excel.Range)oWorkSheet.Cells[Row, intAnsValue]).Value2.ToString(); }Please try the answer for the post and finally Don't forget to click “Mark as Answer” on the post that helped you.
hspatil
Member
97 Points
156 Posts
Re: Error While read cell value from excel file.
Jul 29, 2011 11:43 AM|LINK
Thnks. I solved the issue.