How to convert an Excel file to Base64
- Drop an
.xlsx,.xlsor.csvfile on the box, or pick it with the file picker. - Output as starts on Plain Base64. Choose JSON to include the file name, MIME type and size.
- Copy output, or Save as .txt for large workbooks.
Which spreadsheet is it?
| File | Base64 starts with | MIME type |
|---|---|---|
.xlsx, .xlsm | UEsDB (ZIP) | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
.xls | 0M8R4KGxGuE (OLE2) | application/vnd.ms-excel |
password-protected .xlsx | 0M8R4KGxGuE | same as .xlsx |
.csv, UTF-8 with BOM | 77u/ | text/csv |
.csv, no BOM | the text itself, e.g. bmFtZSxxdHkK for name,qty and a newline | text/csv |
The data URI and JSON outputs use the type your browser reports. On Windows computers with Excel installed, the system often labels .csv files as application/vnd.ms-excel. If an API is strict about CSV, change the type to text/csv by hand.
CSV is just text
A CSV file is plain text, so its Base64 decodes to readable rows. That has a few consequences:
- The character encoding travels with the bytes. A CSV saved by Excel in a legacy code page, such as Windows-1252, decodes to wrong characters if the receiver assumes UTF-8. Prefer “CSV UTF-8” when saving.
- A large CSV shrinks a lot with gzip or ZIP, which is worth doing before encoding if the API accepts compressed uploads. An
.xlsxis already a ZIP, so compressing it again saves almost nothing. - For a quick look at a CSV you received as Base64, Base64 to CSV decodes and shows it as text.
Where spreadsheets travel as Base64
- Report and import APIs that accept a workbook in a JSON body, for example for bulk product or price imports.
- Automation platforms that pass files between steps as Base64 strings, such as reading an email attachment and uploading it to storage.
- Email-sending APIs, where a spreadsheet attachment goes into a JSON field as Base64.
- Download links in generated HTML, using the HTML
<a download>output, so a report page can carry its own.xlsx.
Encode and check the format in Python
import base64
from pathlib import Path
SIGNATURES = {
"UEsDB": "xlsx (ZIP)",
"0M8R4KGxGuE": "xls (OLE2) or encrypted xlsx",
"77u/": "text with a UTF-8 BOM, e.g. CSV UTF-8",
}
def encode_sheet(path):
b64 = base64.b64encode(Path(path).read_bytes()).decode("ascii")
kind = next((v for k, v in SIGNATURES.items() if b64.startswith(k)), "other")
return b64, kind
A check like this catches a common upload error: a “spreadsheet” that is really an HTML error page or an old .xls renamed to .xlsx. More on files in Base64 in Python, and Base64 to Excel previews a Base64 workbook and saves it as a file.
FAQ
What is the MIME type of an XLSX file?
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet. The legacy .xls format uses application/vnd.ms-excel, and CSV is text/csv.
Why does my CSV Base64 start with 77u/?
77u/ is the UTF-8 byte-order mark (EF BB BF). Excel adds it when you save as “CSV UTF-8”. Most parsers handle it, but some treat it as part of the first column name, so strip it if a header like name stops matching.
Can I send an Excel file in a JSON request?
Yes. Encode it as plain Base64 and put it in the file content field your API documents, with the file name and MIME type. The JSON output shows the shape: name, type, size and data.