0

I need to open an excel work sheet, and create different excel sheets segmenting from data.

  • Ancienneté Site 1 - Mon territoire -Direction Générale 2 paris 2 -COMEX 0 paris 2 -Direction Générale 12 paris 2 -Développement 21 ollioules 2

For example, I need to create different sheets for each city, paris, ollioules ( i have different cities) and get all of the informations in that row. Until now I have:

# -*- coding: utf-8 -*

import openpyxl as px
workbook = px.load_workbook('digital_trust.xlsx')
worksheet = workbook.get_sheet_names()

for worksheet in worksheet:
    worksheet = workbook.get_sheet_by_name()

    for row in worksheet.iter_rows(row_offset=2):
        ville = row[3].value        
        print ville
oezlem
  • 237
  • 2
  • 12
  • fist of all you have a problem if you want to use for worksheet in worksheet... change the following "worksheet = " to "worksheets = " and "for worksheet in worksheet" to "for worksheet in worksheets" because you overwrite the first variable with the worksheet name of the first worksheet. – Kathara Aug 25 '17 at 11:09
  • Do you want to create new sheets or do you want to rename the existing ones according to the name of the city? – Kathara Aug 25 '17 at 11:19
  • According to [this](https://stackoverflow.com/a/40385840/5621032) you only need to add workbook.create_sheet(ville). – Kathara Aug 25 '17 at 12:18
  • But i want to get all the information by city name – oezlem Aug 25 '17 at 12:30
  • What do you want? new sheets that are named as the cities? or do you want to change the name of the sheet you get the name of the city out? – Kathara Aug 25 '17 at 12:40
  • I want a new sheet for each city name, and the information for that row For example: Paris ... sheet 2 for another city.. – oezlem Aug 25 '17 at 12:40
  • Read [Simple usage wb.create_sheet](http://openpyxl.readthedocs.io/en/default/usage.html) – stovfl Aug 25 '17 at 19:51

0 Answers0