Frag Me Nation
Frag Me Nation
Frag Me Nation
import zipfile
import zipfile
3) Write a Python program to create a ZIP file and add the files to it
import zipfile
4) Write a Python program using shutil library functions to: Copying Files and
import shutil
ii)
# Move a file or folder
shutil.move("source.txt", "new_location.txt")
# Rename a file
shutil.move("old_name.txt", "new_name.txt")
5) Explain the process of getting sheets from the workbook with suitable
example.
wb = load_workbook("example.xlsx")
print("Sheets:", wb.sheetnames)
sheet = wb["Sheet1"]
Explanation:
6) Explain the process of reading cell values from the sheets with suitable examples
wb = load_workbook("example.xlsx")
sheet = wb["Sheet1"]
Explanation:
9) Write a Python program to create an excel file with the name demo.xlsx, write
the statement ‘Hello World’ in the cell B3, change the font style to ‘Cambria’,
size to 20, color to ‘Red’ andmake the statement bold and underline.
wb = Workbook()
sheet = wb.active
# Write to cell B3
cell = sheet["B3"]
wb.save("demo.xlsx")
spreadsheet.
wb = Workbook()
sheet = wb.active
sheet["A1"] = 10
sheet["A2"] = 20
sheet["A3"] = "=SUM(A1:A2)"
wb.save("sum_demo.xlsx")
spreadsheet
wb = Workbook()
sheet = wb.active
sheet["B1"] = 10
sheet["B2"] = 20
sheet["B3"] = "=AVERAGE(B1:B2)"
wb.save("average_demo.xlsx")
12) Write a Python program to set Row Height and Column Width in Excel
Spreadsheet.
wb = Workbook()
sheet = wb.active
sheet.row_dimensions[1].height = 30
sheet.column_dimensions["A"].width = 20
wb.save("dimensions_demo.xlsx")
13) Write a Python program to demonstrate merging and unmerging cells in Excel
spreadsheet.
wb = Workbook()
sheet = wb.active
# Merge cells
sheet.merge_cells("A1:C3")
# Unmerge cells
sheet.unmerge_cells("A1:C3")
wb.save("merge_demo.xlsx")
wb = Workbook()
sheet = wb.active
# Add data
data = [("Category", "Value"), ("A", 10), ("B", 20), ("C", 30)]
sheet.append(row)
# Create chart
chart = BarChart()
chart.add_data(data_ref, titles_from_data=True)
sheet.add_chart(chart, "E5")
wb.save("chart_demo.xlsx")
15) How can you retrieve a tuple of all the Cell Objects (Getting Rows and
wb = load_workbook("example.xlsx")
sheet = wb.active
cells = tuple(sheet["A1:F1"])