I am aware of using
in2csv to save a particular worksheet as a .csv:
in2csv --sheet "sheet name" file1.xls > sheet-name.csv
But are there any other tools to just print the sheetnames?
Perhaps there are options with Perl?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
in2csv from the
csvkit package provides the
-n option for that: [Source]
-n, --names Display sheet names from the input Excel file.
In your example the command would be:
in2csv -n file1.xls
This feature was added in
csvkit 1.0.2, which is not available from the official package sources for releases older than Bionic. If you’re running Xenial you need to either
install it via
sudo pip install csvkit
to get the latest version.
in2csv is the simpler option, but I'll leave this in case somebody might find it useful. There's a nice command called
xlhtml for converting XLS files to HTML or XML. And once you have the XML, various XML processing tools can be used to do a wide variety of queries on it. In this case:
$ xlhtml -xml ~/foo.xls | xmlstarlet sel -t -m '//pagetitle' -v . -n Sheet1 Sheet2
The XML that
xlhtml generates is like so:
<?xml version="1.0" encoding="iso-8859-1" ?> <excel_workbook> <sheets> <sheet> <page>0</page> <pagetitle>Sheet1</pagetitle> <firstrow>0</firstrow> <lastrow>11</lastrow> <firstcol>0</firstcol> <lastcol>0</lastcol>
So, for the sheet names, we can query the
pagetitle nodes, for which I used