OpenPyXL: Is it possible to create a dropdown menu in an excel sheet?











up vote
1
down vote

favorite












I'm attempting to store a list of valid ip addresses in a cell using openpyxl. At the moment the data is simply placed into a cell, and usually overflows into other cells. Using the code below:



# Regex to return a tidy list of ip addresses in that block
"""
r = row to be checked
s = source or destination columns
iptc = ips to check
"""

def regex_ips(r, s):
iptc = ['165.11.14.20', '166.22.24.0/24', '174.68.19.11', '165.211.20.0/23']
if r is not None:
if s is not None:
iptc = str(sheet.cell(r, s).value)
san = re.sub('n', ', ', iptc)
sheet_report.cell(r, 8).value = san


However, I would prefer if i could place these ip addresses into a dropdown list since that would be far easier to read - so my question is twofold, first, can this be done? because I couldn't find any info about it, And secondly, is there possibly a better way to display the data without it overflowing?



Thanks for reading over this



EDIT: added some example addresses and subnets to reflect what may be in a list.










share|improve this question
























  • "Drop Down" lists can be done fairly easy with openpyxl, so called "data validation" in Excel, can you provide the contents of iptc,or a list of some examples ips, or how are they store.
    – HaR
    Jul 24 at 13:56












  • Also how many ip address do you have in the list?
    – HaR
    Jul 24 at 14:04










  • The list can vary in size, usually no more than maybe 40 addresses total, and they are being stored in a list - ill update the example to reflect this with some pseudo examples
    – Connor J
    Jul 24 at 14:23










  • Also you have to store your ip addresses into separate strings like this : iptc = ["165.11.14.20", "166.22.24.0/24", "174.68.19.11", "165.211.20.0/23"]
    – HaR
    Jul 24 at 14:56












  • @HaR Thanks for pointing that out - just updated the example to reflect that
    – Connor J
    Jul 25 at 9:06















up vote
1
down vote

favorite












I'm attempting to store a list of valid ip addresses in a cell using openpyxl. At the moment the data is simply placed into a cell, and usually overflows into other cells. Using the code below:



# Regex to return a tidy list of ip addresses in that block
"""
r = row to be checked
s = source or destination columns
iptc = ips to check
"""

def regex_ips(r, s):
iptc = ['165.11.14.20', '166.22.24.0/24', '174.68.19.11', '165.211.20.0/23']
if r is not None:
if s is not None:
iptc = str(sheet.cell(r, s).value)
san = re.sub('n', ', ', iptc)
sheet_report.cell(r, 8).value = san


However, I would prefer if i could place these ip addresses into a dropdown list since that would be far easier to read - so my question is twofold, first, can this be done? because I couldn't find any info about it, And secondly, is there possibly a better way to display the data without it overflowing?



Thanks for reading over this



EDIT: added some example addresses and subnets to reflect what may be in a list.










share|improve this question
























  • "Drop Down" lists can be done fairly easy with openpyxl, so called "data validation" in Excel, can you provide the contents of iptc,or a list of some examples ips, or how are they store.
    – HaR
    Jul 24 at 13:56












  • Also how many ip address do you have in the list?
    – HaR
    Jul 24 at 14:04










  • The list can vary in size, usually no more than maybe 40 addresses total, and they are being stored in a list - ill update the example to reflect this with some pseudo examples
    – Connor J
    Jul 24 at 14:23










  • Also you have to store your ip addresses into separate strings like this : iptc = ["165.11.14.20", "166.22.24.0/24", "174.68.19.11", "165.211.20.0/23"]
    – HaR
    Jul 24 at 14:56












  • @HaR Thanks for pointing that out - just updated the example to reflect that
    – Connor J
    Jul 25 at 9:06













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm attempting to store a list of valid ip addresses in a cell using openpyxl. At the moment the data is simply placed into a cell, and usually overflows into other cells. Using the code below:



# Regex to return a tidy list of ip addresses in that block
"""
r = row to be checked
s = source or destination columns
iptc = ips to check
"""

def regex_ips(r, s):
iptc = ['165.11.14.20', '166.22.24.0/24', '174.68.19.11', '165.211.20.0/23']
if r is not None:
if s is not None:
iptc = str(sheet.cell(r, s).value)
san = re.sub('n', ', ', iptc)
sheet_report.cell(r, 8).value = san


However, I would prefer if i could place these ip addresses into a dropdown list since that would be far easier to read - so my question is twofold, first, can this be done? because I couldn't find any info about it, And secondly, is there possibly a better way to display the data without it overflowing?



Thanks for reading over this



EDIT: added some example addresses and subnets to reflect what may be in a list.










share|improve this question















I'm attempting to store a list of valid ip addresses in a cell using openpyxl. At the moment the data is simply placed into a cell, and usually overflows into other cells. Using the code below:



# Regex to return a tidy list of ip addresses in that block
"""
r = row to be checked
s = source or destination columns
iptc = ips to check
"""

def regex_ips(r, s):
iptc = ['165.11.14.20', '166.22.24.0/24', '174.68.19.11', '165.211.20.0/23']
if r is not None:
if s is not None:
iptc = str(sheet.cell(r, s).value)
san = re.sub('n', ', ', iptc)
sheet_report.cell(r, 8).value = san


However, I would prefer if i could place these ip addresses into a dropdown list since that would be far easier to read - so my question is twofold, first, can this be done? because I couldn't find any info about it, And secondly, is there possibly a better way to display the data without it overflowing?



Thanks for reading over this



EDIT: added some example addresses and subnets to reflect what may be in a list.







python openpyxl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 25 at 9:06

























asked Jul 24 at 11:43









Connor J

29711




29711












  • "Drop Down" lists can be done fairly easy with openpyxl, so called "data validation" in Excel, can you provide the contents of iptc,or a list of some examples ips, or how are they store.
    – HaR
    Jul 24 at 13:56












  • Also how many ip address do you have in the list?
    – HaR
    Jul 24 at 14:04










  • The list can vary in size, usually no more than maybe 40 addresses total, and they are being stored in a list - ill update the example to reflect this with some pseudo examples
    – Connor J
    Jul 24 at 14:23










  • Also you have to store your ip addresses into separate strings like this : iptc = ["165.11.14.20", "166.22.24.0/24", "174.68.19.11", "165.211.20.0/23"]
    – HaR
    Jul 24 at 14:56












  • @HaR Thanks for pointing that out - just updated the example to reflect that
    – Connor J
    Jul 25 at 9:06


















  • "Drop Down" lists can be done fairly easy with openpyxl, so called "data validation" in Excel, can you provide the contents of iptc,or a list of some examples ips, or how are they store.
    – HaR
    Jul 24 at 13:56












  • Also how many ip address do you have in the list?
    – HaR
    Jul 24 at 14:04










  • The list can vary in size, usually no more than maybe 40 addresses total, and they are being stored in a list - ill update the example to reflect this with some pseudo examples
    – Connor J
    Jul 24 at 14:23










  • Also you have to store your ip addresses into separate strings like this : iptc = ["165.11.14.20", "166.22.24.0/24", "174.68.19.11", "165.211.20.0/23"]
    – HaR
    Jul 24 at 14:56












  • @HaR Thanks for pointing that out - just updated the example to reflect that
    – Connor J
    Jul 25 at 9:06
















"Drop Down" lists can be done fairly easy with openpyxl, so called "data validation" in Excel, can you provide the contents of iptc,or a list of some examples ips, or how are they store.
– HaR
Jul 24 at 13:56






"Drop Down" lists can be done fairly easy with openpyxl, so called "data validation" in Excel, can you provide the contents of iptc,or a list of some examples ips, or how are they store.
– HaR
Jul 24 at 13:56














Also how many ip address do you have in the list?
– HaR
Jul 24 at 14:04




Also how many ip address do you have in the list?
– HaR
Jul 24 at 14:04












The list can vary in size, usually no more than maybe 40 addresses total, and they are being stored in a list - ill update the example to reflect this with some pseudo examples
– Connor J
Jul 24 at 14:23




The list can vary in size, usually no more than maybe 40 addresses total, and they are being stored in a list - ill update the example to reflect this with some pseudo examples
– Connor J
Jul 24 at 14:23












Also you have to store your ip addresses into separate strings like this : iptc = ["165.11.14.20", "166.22.24.0/24", "174.68.19.11", "165.211.20.0/23"]
– HaR
Jul 24 at 14:56






Also you have to store your ip addresses into separate strings like this : iptc = ["165.11.14.20", "166.22.24.0/24", "174.68.19.11", "165.211.20.0/23"]
– HaR
Jul 24 at 14:56














@HaR Thanks for pointing that out - just updated the example to reflect that
– Connor J
Jul 25 at 9:06




@HaR Thanks for pointing that out - just updated the example to reflect that
– Connor J
Jul 25 at 9:06












2 Answers
2






active

oldest

votes

















up vote
4
down vote



accepted










If you have a larger number of ips (10+), it's better suited to first store them into a column somewhere in the excel and then use their range as the data validation "Source" aka formula1.



from openpyxl.worksheet.datavalidation import DataValidation
wb = Workbook()

ws = wb.create_sheet('New Sheet')

for number in range(1,100): #Generates 99 "ip" address in the Column A;
ws['A{}'.format(number)].value= "192.168.1.{}".format(number)

data_val = DataValidation(type="list",formula1='=$A:$A') #You can change =$A:$A with a smaller range like =A1:A9
ws.add_data_validation(data_val)

data_val.add(ws["B1"]) #If you go to the cell B1 you will find a drop down list with all the values from the column A

wb.save('Test.xlsx')


More info here: https://openpyxl.readthedocs.io/en/2.5/validation.html






share|improve this answer






























    up vote
    2
    down vote













    First you must understand some Excel capabilities. There is one called data validation, which can restrict data input, usually with a drop menu. It can restrict data using a list of values, a range of cells, numeric values, etc.



    After you understand data validation, look in library documentation how to use this Excel capability.






    share|improve this answer

















    • 1




      Thanks, ill have a read up on those links this afternoon
      – Connor J
      Jul 24 at 14:23











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51497731%2fopenpyxl-is-it-possible-to-create-a-dropdown-menu-in-an-excel-sheet%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote



    accepted










    If you have a larger number of ips (10+), it's better suited to first store them into a column somewhere in the excel and then use their range as the data validation "Source" aka formula1.



    from openpyxl.worksheet.datavalidation import DataValidation
    wb = Workbook()

    ws = wb.create_sheet('New Sheet')

    for number in range(1,100): #Generates 99 "ip" address in the Column A;
    ws['A{}'.format(number)].value= "192.168.1.{}".format(number)

    data_val = DataValidation(type="list",formula1='=$A:$A') #You can change =$A:$A with a smaller range like =A1:A9
    ws.add_data_validation(data_val)

    data_val.add(ws["B1"]) #If you go to the cell B1 you will find a drop down list with all the values from the column A

    wb.save('Test.xlsx')


    More info here: https://openpyxl.readthedocs.io/en/2.5/validation.html






    share|improve this answer



























      up vote
      4
      down vote



      accepted










      If you have a larger number of ips (10+), it's better suited to first store them into a column somewhere in the excel and then use their range as the data validation "Source" aka formula1.



      from openpyxl.worksheet.datavalidation import DataValidation
      wb = Workbook()

      ws = wb.create_sheet('New Sheet')

      for number in range(1,100): #Generates 99 "ip" address in the Column A;
      ws['A{}'.format(number)].value= "192.168.1.{}".format(number)

      data_val = DataValidation(type="list",formula1='=$A:$A') #You can change =$A:$A with a smaller range like =A1:A9
      ws.add_data_validation(data_val)

      data_val.add(ws["B1"]) #If you go to the cell B1 you will find a drop down list with all the values from the column A

      wb.save('Test.xlsx')


      More info here: https://openpyxl.readthedocs.io/en/2.5/validation.html






      share|improve this answer

























        up vote
        4
        down vote



        accepted







        up vote
        4
        down vote



        accepted






        If you have a larger number of ips (10+), it's better suited to first store them into a column somewhere in the excel and then use their range as the data validation "Source" aka formula1.



        from openpyxl.worksheet.datavalidation import DataValidation
        wb = Workbook()

        ws = wb.create_sheet('New Sheet')

        for number in range(1,100): #Generates 99 "ip" address in the Column A;
        ws['A{}'.format(number)].value= "192.168.1.{}".format(number)

        data_val = DataValidation(type="list",formula1='=$A:$A') #You can change =$A:$A with a smaller range like =A1:A9
        ws.add_data_validation(data_val)

        data_val.add(ws["B1"]) #If you go to the cell B1 you will find a drop down list with all the values from the column A

        wb.save('Test.xlsx')


        More info here: https://openpyxl.readthedocs.io/en/2.5/validation.html






        share|improve this answer














        If you have a larger number of ips (10+), it's better suited to first store them into a column somewhere in the excel and then use their range as the data validation "Source" aka formula1.



        from openpyxl.worksheet.datavalidation import DataValidation
        wb = Workbook()

        ws = wb.create_sheet('New Sheet')

        for number in range(1,100): #Generates 99 "ip" address in the Column A;
        ws['A{}'.format(number)].value= "192.168.1.{}".format(number)

        data_val = DataValidation(type="list",formula1='=$A:$A') #You can change =$A:$A with a smaller range like =A1:A9
        ws.add_data_validation(data_val)

        data_val.add(ws["B1"]) #If you go to the cell B1 you will find a drop down list with all the values from the column A

        wb.save('Test.xlsx')


        More info here: https://openpyxl.readthedocs.io/en/2.5/validation.html







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jul 24 at 14:48

























        answered Jul 24 at 14:40









        HaR

        365111




        365111
























            up vote
            2
            down vote













            First you must understand some Excel capabilities. There is one called data validation, which can restrict data input, usually with a drop menu. It can restrict data using a list of values, a range of cells, numeric values, etc.



            After you understand data validation, look in library documentation how to use this Excel capability.






            share|improve this answer

















            • 1




              Thanks, ill have a read up on those links this afternoon
              – Connor J
              Jul 24 at 14:23















            up vote
            2
            down vote













            First you must understand some Excel capabilities. There is one called data validation, which can restrict data input, usually with a drop menu. It can restrict data using a list of values, a range of cells, numeric values, etc.



            After you understand data validation, look in library documentation how to use this Excel capability.






            share|improve this answer

















            • 1




              Thanks, ill have a read up on those links this afternoon
              – Connor J
              Jul 24 at 14:23













            up vote
            2
            down vote










            up vote
            2
            down vote









            First you must understand some Excel capabilities. There is one called data validation, which can restrict data input, usually with a drop menu. It can restrict data using a list of values, a range of cells, numeric values, etc.



            After you understand data validation, look in library documentation how to use this Excel capability.






            share|improve this answer












            First you must understand some Excel capabilities. There is one called data validation, which can restrict data input, usually with a drop menu. It can restrict data using a list of values, a range of cells, numeric values, etc.



            After you understand data validation, look in library documentation how to use this Excel capability.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jul 24 at 12:00









            PedroMVM

            277129




            277129








            • 1




              Thanks, ill have a read up on those links this afternoon
              – Connor J
              Jul 24 at 14:23














            • 1




              Thanks, ill have a read up on those links this afternoon
              – Connor J
              Jul 24 at 14:23








            1




            1




            Thanks, ill have a read up on those links this afternoon
            – Connor J
            Jul 24 at 14:23




            Thanks, ill have a read up on those links this afternoon
            – Connor J
            Jul 24 at 14:23


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51497731%2fopenpyxl-is-it-possible-to-create-a-dropdown-menu-in-an-excel-sheet%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]