简体   繁体   中英

How to insert column to excel file using python?

How to insert column to excel file using python? please some help me

import xlrd
import pyexcel


l=[]
s=["heading 1","heading 2","heading 3","heading 4"]
l.append(s)
string_1 = [["column 1.1"],["column 1.2"]]
string_2 = [["column 2.1"],["column 2.2"]]
string_3 = [["column 3.1"],["column 3.2"]]
string_4 = [["column 4.1"],["column 4.2"]]
for i in string_1:
   print(i)
   l.append(i)
for j in string_2:
   print(j)
   l.append(j)
for k in string_3:
   print(k)
   l.append(k)
for v in string_4:
   print(v)
   l.append(v)
s = pyexcel.save_as(array=l, dest_file_name="aarray_data.xlsx")

Expected Output

 heading 1   heading 2   heading 3    heading 4
 column 1.1  column 2.1  column 3.1  column 4.1
 column 1.2  column 2.2  column 3.2  column 4.2

check this

import xlrd
import pyexcel


l=[]
s=["heading 1","heading 2","heading 3","heading 4"]
l.append(s)
string_1 = [["column 1.1","column 1.2", "column 2.1","column 2.2"], ["column 3.1","column 3.2","column 4.1","column 4.2"]]
for i in string_1:
   print(i)
   l.append(i)

print(l)
s = pyexcel.save_as(array=l, dest_file_name="aarray_data.xlsx")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM