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
965 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
204 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,640 points
654 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,680 points
125 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
188 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
316 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,110 points
264 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 6, 2018 by Omkar 40,797 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,520 points
5,291 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,520 points
11,784 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,520 points
2,269 views