.xlsxusing xlrd and openpyxl.
.mhtfiles containing tables or excel contents to
.xlsxusing beautifulsoup4 and openpyxl.
We attempt to support anything that the underlying packages used will support. For example, the following are supported for both input types:
- Multiple worksheets
- Text, Numbers, Dates/Times, Unicode
- Fonts, text color, bold, italic, underline, double underline, strikeout
- Solid and Pattern Fills with color
- Borders: Solid, Hair, Thin, Thick, Double, Dashed, Dotted; with color
- Alignment: Horizontal, Vertical, Rotated, Indent, Shrink To Fit
- Number Formats, including unicode currency symbols
- Hidden Rows and Columns
- Merged Cells
- Hyperlinks (only 1 per cell)
These features are additionally supported by the
.xls input format:
- Freeze panes
These features are additional supported by the
.mht input formats:
Not supported by either format:
- Conditional Formatting (the current stylings are preserved)
- Formulas (the calculated values are preserved)
- Charts (the image of the chart is handled by
- Pivot tables (the current data is preserved)
- Text boxes (converted to an image by
- Shapes and Clip Art (converted to an image by
- Autofilter (the current filtered out rows are preserved)
- Rich text in cells (openpyxl doesn’t support this: only styles applied to the entire cell are preserved)
To install xls2xlsx, run this command in your terminal:
$ pip install xls2xlsx
This is the preferred method to install xls2xlsx, as it will always install the most recent stable release.
To use xls2xlsx from the command line:
$ xls2xlsx [-v] file.xls ...
This will create
file.xlsx in the current folder.
file.xls can be any
.mht file and can also be a URL. The
-v flag will print the input and output filename.
To use xls2xlsx in a project:
from xls2xlsx import XLS2XLSX x2x = XLS2XLSX("spreadsheet.xls") x2x.to_xlsx("spreadsheet.xlsx")
from xls2xlsx import XLS2XLSX x2x = XLS2XLSX("spreadsheet.xls") wb = x2x.to_xlsx()
The xls2xlsx.to_xlsx method returns the filename given. If no filename is provided, the method returns the openpyxl workbook.
The input file can be in any of the following formats:
- Excel 97-2003 workbook (
- Web page (
.html), optionally including a _Files folder
- Single file web page (
The input specified can also be any of the following:
- A filename / pathname
- A url
- A file-like object (opened in Binary mode for
.xlsand either Binary or Text mode otherwise)
- The contents of a
.xlsfile as a
- The contents of a
.mhtfile as a
Note: The file format is determined by examining the file contents, not by looking at the file extension.
STATS ON GITHUB
- License: MIT
- Author: Joe Cool
- Last update: N/A