create multiple excel sheets.xlsx based on each iteration

0 votes

Prob : I have a method executeunixcommand that returns filename, the executionresults(ist iteration of that method), the unixcommandresult(ist iteration of that method). Once i get all the three values i(flename, executionresults,unixcommandresult) I want to create the excel workbook(xlsx) and create a sheet with some name+count (like unix1) and add data to that sheet. below is the method for the same.

once it completes adding the data for the first iteraton in sheet1(unix1), it will go back to the method and do the second iteration, bring the three result variables(filename,executionresults,unixcommandresult) and open the sheet and add the data in the second sheet of excel.

COuld you please tell me whats wrong in this code.



public int writeresultstoexcel(string filename, AttayList<String> executionresults, ArrayList<String> unixcommandresult)
{
File parsedfile = new File(fileName);
int count=0;
if(parsedfile.exists())
{
count=count++;
XSSFSheet resultsheetname = createSheet("FID- " +count);
}
else{
createexcel(filename);
XSSFSheet resultsheetname = createSheet("FID- " +count);
}
}
Jul 14 in Java by Jyra
• 510 points
51 views

Hi. @Jyra,

Are you facing any kind of error while executing your code snippet?

Sorry. I m not getting any error Gitika. This is not creating the excel sheet as required. I get the message that excel file already existis and it doesnot go beyond that. please let me know if I am missing any info.  I am first converting the filename which is of string type to file type to check if the file exists or not in that particular path

Hi, @Jyra,

You can write to multiple sheets with the xlsx package. You just need to use a different sheetName for each data frame and you need to add append=TRUE:

library(xlsx)
write.xlsx(dataframe1, file="filename.xlsx", sheetName="sheet1", row.names=FALSE)
write.xlsx(dataframe2, file="filename.xlsx", sheetName="sheet2", append=TRUE, row.names=FALSE)

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Java

0 votes
2 answers

Performing Iteration over each entry in a 'Map'

In Java 8 you can do it ...READ MORE

answered Oct 24, 2018 in Java by Sushmita
• 6,890 points
124 views
0 votes
1 answer

How to read and write on an excel files?

Follow these steps: Write: public class User { ...READ MORE

answered May 15, 2018 in Java by Rishabh
• 3,580 points
466 views
0 votes
1 answer

Get sub-string from text based on certain conditions/rules

Hello @laiman, You can use IsMatch function that tests whether ...READ MORE

answered Jul 28 in Java by Niroj
• 44,800 points
38 views
+4 votes
3 answers

What are the steps to set Java_home on Windows?

Set Java Home JAVA_HOME = C:\Program Files\Java\jdk1.7.0 [Location ...READ MORE

answered Sep 18, 2018 in Java by Sushmita
• 6,890 points
219 views
0 votes
2 answers

How to create a 2-D array in java?

int[][] multi = new int[5][]; multi[0] = new ...READ MORE

answered Jul 16, 2018 in Java by Daisy
• 8,090 points
140 views
0 votes
2 answers

How can I create File and write data in it using Java?

import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFiles{ ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,190 points
260 views
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,420 points

edited Nov 6, 2018 by Omkar 27,010 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,510 points
3,997 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,510 points
9,557 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,510 points
1,726 views