Extract Excel Columns

Posted by John Liu on Friday, August 15, 2025

You might want to grab all columns from all worksheets in an Excel. This simple Python script will help to do that.

# pip install pandas openpyxl

import pandas as pd

# Path to your Excel file
excel_file = "your excel file.xlsx"

# Read the Excel file
xls = pd.ExcelFile(excel_file)

# Initialize an empty list to store tuples
sheet_column_pairs = []

# Loop through each sheet and get column names
for sheet_name in xls.sheet_names:
    df = pd.read_excel(xls, sheet_name=sheet_name)
    for col in df.columns:
        sheet_column_pairs.append((sheet_name, str(col)))

# Print in desired format
for pair in sheet_column_pairs:
    print(f",{pair}")