0
Q:

python write to xlsx

# import xlsxwriter module 
import xlsxwriter 
  
workbook = xlsxwriter.Workbook('Example2.xlsx') 
worksheet = workbook.add_worksheet() 
  
# Start from the first cell. 
# Rows and columns are zero indexed. 
row = 0
column = 0
  
content = ["ankit", "rahul", "priya", "harshita", 
                    "sumit", "neeraj", "shivam"] 
  
# iterating through content list 
for item in content : 
  
    # write operation perform 
    worksheet.write(row, column, item) 
  
    # incrementing the value of row by one 
    # with each iteratons. 
    row += 1
      
workbook.close() 
1
# import xlsxwriter module 
import xlsxwriter 
  
# Workbook() takes one, non-optional, argument  
# which is the filename that we want to create. 
workbook = xlsxwriter.Workbook('hello.xlsx') 
  
# The workbook object is then used to add new  
# worksheet via the add_worksheet() method. 
worksheet = workbook.add_worksheet() 
  
# Use the worksheet object to write 
# data via the write() method. 
worksheet.write('A1', 'Hello..') 
worksheet.write('B1', 'Geeks') 
worksheet.write('C1', 'For') 
worksheet.write('D1', 'Geeks') 
  
# Finally, close the Excel file 
# via the close() method. 
workbook.close() 
0
import openpyxl

## initializing the xlsx
xlsx = openpyxl.Workbook()

## creating an active sheet to enter data
sheet = xlsx.active

## creating data to append
data = [
         [1, 2, 3],
         [4, 5, 6],
         [7, 8, 9],
         [10, 11, 12]
       ]

## appending row by row to the sheet
for row in data:
    ## append method is used to append the data to a cell
    sheet.append(row)

## saving the xlsx file using 'save' method
xlsx.save('appending.xlsx')
0

New to Communities?

Join the community