Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert column using openpyxl

I'm working on a script that modifies an existing excel document and I need to have the ability to insert a column between two other columns like the VBA macro command .EntireColumn.Insert.

Is there any method with openpyxl to insert a column like this?
If not, any advice on writing one?

like image 345
Shawn Avatar asked Apr 05 '13 05:04

Shawn


1 Answers

Here is an example of a much much faster way:

import openpyxl

wb = openpyxl.load_workbook(filename)
sheet = wb.worksheets[0]
# this statement inserts a column before column 2
sheet.insert_cols(2)
wb.save("filename.xlsx")
like image 169
Naghmeh Avatar answered Oct 07 '22 17:10

Naghmeh