File tree 3 files changed +19
-0
lines changed
3 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -2363,6 +2363,10 @@ def to_excel(
2363
2363
Once a workbook has been saved it is not possible to write further
2364
2364
data without rewriting the whole workbook.
2365
2365
2366
+ Pandas will check the number of rows, columns,
2367
+ and cell character count does not exceed Excel's limitations.
2368
+ All other limitations must be checked by the user.
2369
+
2366
2370
Examples
2367
2371
--------
2368
2372
Original file line number Diff line number Diff line change @@ -1326,6 +1326,12 @@ def _value_with_fmt(
1326
1326
fmt = "0"
1327
1327
else :
1328
1328
val = str (val )
1329
+ # GH#56954
1330
+ if len (val ) > 32767 :
1331
+ warnings .warn (
1332
+ "String value too long, truncated to 32767 characters" ,
1333
+ UserWarning ,
1334
+ stacklevel = find_stack_level ())
1329
1335
1330
1336
return val , fmt
1331
1337
Original file line number Diff line number Diff line change @@ -1505,3 +1505,12 @@ def test_subclass_attr(klass):
1505
1505
attrs_base = {name for name in dir (ExcelWriter ) if not name .startswith ("_" )}
1506
1506
attrs_klass = {name for name in dir (klass ) if not name .startswith ("_" )}
1507
1507
assert not attrs_base .symmetric_difference (attrs_klass )
1508
+
1509
+
1510
+ def test_to_excel_raising_warning_when_cell_character_exceed_limit ():
1511
+ # GH#56954
1512
+ df = DataFrame ({"A" : ["a" * 32768 ]})
1513
+ msg = "String value too long, truncated to 32767 characters"
1514
+ with tm .assert_produces_warning (UserWarning , match = msg ):
1515
+ buf = BytesIO ()
1516
+ df .to_excel (buf )
You can’t perform that action at this time.
0 commit comments