none
How to get the Particular Cell Value from the Excel RRS feed

  • Question

  • Hi All,

    I've an Excel with 20 sheets.

    lets say , In the Excel Sheet, I've Sheet1 and Sheet 2.

    In the Sheet1, I've SUBTOTAL MATERIAL (Excludes Sales Tax) at B125 and the value for this is at T125 as 

     $    53,875.28 

    .

    In the Sheet2, also  I've SUBTOTAL MATERIAL (Excludes Sales Tax) at B125 and the value for this is at T125 as

     $   875.28 

    Here i need to get this values and compare this values.


                               Microsoft.Office.Interop.Excel.Worksheet wsOrderMat = theWorkbook.Sheets["Sheet1"];
                               Microsoft.Office.Interop.Excel.Range Material_Order = wsOrderMat.Range["T125"];

                               Microsoft.Office.Interop.Excel.Worksheet wsOrderLabor = theWorkbook.Sheets["Sheet2"];
                               Microsoft.Office.Interop.Excel.Range Labor_Order = wsOrderLabor.Range["T125"];

                               decimal strMatOrder = Material_Order.Value;
                               decimal strLabourOrder = Labor_Order.Value;

                               string strTurnMatLab = string.Empty;

                               if (strMatOrder.Equals(null))
                               {
                                   strTurnMatLab = Convert.ToString(strLabourOrder);
                               }
                               else if (strLabourOrder.Equals(null))
                               {
                                   strTurnMatLab = Convert.ToString(strMatOrder);
                               }
                               else
                               {
                                   strTurnMatLab = "TurnKey";
                               }

    I am using the above code for getting the values.

    But i am getting the message like Cannot implicitly convert type 'string' to 'decimal' but i need to check the value should be the number and then i need to compare.

    Kindly help me.

    Regards,

    Sureshbabu

    Tuesday, July 26, 2016 3:36 PM

Answers

  • Hi Sureshbabu Yadavalli,

    did you mean that you got ,"Cannot implicitly convert type 'decimal' to 'string'." on the line below?

    Here first I want to again confirm with you, because the value you trying to assign the variable is String Data type.

    The variable we had declare is also a String Data type.

    so it should assign the value successfully.

    I did that on my side with your code and it is working correctly.

    please verify it and post the snapshot of error here along with that line.

    in the post below I find that you had asked an another question.

    let me inform you that you can ask only one question in one thread.

    if you have a new issue or another question that is not related with current question that every time you have to create a new thread for that.

    so here I would recommend to you that please create a new thread for the issue you had mentioned below.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 28, 2016 8:26 AM
    Moderator

All replies

  • Please tell us on what line you get the error.

    Best regards, George

    Tuesday, July 26, 2016 4:46 PM
  • Hi Sureshbabu Yadavalli,

     its looks like you are having a string value in your cell. so when you try to assign that string value to decimal variable at that time you got this error.

    so you need to define the decimal variables as string like below.

      string strMatOrder = Material_Order.Value;
      string strLabourOrder = Labor_Order.Value;

    so now your string data are going to stored in string variable so you will not get error also you need to change the line I have mentioned below in which you try to type casting the values to string. because as we are already storing the data as string so there is no need to type casting.

     if (strMatOrder.Equals(null))
                {
                    strTurnMatLab = strLabourOrder;
                }
                else if (strLabourOrder.Equals(null))
                {
                    strTurnMatLab = strMatOrder;
                }

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, July 27, 2016 4:42 AM
    Moderator
  • Hi Deepak,

    thanks for providing the solution.

    I've done the same which you've suggested and am getting the data as "Link Broken" from the Cell Value .

    And After the  string strMatOrder = Material_Order.Value; step, the its showing the exception as Cannot implicitly convert type 'decimal' to 'string'.

    Kindly Suggest.

    Regards,
    Sureshbabu

    Wednesday, July 27, 2016 10:27 AM
  • How to get the row number of a particular string in the Sheet.

    I am using the below code to get the row number in the Sheet

    But it showing that the process can t access the files becoz the file is accessing by another process.

             Microsoft.Office.Interop.Excel.Range oRng = GetSpecifiedRange(cellContent, wsOrderMat);                              

     private ExcelTools.Interop.Excel.Range GetSpecifiedRange(string cellContent, ExcelTools.Interop.Excel.Worksheet wsOrderMat)
            {

               Microsoft.Office.Interop.Excel.Range last = wsOrderMat.Cells.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
                Microsoft.Office.Interop.Excel.Range range = wsOrderMat.get_Range("A1", last);

                object missing = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Excel.Range currentFind = null;
               // Microsoft.Office.Interop.Excel.Range firstFind = null;
                currentFind = wsOrderMat.get_Range(range).Find(cellContent, missing,
                               Microsoft.Office.Interop.Excel.XlFindLookIn.xlValues,
                               Microsoft.Office.Interop.Excel.XlLookAt.xlPart,
                               Microsoft.Office.Interop.Excel.XlSearchOrder.xlByRows,
                               Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, false, missing, missing);
                return currentFind;
            }



    Wednesday, July 27, 2016 2:47 PM
  • Sureshbabu Yadavalli,

    With all due respect but you really need to get a deeper understanding of how Excel and VBA work. Your code looks like a copy and paste example and your question suggests that you have not understood what each line does.

    If you put in some effort and study Excel/VBA you will see that this is not difficult to solve.

    Even if someone provides you with a solution here, you will not be better off when you hit the next obstacle.
    You really need a basic understanding before you design a rocket.


    Best regards, George

    Wednesday, July 27, 2016 4:04 PM
  • Hi Sureshbabu Yadavalli,

    did you mean that you got ,"Cannot implicitly convert type 'decimal' to 'string'." on the line below?

    Here first I want to again confirm with you, because the value you trying to assign the variable is String Data type.

    The variable we had declare is also a String Data type.

    so it should assign the value successfully.

    I did that on my side with your code and it is working correctly.

    please verify it and post the snapshot of error here along with that line.

    in the post below I find that you had asked an another question.

    let me inform you that you can ask only one question in one thread.

    if you have a new issue or another question that is not related with current question that every time you have to create a new thread for that.

    so here I would recommend to you that please create a new thread for the issue you had mentioned below.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 28, 2016 8:26 AM
    Moderator