# Python Excel (OpenPyXL) * ### Download by PIP ```Python= pip install openpyxl ``` * ### Change Directory ```Python= import os os.chdir("The Folder's Location You Kept") ``` * ### Open Excel ```Python= wb = openpyxl.load_workbook('file.xlsx') ``` * ### Create New Sheet ```Python= wb.create_sheet(title='Sheet's Title,index=1) ``` * ### Show Sheets' Name ```Python= wb.get_sheet_names() ``` * ### Get Sheet & Change Sheet Name ```Python= sheet = wb.geet_sheet_by_name('Shee1') sheet.title = "New Sheet Name" ``` * ### Simple Grab Data ```Python= sheet['LOCATION(A1)'].value ## Supposingly number in 72 sheet.cell(row=1,column=3).value ``` * ### Change Data Value ```Python= sheet['LOCATION(A1)'].value = 42 ``` * ### Save File ```Python= wb.save('file2.xlsx') ``` Note: A file's name is suggesting to save in different name because it will occur in overlap. It also help to find out the error when we debug. * ### Check Max Column(Row) ```Python= sheet.max_row sheet.max_column ``` * ### Get Column's Cell Letter ```Python= openpysl.cell.get_coloumn_letter(1) # return 'A' openpyxl.cell.column_index_from_string('A') # return 1 ``` Note: We usually use it when we want to check the column row letter. * ### Adjust Column Width & Raw Height ```Python= sheet.column_dimensions['B'].width = 20 sheet.raw_dimensions[1].height = 70 ``` * ### Change Font Style ```Python= from openpyxl.styles import Font sheet['B1'].font = Font(sz = 14,bold = True,italic = True) ```