Service Virtualization

Expand all | Collapse all

How to write a special character in Excel

Jump to Best Answer
  • 1.  How to write a special character in Excel

    Posted 05-12-2017 02:50 AM

    Hi All,

     

    I want to write the filter value in Excel , in the filter value is like this [141234354235].

     

    AccountID value in the Property = [141234354235]

     

    String ID = testExec.getStateValue("AccountID");

     

    while executing the Javascript am getting the below error. Please help me on this.

     

    Thanks

    Ram

     

     

    ============================================================================
    | Error in Script
    ============================================================================
    | Step: Write to an Excel
    ----------------------------------------------------------------------------
    | Message: Sourced file: inline evaluation of: ``import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.userm . . . '' : Typed variable declaration : at Line: 22 : in file: inline evaluation of: ``import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.userm . . . '' : String ID = testExec .getStateValue ( "AccountID" )

    Target exception: java.lang.ClassCastException: Cannot cast java.util.Vector to java.lang.String

    ----------------------------------------------------------------------------
    | Trapped Exception: Sourced file: inline evaluation of: ``import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.userm . . . '' : Typed variable declaration : at Line: 22 : in file: inline evaluation of: ``import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.userm . . . '' : String ID = testExec .getStateValue ( "AccountID" )

    Target exception: java.lang.ClassCastException: Cannot cast java.util.Vector to java.lang.String

    | Trapped Message: bsh.TargetError: Sourced file: inline evaluation of: ``import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.userm . . . '' : Typed variable declaration : at Line: 22 : in file: inline evaluation of: ``import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.userm . . . '' : String ID = testExec .getStateValue ( "AccountID" )

    Target exception: java.lang.ClassCastException: Cannot cast java.util.Vector to java.lang.String

    ----------------------------------------------------------------------------
    STACK TRACE
    bsh.TargetError: Sourced file: inline evaluation of: ``import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.userm . . . '' : Typed variable declaration : at Line: 22 : in file: inline evaluation of: ``import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.userm . . . '' : String ID = testExec .getStateValue ( "AccountID" )

    Target exception: java.lang.ClassCastException: Cannot cast java.util.Vector to java.lang.String

    at bsh.UtilTargetError.toEvalError(UtilTargetError.java:70)
    at bsh.UtilEvalError.toEvalError(UtilEvalError.java:94)
    at bsh.BSHTypedVariableDeclaration.eval(BSHTypedVariableDeclaration.java:90)
    at bsh.Interpreter.eval(Interpreter.java:664)
    at bsh.Interpreter.eval(Interpreter.java:758)
    at bsh.Interpreter.eval(Interpreter.java:747)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:636)
    at com.itko.lisa.test.ScriptExecHandler.executeScriptOld(ScriptExecHandler.java:528)
    at com.itko.lisa.test.ScriptNode._execute(ScriptNode.java:126)
    at com.itko.lisa.test.ScriptNode.execute(ScriptNode.java:103)
    at com.itko.lisa.test.TestNode.executeNode(TestNode.java:981)
    at com.itko.lisa.test.TestCase.execute(TestCase.java:1283)
    at com.itko.lisa.test.TestCase.execute(TestCase.java:1198)
    at com.itko.lisa.test.TestCase.executeNextNode(TestCase.java:1183)
    at com.itko.lisa.editor.WalkThruPanel.prepAndExecNode(WalkThruPanel.java:1050)
    at com.itko.lisa.editor.WalkThruPanel.access$900(WalkThruPanel.java:70)
    at com.itko.lisa.editor.WalkThruPanel$10.doCallback(WalkThruPanel.java:963)
    at com.itko.util.swing.panels.ProcessingDialog$2.run(ProcessingDialog.java:194)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassCastException: Cannot cast java.util.Vector to java.lang.String
    at bsh.Types.castError(Types.java:524)
    at bsh.Types.castError(Types.java:512)
    at bsh.Types.castObject(Types.java:502)
    at bsh.Types.castObject(Types.java:310)
    at bsh.Variable.setValue(Variable.java:83)
    at bsh.Variable.<init>(Variable.java:49)
    at bsh.NameSpace.setTypedVariable(NameSpace.java:703)
    at bsh.BSHTypedVariableDeclaration.eval(BSHTypedVariableDeclaration.java:87)
    ... 16 more
    ============================================================================



  • 2.  Re: How to write a special character in Excel

    Posted 05-12-2017 03:09 AM

    Since you writing to excel file you may need to import libraries. Its looks like you missing to include import statement for some of library.  Like below. 

    import org.apache.poi.xssf.usermodel.XSSFCell;
    import org.apache.poi.xssf.usermodel.XSSFRow;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;

     

    Also i assume you imported java.lang.String as well. 

     

    Hope this will resolve your issue.  

     

    Thanks, 

    Rajesh k Singh



  • 3.  Re: How to write a special character in Excel

    Posted 05-12-2017 03:43 AM

    Thanks Rajesh...

     

    I haved imported java.lang.String and executed but getting the below error.

    import org.apache.poi.xssf.usermodel.XSSFCell;
    import org.apache.poi.xssf.usermodel.XSSFRow;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    import org.apache.poi.ss.usermodel.FormulaEvaluator;
    import java.lang.String;

     

    Error: Target exception: java.lang.ClassCastException: Cannot cast java.util.Vector to java.lang.String

     

    Please help.

     

    Thanks

    Ram



  • 4.  Re: How to write a special character in Excel

    Posted 05-12-2017 01:20 PM

    Hi Ram,

     

    I think you issue is with the "AccountID" property.

     

    Can you try the following in your code & see if it helps

     

    String ID = testExec.getStateValue("AccountID").toString();



  • 5.  Re: How to write a special character in Excel

    Posted 05-15-2017 07:11 AM

    Hi,

    With toString() you can capture the Id and store it in some property and then put it in excel.



  • 6.  Re: How to write a special character in Excel

    Posted 05-12-2017 09:53 AM

    May I know what filter you use? If possible share screenshot. AccountID and ID datatype mismatch so type casting exception thrown.  

     

    Thanks, 

    Rajesh k Singh



  • 7.  Re: How to write a special character in Excel

    Posted 05-14-2017 01:28 AM

    Hi Rajesh, 

    I am using this"Parse HTML into list of Attributes" filter to capture response.

     

    And the property value of the response is coming like [12132343,3564576547,57568768]

     

    So i want capture the individual item in the above square bracket and write it to an excel cell.

     

    Thanks

     

    Thanks

    Ram



  • 8.  Re: How to write a special character in Excel

    Posted 05-14-2017 10:42 PM

    Are you writing 3 values into 1 cell or individual cell?  



  • 9.  Re: How to write a special character in Excel

    Posted 05-15-2017 12:59 AM

    HI Eric,

     

    Not in 1 cell, in a 3 seperate Cells.

     

    Thanks

    Ram



  • 10.  Re: How to write a special character in Excel
    Best Answer

    Posted 05-15-2017 09:02 AM

    Hi All,

     

    thanks for all your help on this.

     

    I have used the below code to conver the Vector element into string and then writting into excel file.

    import java.util.Vector;

    Vector v = testExec.getStateValue("AccountID");
    int totalElements = v.size();
    testExec.setStateValue("totalElements",totalElements);
    for(int index=0; index < totalElements; index++){
    testExec.setStateValue("ID"+index,v.get(index)).toString();
    }
    }