Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

create a drop down list in excel using python

I'd like to create a simple drop down list in excel using python, that contains :

  • the first cell alow me to filter by year :2020 2021 2022 ..2024
  • the second cell allow me to filter by month : 1 2 3 ...12

this is my code :

import pandas as pd
import numpy as np

from openpyxl.worksheet.datavalidation import DataValidation
from openpyxl import Workbook
import xlsxwriter

wb = Workbook()
ws = wb.create_sheet('list')
wss = wb.create_sheet('year')

for number in range(1,9): #Generates 10 "date" year in the Column A;
  ws['A{}'.format(number)].value= "202{}".format(number)

data_val = DataValidation(type="list",formula1='=$A:$A') 
ws.add_data_validation(data_val)

data_val.add(wss["B1"]) # drop down list with all the values 

wb.save('date.xlsx')

I don't know how to complete this code , I want to have in sheet 'list ' all the years from 2020 until 2040, and in sheet 'year' to have the drop down list

thank you in advance for your help!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...