Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

convert xls to xlsx python

use "pip install xls2xlsx"
Comment

save to xlsx in python

import pandas as pd
df = pd.read_excel()

>>> df
      User Name Country      City Gender  Age
0  Forrest Gump     USA  New York      M   50
1     Mary Jane  CANADA   Tornoto      F   30
2  Harry Porter      UK    London      M   20
3     Jean Grey   CHINA  Shanghai      F   30


df.to_excel('saved_file.xlsx')
Comment

openpyxl xls - Create xlsx work sheet, write data to it, save xlsx file

from openpyxl import Workbook

workbook = Workbook()

# create xls workbook sheet
workbook.create_sheet(index=0, title='Sheet1')
workbook.create_sheet(index=0, title='Sheet2')

# remove xls workbook sheet
workbook.remove(workbook['Sheet2'])

# get active work sheet
work_sheet = workbook.active

data = [
    ['Naveen', 'M', 'Software Engineer'],
    ['David', 'N', 'Designer'],
    ['Shera', 'H', 'Web Developer']
]

rows = 3
cols = 3
# iterate to set data
for row_num in range(0, rows):
    for col_num in range (0, cols):
        work_sheet.cell(
            row=row_num + 1,
            column=col_num + 1
        ).value = data[row_num][col_num]

# save data to xls file
workbook.save('output.xlsx')
Comment

PREVIOUS NEXT
Code Example
Python :: access myultiple dict values with list pythojn 
Python :: list length in python 
Python :: gaussian filter 
Python :: connect mongodb with python 
Python :: pandas check if any of the values in one column exist in another 
Python :: tkinter change button state 
Python :: python machine learning scale 
Python :: is vs == python 
Python :: select rows in python 
Python :: Publish Image msg ros python 
Python :: py2exe no console 
Python :: numpy where 
Python :: opencv load image python 
Python :: numpy transpose 
Python :: python loop shorthand 
Python :: basic flask app 
Python :: django rest framework viewset perform_update 
Python :: Python Add a string in a certain position 
Python :: wxpython icon 
Python :: length of int in python 
Python :: plotting in python 
Python :: deep clone 2d list python 
Python :: # read the JSON file and also print the file content in JSON format. 
Python :: how does HTTPServer work in python 
Python :: how to install os module in python 
Python :: creating new virtual environment in python 
Python :: python change audio output device 
Python :: selenium python has no attrirute getText 
Python :: get method in python 
Python :: permutation python 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =