When you export large text to excel, no more than 8203 characters are exported to an excel cell. I think problem to VBA or win32com.client, if i use openpyxl lib
- export correct.
Error: (-2147352567, 'Ошибка.', (0, None, None, None, 0, -2146827284), None)
I have the problem only in office 2007, export so use 2007 office only.
In office 2016 export is working fine.
import win32com.client
import os
path_excell = 'c:\wa\Excel2.xlsx'
excel = win32com.client.Dispatch("Excel.Application")
if os.path.isfile(path_excell):
wb = excel.Workbooks.Open(path_excell)
else:
wb = excel.Workbooks.add
sheet = wb.ActiveSheet
new_str = '1|2|3|4|5|6|7|8|9'
new_str = new_str.split('|')
k = 8200
i = 1
try:
while k<8400:
s = 'v'*k
new_str[7] = s
sheet.Range(sheet.Cells(i, 1), sheet.Cells(i, 9)).Value = new_str
k += 1
i += 1
except Exception as err:
print(f'Error: {str(err)}: max {k} char')
finally:
if os.path.isfile(path_excell):
wb.Save()
else:
wb.SaveAs(path_excell)
wb.Close()
excel.Quit()