Last active
November 7, 2024 19:57
-
-
Save horvatha/0ac42748ad91118a8cf0dd7b7bb88934 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from openpyxl import Workbook | |
text = "" # Including three bytes: hexadecimal FFBFBF resulting ValueError | |
# text = '\x16' # resulting IllegalCharacterError | |
wb = Workbook() | |
ws = wb.active | |
ws.append([text]) | |
wb.save("test.xlsx") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""FFBFBF 3 bytes in text prevents excel to be saved""" | |
from io import BytesIO | |
import platform | |
import sys | |
import pandas as pd | |
print(pd.__version__) | |
print(platform.platform()) | |
print(sys.version) | |
""" | |
pandas version: 1.5.3 | |
Windows-10-10.0.22631-SP0 | |
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] | |
and | |
openpyxl 3.1.2 | |
pandas 2.2.1 | |
Linux-6.11.5-200.fc40.x86_64-x86_64-with-glibc2.39 (Fedora) | |
Python 3.12.7 (main, Oct 1 2024, 00:00:00) [GCC 14.2.1 20240912 (Red Hat 14.2.1-3)] | |
""" | |
df = pd.DataFrame(data=dict(a=["text 1", "text2"])) | |
output = BytesIO() | |
writer = pd.ExcelWriter(output, engine='openpyxl') | |
df.to_excel(writer, index=False, sheet_name="first_sheet") | |
writer.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment