Comments (14)
@qfjp in principle, something like the following could work, but unfortunately there is a problem wrt. shading:
import com.crealytics.spark.excel._
val wbr = WorkbookReader(Map("path" -> "/path/to/file.xlsx"), spark.sparkContext.hadoopConfiguration)
// wbr: com.crealytics.spark.excel.WorkbookReader = com.crealytics.spark.excel.DefaultWorkbookReader@53ce41e7
wbr.withWorkbook(w => w.getSheetAt(0))
// java.lang.ClassCastException: class shadeio.poi.xssf.usermodel.XSSFWorkbook cannot be cast to class org.apache.poi.ss.usermodel.Workbook (shadeio.poi.xssf.usermodel.XSSFWorkbook and org.apache.poi.ss.usermodel.Workbook are in unnamed module of loader scala.reflect.internal.util.ScalaClassLoader$URLClassLoader @6d4c7248)
// at $anonfun$1.apply(<console>:29)
// at com.crealytics.spark.excel.WorkbookReader$class.withWorkbook(WorkbookReader.scala:15)
// at com.crealytics.spark.excel.DefaultWorkbookReader.withWorkbook(WorkbookReader.scala:38)
// ... 51 elided
If you can figure out how to solve the shading problem, that would be the way to go.
One possibility would be to create a def sheetNames: Seq[String]
on WorkbookReader
.
That should hopefully work as it doesn't expose any shaded classes.
We're open to PRs 😄
from spark-excel.
Hi @antonkulaga,
would you want to retrieve this as a special DataFrame like this?
val df = sqlContext.read
.format("com.crealytics.spark.excel")
.option("sheetName", "SHEET_NAMES")
.load("Worktime.xlsx")
Or just a simple helper function like
ExcelRelation.sheetNames("Worktime.xlsx")
Would you mind giving this a try yourself?
from spark-excel.
@nightscape either way is ok for me. I think just RDD[String] or even Seq[String] will be enough
from spark-excel.
I'm slightly leaning toward the Seq[String]
version.
Do you wanna give it a try?
from spark-excel.
Yes, of course
from spark-excel.
@antonkulaga are you still interested in this?
from spark-excel.
@nightscape it is nice to have but it is not of any urgency for me
from spark-excel.
Ok, then I'll close this for the time being.
from spark-excel.
Has there been any work in this direction in the intervening time? If not, I would still be interested in such a feature.
from spark-excel.
You can always use a different library to get the sheet names. If you're using python, you can use xlrd. It looks fairly straightforward:
import xlrd
xls = xlrd.open_workbook(r'<path_to_your_excel_file>', on_demand=True)
print xls.sheet_names()
from spark-excel.
Unfortunately python isn't really an option, and I would prefer not to mix libraries if I already have one for xlsx. Thanks for the advice though, it might come in handy in the future.
from spark-excel.
OK. So would you prefer (1) to the sheetnames as a dataframe or (2) a helper function that returns a list of the sheetnames?
from spark-excel.
@luzlab I don't think I'm ever going to be working with enough sheets to need it as a DataFrame, but it still might be worth it just for consistency's sake?
@nightscape Thanks for the advice, I may take a look at the code later and submit something.
from spark-excel.
from spark-excel.
Related Issues (20)
- [BUG] Old excel files are not supported. HOT 1
- [BUG] <title>Spark Excel reads all Excel files under the file HOT 3
- [BUG] spark-excel library not working as a workspace library HOT 2
- New Case on Large Number Being Captured As Scientific Notation
- [BUG] last Columns with first line value empty not being read from .xlsx HOT 3
- support spark 3.5 HOT 3
- Incorrect Data Frame creation HOT 1
- [BUG] ClassNotFoundException for 'excel.DefaultSource' while using API V2 HOT 13
- Mentioned jar for scala 2.12 does not exist HOT 2
- [BUG] <infer schema should not include the auto generated columns>
- [BUG] Spark Excel is Incompatible with AWS EMR v6.13 and higher HOT 2
- [BUG] ClassCastException: scala.Some cannot be cast to [Lorg.apache.spark.sql.catalyst.InternalRow HOT 6
- [BUG] Incorrect date formatting if I indicate sheet Spark Read Excel HOT 1
- [BUG] Excel File with Macros Detected as "Potentially" Malicious. Unable to read Excel as a result. HOT 1
- [BUG] When Read Excel Files, Several Errors Using Java HOT 2
- Error Handling for Corrupt Files in Chunk Processing HOT 1
- [BUG] No thrown exception if schema is provieded, but there is no workbook/sheet (PDF with XLSX Extension)
- [FEATURE] Optimize JAR size HOT 2
- [BUG] Cannot read files into dataframe in Databricks 13.3 LTS Runtime 3.3.0 Spark HOT 3
- Extract sheet names using pyspark HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spark-excel.