1

I am a bit new in python now working in qgis to automates some time. I have an excel pre-written template file where i have to add different data in different columns.

outpufFile = open('d:/template.xlsx','w')
for layer in QgsMapLayerRegistry.instance().mapLayers().values():
    print layer.name() +","+ str(layer.featureCount())
    line = layer.name()
    unicode_line = line.encode('utf-8')
    outpufFile.write(unicode_line)
outpufFile.close() 

I get this so far but it corrupting my template while I also don't know how to access specific column or row of my file In order to write at exactly column and row to full my template.

Muhammad Faizan Khan
  • 10,013
  • 18
  • 97
  • 186
  • Have you considered using [openpyxl](https://openpyxl.readthedocs.io/en/default/) for this, like in this answer: http://stackoverflow.com/a/31405828/1619971? – JCVanHamme Sep 29 '16 at 12:21

1 Answers1

1

You need a Python library that understands how to handle xlsx files:

openpyxl, for example.

ppaulojr
  • 3,579
  • 4
  • 29
  • 56
Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/13833482) – ivan_pozdeev Sep 29 '16 at 13:17
  • 1
    The question's author, who would seem to be the ultimate authority, would appear to disagree. – Scott Hunter Oct 04 '16 at 12:01