How to mention individual sheet names while writing mutiple org.apache.spark.sql.Dataset into an .xls file using crealytics / spark-excel in java?

1 answer

I am trying to write different Java Datasets into an excel file which will contain multiple sheets inside it using crealytics/spark-excel library.

<dependency>             <groupId>com.crealytics</groupId>             <artifactId>spark-excel_2.11</artifactId>             <version>0.13.0</version> </dependency> 

How do I provide a name for those individual excel sheets?

Here's what I am trying to do:

import org.apache.spark.api.java.JavaRDD;  SparkSession spark = SparkSession.builder().appName("LineQuery").getOrCreate();  Dataset<Row> df1 = spark.sql("SELECT * FROM my_table1"); Dataset<Row> df2 = spark.sql("SELECT * FROM my_table2");  df1.write().format("com.crealytics.spark.excel").option("sheetName","My Sheet 1").option("header", "true").save("hdfs://127.0.0.1:9000/var/www/" + outFile + ".xls");  df2.write().format("com.crealytics.spark.excel").option("sheetName","My Sheet 2").option("header", "true").mode(SaveMode.Append).save("hdfs://127.0.0.1:9000/var/www/" + outFile + ".xls"); 

All answers to this question, which has the identifier 60500266

The best answer:

Use dataAddress option instead

Example:

>>> df = spark.createDataFrame([(11, 12), (21, 22)]) >>> df.show() +---+---+ | _1| _2| +---+---+ | 11| 12| | 21| 22| +---+---+ >>> df.where("_1 == 11").write.format("com.crealytics.spark.excel").option("dataAddress", "my sheet 1[#All]").option("header", "true").mode("append").save("/tmp/excel-df.xlsx") >>> df.where("_1 == 21").write.format("com.crealytics.spark.excel").option("dataAddress", "my sheet 2[#All]").option("header", "true").mode("append").save("/tmp/excel-df.xlsx") 

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data