Home > other >  One man openpyxl ranks to excel realize conversion?
One man openpyxl ranks to excel realize conversion?

Time:11-23

One man openpyxl ranks to excel realize conversion? The question why openpyxl implementing old error, can anyone help to write a? I am the first load_workbook () to create a Workbook object, built a sheet object, read the data, then Workbook () an object, establish a sheet object, read, everything goes well, but the final step, the second Workbook object when using the save method is an error,

An error, as follows:
Traceback (the most recent call last) :
The File "C: \ Users \ Administrator \ PycharmProjects \ test \ SC - 201901230905 venv \ lib \ site - packages \ openpyxl \ utils \ cell py", line 110, in get_column_letter
Return _STRING_COL_CACHE [independence idx]
KeyError: 23758

During handling of the above exception, another exception occurred:

Traceback (the most recent call last) :
The File "C:/Users/Administrator. SC - 201901230905/PycharmProjects/test/test. Py", line 33, in & lt; module>
Wb2. Save (' tt. XLSX)
The File "C: \ Users \ Administrator \ PycharmProjects \ test \ SC - 201901230905 venv \ lib \ site - packages \ openpyxl \ workbook \ workbook py", line 392, in the save
Save_workbook (self, filename)
The File "C: \ Users \ Administrator \ PycharmProjects \ test \ SC - 201901230905 venv \ lib \ site - packages \ openpyxl \ writer \ excel py", line 293, in save_workbook
Writer. The save ()
The File "C: \ Users \ Administrator \ PycharmProjects \ test \ SC - 201901230905 venv \ lib \ site - packages \ openpyxl \ writer \ excel py", line 275, in the save
Self. Write_data ()
The File "C: \ Users \ Administrator \ PycharmProjects \ test \ SC - 201901230905 venv \ lib \ site - packages \ openpyxl \ writer \ excel py", line 75, in write_data
Self. _write_worksheets ()
The File "C: \ Users \ Administrator \ PycharmProjects \ test \ SC - 201901230905 venv \ lib \ site - packages \ openpyxl \ writer \ excel py", line 215, in _write_worksheets
Self. Write_worksheet (ws)
The File "C: \ Users \ Administrator \ PycharmProjects \ test \ SC - 201901230905 venv \ lib \ site - packages \ openpyxl \ writer \ excel py", line 200, in write_worksheet
Writer. Write ()
The File "C: \ Users \ Administrator \ PycharmProjects \ test \ SC - 201901230905 venv \ lib \ site - packages \ openpyxl \ worksheet \ _writer py", line 357, in the write
Self. Write_top ()
The File "C: \ Users \ Administrator \ PycharmProjects \ test \ SC - 201901230905 venv \ lib \ site - packages \ openpyxl \ worksheet \ _writer py", line 99, in write_top
Self. Write_dimensions ()
The File "C: \ Users \ Administrator \ PycharmProjects \ test \ SC - 201901230905 venv \ lib \ site - packages \ openpyxl \ worksheet \ _writer py", line 69, in write_dimensions
Dim=SheetDimension (ref ())
The File "C: \ Users \ Administrator \ PycharmProjects \ test \ SC - 201901230905 venv \ lib \ site - packages \ openpyxl \ worksheet \ worksheet py", line 396, in calculate_dimension
Return f "{get_column_letter (min_col)} {min_row}, {get_column_letter (max_col)} {max_row}"
The File "C: \ Users \ Administrator \ PycharmProjects \ test \ SC - 201901230905 venv \ lib \ site - packages \ openpyxl \ utils \ cell py", line 112, in get_column_letter
Raise ValueError (" Invalid column index {0} ". The format (independence idx))
ValueError: Invalid column index 23758
The Error in atexit. _run_exitfuncs:
Traceback (the most recent call last) :
The File "C: \ Users \ Administrator \ PycharmProjects \ test \ SC - 201901230905 venv \ lib \ site - packages \ openpyxl \ worksheet \ _writer py", line 32, in _openpyxl_shutdown
OS. Remove (path)
PermissionError: [32] WinError another program is using this file, the process cannot access the: 'C: \ \ Users \ \ ADMINI ~ 1. SC - \ \ AppData \ \ Local \ \ Temp \ \ openpyxl 2 zfq0dk0'

CodePudding user response:

Code is as follows: the question that the error, logic thought do not have what problem!
The import openpyxl, OS, sys
OS. The chdir (r 'C: \ Users \ Administrator \ Desktop' SC - 201901230905)
Wb=openpyxl. Load_workbook (' 110. XLSX, data_only=False)
Wb2=openpyxl. Workbook ()
Sheet=wb. Active
Sheet2=sheet. Active_cell

# read data from the original table
SheetDate=[]
Rows=sheet. Rows
Rows=[x for x in rows]
For k in range (len (rows) :
SheetDate_row=[]
In the range for v (len (rows [0])) :
SheetDate_row. Append (sheet) cell (row=k + 1, column=v + 1). The value)
SheetDate. Append (sheetDate_row)

# transformation, and the data have the anewData
AnewData []=https://bbs.csdn.net/topics/
For k in range (len (sheetDate [0])) :
AnewData_row=[]
In the range for v (len (sheetDate)) :
AnewData_row. Append (sheetDate [v] [k])
AnewData. Append (anewData_row)

# from the list of data written to the sheet2
For k in range (len (anewData) :
In the range for v (len (anewData [0])) :
Sheet2. Cell (row=k + 1, column=v + 1). The value=https://bbs.csdn.net/topics/anewData [k] [v]


Wb. Save (' tt. XLSX) # is obviously the line error

CodePudding user response:

Your new file wb2, isn't it?
Why keep a wb again?

In addition, the end of the program to be
Wb2. Close ()
Wb. Close ()
Otherwise may cause the excel instance in memory is more and more,

CodePudding user response:

Code should be this,
The import openpyxl, OS, sys
OS. The chdir (r 'C: \ Users \ Administrator \ Desktop' SC - 201901230905)
Wb=openpyxl. Load_workbook (' 110. XLSX, data_only=False)
Wb2=openpyxl. Workbook ()
Sheet=wb. Active
Sheet2=wb2. Active

# read data from the original table
SheetDate=[]
Rows=sheet. Rows
Rows=[x for x in rows]
For k in range (len (rows) :
SheetDate_row=[]
In the range for v (len (rows [0])) :
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related