Want to Save data received from mongodb collection to excel using java in selenium












0















I'm using appium with eclipse. In my project I need to read config data of my account from Mongo DB and based on the value assigned to key I have to execute code. My config file is as below. When I read it from mongo I get data in the form of Document, but I am not getting any function to save document in excel.



Config in mongo:



  {
"_id" : ObjectId("5b64017c6c9b9d1a9d08563a"),
"configId" : "1503121975430462",
"configType" : "Workshop",
"customerSource" : {
"enabled" : true,
"options" : [
"Walk-in",
"Newspaper Ad",
"Print Ad",
"TV Ad"
]
},
"vehicleType" : {
"enabled" : true,
"values" : [
"cars",
"bikes"
]
},
"createdOn" : ISODate("2018-09-06T09:47:25.006Z"),
"updatedOn" : ISODate("2018-11-27T15:55:22.724Z")
}


// function to get data from config.



`public Document GetConfig(String AccountId) throws Exception{
String MongoColl = ExcelUtils.getCellData(7,4);
String QueryKey = ExcelUtils.getCellData(7,5);
//Get table/collection in variable
MongoCollection<Document> collector = GetCollection(MongoColl);
// Get documents by query
BasicDBObject query = new BasicDBObject();
query.put(QueryKey, WorkshopId);
//Get value based on query
MongoIterable<Document> cursor = collector.find(query);
//Print first row of data returned
System.out.println(cursor.first());
return cursor.first();
}`


// Output I get is like below



`Document{{_id=1514279651131149, configId=1503121975430462, configType=Workshop,  customerSource=Document{{enabled=true, options=[Walk-in, Newspaper Ad, Print Ad, TV Ad, Leaflet]}}, vehicleType=Document{{enabled=true, values=[cars]}}, createdOn=Tue Dec 26 14:44:11 IST 2017, updatedOn=Tue Nov 27 19:11:42 IST 2018}}`


// function to save data in excel is as below



    public static void setCellData(Document value, int RowNum, int ColNum) throws Exception {
try {
row = excelWSheet.getRow(RowNum);
if (row == null) {
row = excelWSheet.createRow(RowNum);
}
cell = row.getCell(ColNum);
if (cell == null) {
cell = row.createCell(ColNum);
cell.setCellValue(value);
} else {
cell.setCellValue(value);
}
// Constant variables Test Data path and Test Data file name
FileOutputStream fileOut = new FileOutputStream(Constant.Path_TestData + Constant.File_TestData);
excelWBook.write(fileOut);
fileOut.flush();
fileOut.close();

} catch (Exception e) {
try {
throw (e);
} catch (IOException e1) {
e1.printStackTrace();
}
}

}


But this gives error:



"The method setCellValue(double) in the type Cell is not applicable for the arguments (Document)"


I want to save all the values from config to an excel file. Can anyone suggest how to save this output(document) in Key:value format in excel in different rows?










share|improve this question





























    0















    I'm using appium with eclipse. In my project I need to read config data of my account from Mongo DB and based on the value assigned to key I have to execute code. My config file is as below. When I read it from mongo I get data in the form of Document, but I am not getting any function to save document in excel.



    Config in mongo:



      {
    "_id" : ObjectId("5b64017c6c9b9d1a9d08563a"),
    "configId" : "1503121975430462",
    "configType" : "Workshop",
    "customerSource" : {
    "enabled" : true,
    "options" : [
    "Walk-in",
    "Newspaper Ad",
    "Print Ad",
    "TV Ad"
    ]
    },
    "vehicleType" : {
    "enabled" : true,
    "values" : [
    "cars",
    "bikes"
    ]
    },
    "createdOn" : ISODate("2018-09-06T09:47:25.006Z"),
    "updatedOn" : ISODate("2018-11-27T15:55:22.724Z")
    }


    // function to get data from config.



    `public Document GetConfig(String AccountId) throws Exception{
    String MongoColl = ExcelUtils.getCellData(7,4);
    String QueryKey = ExcelUtils.getCellData(7,5);
    //Get table/collection in variable
    MongoCollection<Document> collector = GetCollection(MongoColl);
    // Get documents by query
    BasicDBObject query = new BasicDBObject();
    query.put(QueryKey, WorkshopId);
    //Get value based on query
    MongoIterable<Document> cursor = collector.find(query);
    //Print first row of data returned
    System.out.println(cursor.first());
    return cursor.first();
    }`


    // Output I get is like below



    `Document{{_id=1514279651131149, configId=1503121975430462, configType=Workshop,  customerSource=Document{{enabled=true, options=[Walk-in, Newspaper Ad, Print Ad, TV Ad, Leaflet]}}, vehicleType=Document{{enabled=true, values=[cars]}}, createdOn=Tue Dec 26 14:44:11 IST 2017, updatedOn=Tue Nov 27 19:11:42 IST 2018}}`


    // function to save data in excel is as below



        public static void setCellData(Document value, int RowNum, int ColNum) throws Exception {
    try {
    row = excelWSheet.getRow(RowNum);
    if (row == null) {
    row = excelWSheet.createRow(RowNum);
    }
    cell = row.getCell(ColNum);
    if (cell == null) {
    cell = row.createCell(ColNum);
    cell.setCellValue(value);
    } else {
    cell.setCellValue(value);
    }
    // Constant variables Test Data path and Test Data file name
    FileOutputStream fileOut = new FileOutputStream(Constant.Path_TestData + Constant.File_TestData);
    excelWBook.write(fileOut);
    fileOut.flush();
    fileOut.close();

    } catch (Exception e) {
    try {
    throw (e);
    } catch (IOException e1) {
    e1.printStackTrace();
    }
    }

    }


    But this gives error:



    "The method setCellValue(double) in the type Cell is not applicable for the arguments (Document)"


    I want to save all the values from config to an excel file. Can anyone suggest how to save this output(document) in Key:value format in excel in different rows?










    share|improve this question



























      0












      0








      0








      I'm using appium with eclipse. In my project I need to read config data of my account from Mongo DB and based on the value assigned to key I have to execute code. My config file is as below. When I read it from mongo I get data in the form of Document, but I am not getting any function to save document in excel.



      Config in mongo:



        {
      "_id" : ObjectId("5b64017c6c9b9d1a9d08563a"),
      "configId" : "1503121975430462",
      "configType" : "Workshop",
      "customerSource" : {
      "enabled" : true,
      "options" : [
      "Walk-in",
      "Newspaper Ad",
      "Print Ad",
      "TV Ad"
      ]
      },
      "vehicleType" : {
      "enabled" : true,
      "values" : [
      "cars",
      "bikes"
      ]
      },
      "createdOn" : ISODate("2018-09-06T09:47:25.006Z"),
      "updatedOn" : ISODate("2018-11-27T15:55:22.724Z")
      }


      // function to get data from config.



      `public Document GetConfig(String AccountId) throws Exception{
      String MongoColl = ExcelUtils.getCellData(7,4);
      String QueryKey = ExcelUtils.getCellData(7,5);
      //Get table/collection in variable
      MongoCollection<Document> collector = GetCollection(MongoColl);
      // Get documents by query
      BasicDBObject query = new BasicDBObject();
      query.put(QueryKey, WorkshopId);
      //Get value based on query
      MongoIterable<Document> cursor = collector.find(query);
      //Print first row of data returned
      System.out.println(cursor.first());
      return cursor.first();
      }`


      // Output I get is like below



      `Document{{_id=1514279651131149, configId=1503121975430462, configType=Workshop,  customerSource=Document{{enabled=true, options=[Walk-in, Newspaper Ad, Print Ad, TV Ad, Leaflet]}}, vehicleType=Document{{enabled=true, values=[cars]}}, createdOn=Tue Dec 26 14:44:11 IST 2017, updatedOn=Tue Nov 27 19:11:42 IST 2018}}`


      // function to save data in excel is as below



          public static void setCellData(Document value, int RowNum, int ColNum) throws Exception {
      try {
      row = excelWSheet.getRow(RowNum);
      if (row == null) {
      row = excelWSheet.createRow(RowNum);
      }
      cell = row.getCell(ColNum);
      if (cell == null) {
      cell = row.createCell(ColNum);
      cell.setCellValue(value);
      } else {
      cell.setCellValue(value);
      }
      // Constant variables Test Data path and Test Data file name
      FileOutputStream fileOut = new FileOutputStream(Constant.Path_TestData + Constant.File_TestData);
      excelWBook.write(fileOut);
      fileOut.flush();
      fileOut.close();

      } catch (Exception e) {
      try {
      throw (e);
      } catch (IOException e1) {
      e1.printStackTrace();
      }
      }

      }


      But this gives error:



      "The method setCellValue(double) in the type Cell is not applicable for the arguments (Document)"


      I want to save all the values from config to an excel file. Can anyone suggest how to save this output(document) in Key:value format in excel in different rows?










      share|improve this question
















      I'm using appium with eclipse. In my project I need to read config data of my account from Mongo DB and based on the value assigned to key I have to execute code. My config file is as below. When I read it from mongo I get data in the form of Document, but I am not getting any function to save document in excel.



      Config in mongo:



        {
      "_id" : ObjectId("5b64017c6c9b9d1a9d08563a"),
      "configId" : "1503121975430462",
      "configType" : "Workshop",
      "customerSource" : {
      "enabled" : true,
      "options" : [
      "Walk-in",
      "Newspaper Ad",
      "Print Ad",
      "TV Ad"
      ]
      },
      "vehicleType" : {
      "enabled" : true,
      "values" : [
      "cars",
      "bikes"
      ]
      },
      "createdOn" : ISODate("2018-09-06T09:47:25.006Z"),
      "updatedOn" : ISODate("2018-11-27T15:55:22.724Z")
      }


      // function to get data from config.



      `public Document GetConfig(String AccountId) throws Exception{
      String MongoColl = ExcelUtils.getCellData(7,4);
      String QueryKey = ExcelUtils.getCellData(7,5);
      //Get table/collection in variable
      MongoCollection<Document> collector = GetCollection(MongoColl);
      // Get documents by query
      BasicDBObject query = new BasicDBObject();
      query.put(QueryKey, WorkshopId);
      //Get value based on query
      MongoIterable<Document> cursor = collector.find(query);
      //Print first row of data returned
      System.out.println(cursor.first());
      return cursor.first();
      }`


      // Output I get is like below



      `Document{{_id=1514279651131149, configId=1503121975430462, configType=Workshop,  customerSource=Document{{enabled=true, options=[Walk-in, Newspaper Ad, Print Ad, TV Ad, Leaflet]}}, vehicleType=Document{{enabled=true, values=[cars]}}, createdOn=Tue Dec 26 14:44:11 IST 2017, updatedOn=Tue Nov 27 19:11:42 IST 2018}}`


      // function to save data in excel is as below



          public static void setCellData(Document value, int RowNum, int ColNum) throws Exception {
      try {
      row = excelWSheet.getRow(RowNum);
      if (row == null) {
      row = excelWSheet.createRow(RowNum);
      }
      cell = row.getCell(ColNum);
      if (cell == null) {
      cell = row.createCell(ColNum);
      cell.setCellValue(value);
      } else {
      cell.setCellValue(value);
      }
      // Constant variables Test Data path and Test Data file name
      FileOutputStream fileOut = new FileOutputStream(Constant.Path_TestData + Constant.File_TestData);
      excelWBook.write(fileOut);
      fileOut.flush();
      fileOut.close();

      } catch (Exception e) {
      try {
      throw (e);
      } catch (IOException e1) {
      e1.printStackTrace();
      }
      }

      }


      But this gives error:



      "The method setCellValue(double) in the type Cell is not applicable for the arguments (Document)"


      I want to save all the values from config to an excel file. Can anyone suggest how to save this output(document) in Key:value format in excel in different rows?







      java excel mongodb selenium-webdriver






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 18:08









      Vasilis G.

      3,8992924




      3,8992924










      asked Nov 28 '18 at 13:23









      Sonal DalalSonal Dalal

      93312




      93312
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53520463%2fwant-to-save-data-received-from-mongodb-collection-to-excel-using-java-in-seleni%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53520463%2fwant-to-save-data-received-from-mongodb-collection-to-excel-using-java-in-seleni%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks