Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exporting to Excel
#1
i am trying to Export the data to excel

list = [{'ip': u'9.11.180.3','endpoint': u'rd2ff5-az2-1519-1520_eth1-18_vpc', 'hostname': u'RD2APIC1', 'encap': u'vlan-42', 'epg': u'19_14_140_172', 'extpaths': u'topology/pod-2/protpaths-1519-1520/pathep-[rd2ff5-az2-1519-1520_eth1-18_vpc]'},{'ip': u'14.10.5.5','endpoint': u'eth1/2','hostname': u'RD2APIC1', 'encap': u'vlan-18', 'epg': u'14_70_7_0', 'extpaths': u'topology/pod-2/paths-1511/extpaths-102/pathep-[eth1/2]'}]
My Code :

filename = self.controller + ".xls"
        excel_file = xlwt.Workbook()
        sheet = excel_file.add_sheet('HOSTLIST')
        sheet.write(0, 0, "APIC")            
        sheet.write(0, 1, "VLAN")
        sheet.write(0, 2, "EPG")
        sheet.write(0, 3, "EndPoint")
        sheet.write(0, 4, "Extpath")
        for count in xrange(1, len(list) + 1):
            if list[count - 1]["epg"]:
                epg = list[count - 1]["epg"]
            else:
                epg = "UNKNOWN"

            sheet.write(count, 0, list[count - 1].get("hostname","UNKNOWN"))
            sheet.write(count, 1, list[count - 1].get("encap","UNKNOWN"))
            sheet.write(count, 2, epg)
            sheet.write(count, 3, list[count - 1].get("endpoint","UNKNOWN"))
            sheet.write(count, 4, list[count - 1].get("extpaths","UNKNOWN"))
        excel_file.save(filename)
[/python]

Link Below : Current and Expected Output :

[Image: iLsQkJc.png]

I have uploaded the image , its about current and expected output . Basically i need to split the "endpoint" if it starts with "rd" while exporting it to excel.

in this case "endpoint - rd2ff5-az2-1519-1520_eth1-18_vpc" needs to be splited as rd2ff5-az2-1519 and rd2ff5-az2-1520 in two rows inserted instead of one in the excel sheet.

Any suggestion/idea ?
Reply


Messages In This Thread
Exporting to Excel - by Nirmal - Jul-26-2019, 05:00 PM
RE: Exporting to Excel - by Nuzvee - Aug-02-2019, 02:41 PM
RE: Exporting to Excel - by Nirmal - Aug-08-2019, 09:24 AM
RE: Exporting to Excel - by Nuzvee - Aug-08-2019, 10:30 AM
RE: Exporting to Excel - by Nirmal - Aug-08-2019, 10:38 AM
RE: Exporting to Excel - by Nirmal - Aug-08-2019, 12:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Exporting Stock Fundamental Data to a CSV file with yahoo_fin DustinKlent 2 4,728 Aug-01-2022, 06:08 PM
Last Post: paulyan
  Exporting dataframes to excel without loosing datetime format Rafa 0 1,238 Oct-27-2021, 10:42 AM
Last Post: Rafa
  Exporting a huge dataFrame stylingpat 5 15,627 Mar-23-2021, 12:13 AM
Last Post: stylingpat
  exporting all lines YazeedbnMohmmed 2 2,127 Feb-24-2021, 03:29 AM
Last Post: YazeedbnMohmmed
  Python code for exporting table using Selenium gj31980 4 3,007 Aug-04-2020, 01:29 AM
Last Post: gj31980
  Exporting data from python into excel Zankawah 5 3,386 Jun-02-2020, 03:17 AM
Last Post: buran
  Exporting list with dictionary to Excel veromi22 0 3,050 Oct-15-2019, 12:54 AM
Last Post: veromi22
  Exporting Python Output to Notepad Nirmal 4 3,585 Sep-02-2018, 02:36 PM
Last Post: Nirmal
  Exporting Json events to a text file uklipse 3 2,675 Aug-21-2018, 02:12 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020