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, 2020 in Java by Jyra
• 580 points
4,617 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,920 points
1,104 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,620 points
1,540 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, 2020 in Java by Niroj
• 82,840 points
1,131 views
0 votes
2 answers

I want list of date of every week based on pass dynamically "Mon ,Tue, Wed, Thu, Fri, Sat, Sun" between startDate and endDate using Java 8 LocaleDate

public List<LocalDate> getWeeklyDateByStringofDays(String daysOfWeek, LocalDate startDate, ...READ MORE

answered Sep 14, 2020 in Java by anonymous
• 190 points
1,467 views
0 votes
0 answers

How to filter object array based on attributes?

The real estate house objects in my ...READ MORE

Sep 28, 2022 in Java by Nicholas
• 7,760 points
687 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,920 points
2,271 views
+5 votes
4 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,450 points

edited Nov 7, 2018 by Omkar 81,223 views
+1 vote
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,500 points
8,359 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,500 points
17,433 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,500 points

edited Aug 4, 2023 by Khan Sarfaraz 4,876 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP