<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to update existing Excel .xlsx file using Openpyxl? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-update-existing-excel-xlsx-file-using/m-p/1065848#M61309</link>
    <description>&lt;P&gt;I am trying to make this code work, the problem is that in the excel file the print (...) data is not written, I have tried to use ws.appened (...) but without results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from openpyxl import Workbook
wb = Workbook("C:/Users/Hp/Desktop/ejemplo/VINCULACION_S.xlsx")
ws =  wb.active
rows = arcpy.SearchCursor("C:/Users/Hp/Desktop/ejemplo/VH_Dissolve.shp",
                          fields="COLOR; INTERNO_DE; CLASE_DEMA; COUNT_AREA; SUM_AREA; SUM_LENGTH",
                          sort_fields="COLOR 222; INTERNO_DE A")
# COLOR, INTERNO_DE, CLASE_DEMA, COUNT_AREA, SUM_AREA y SUM_LENGTH.
for row in rows:
    print("Color: {0}, Interno: {1}, Clase:{2}, ContarA: {3}, SumarA: {4}, SumarL: {5}".format(
        row.getValue("COLOR"),
        row.getValue("INTERNO_DE"),
        row.getValue("CLASE_DEMA"),
        row.getValue("COUNT_AREA"),
        row.getValue("SUM_AREA"),
        row.getValue("SUM_LENGTH")))
wb.save('VINCULACION_S.xlsx')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have also tried to locate the results data in the excel file from cell B3: G3 onwards but I can't find it.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Jun 2021 02:27:45 GMT</pubDate>
    <dc:creator>BriamR</dc:creator>
    <dc:date>2021-06-08T02:27:45Z</dc:date>
    <item>
      <title>How to update existing Excel .xlsx file using Openpyxl?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-update-existing-excel-xlsx-file-using/m-p/1065848#M61309</link>
      <description>&lt;P&gt;I am trying to make this code work, the problem is that in the excel file the print (...) data is not written, I have tried to use ws.appened (...) but without results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
from openpyxl import Workbook
wb = Workbook("C:/Users/Hp/Desktop/ejemplo/VINCULACION_S.xlsx")
ws =  wb.active
rows = arcpy.SearchCursor("C:/Users/Hp/Desktop/ejemplo/VH_Dissolve.shp",
                          fields="COLOR; INTERNO_DE; CLASE_DEMA; COUNT_AREA; SUM_AREA; SUM_LENGTH",
                          sort_fields="COLOR 222; INTERNO_DE A")
# COLOR, INTERNO_DE, CLASE_DEMA, COUNT_AREA, SUM_AREA y SUM_LENGTH.
for row in rows:
    print("Color: {0}, Interno: {1}, Clase:{2}, ContarA: {3}, SumarA: {4}, SumarL: {5}".format(
        row.getValue("COLOR"),
        row.getValue("INTERNO_DE"),
        row.getValue("CLASE_DEMA"),
        row.getValue("COUNT_AREA"),
        row.getValue("SUM_AREA"),
        row.getValue("SUM_LENGTH")))
wb.save('VINCULACION_S.xlsx')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have also tried to locate the results data in the excel file from cell B3: G3 onwards but I can't find it.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 02:27:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-update-existing-excel-xlsx-file-using/m-p/1065848#M61309</guid>
      <dc:creator>BriamR</dc:creator>
      <dc:date>2021-06-08T02:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to update existing Excel .xlsx file using Openpyxl?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-update-existing-excel-xlsx-file-using/m-p/1065851#M61310</link>
      <description>&lt;P&gt;Use data access cursors&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/searchcursor-class.htm" target="_blank"&gt;SearchCursor—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;And try your field list as a list, not a concatenated string&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 02:50:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-update-existing-excel-xlsx-file-using/m-p/1065851#M61310</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-06-08T02:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to update existing Excel .xlsx file using Openpyxl?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-update-existing-excel-xlsx-file-using/m-p/1066007#M61313</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I got this code as a solution to the post&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import openpyxl as px

def main():
    wb = px.load_workbook(r"C:\Users\Hp\Desktop\Ejemplo\VINCULACION_S.xlsx")
    ws = wb['VINCULACION_SH_NUE']
    in_features = r"C:\Users\Hp\Desktop\Ejemplo\VH_Dissolve.shp"

    row_num = 3
    with arcpy.da.SearchCursor(
        in_features,
        ["COLOR", "INTERNO_DE", "CLASE_DEMA", "COUNT_AREA", "SUM_AREA", "SUM_LENGTH"],
    ) as cursor:
        for row in cursor:
            ws.cell(row=row_num, column=2).value = row[0]
            ws.cell(row=row_num, column=3).value = row[1]
            ws.cell(row=row_num, column=4).value = row[2]
            ws.cell(row=row_num, column=6).value = row[3]
            ws.cell(row=row_num, column=7).value = row[4]
            ws.cell(row=row_num, column=8).value = row[5]
            row_num += 1
    wb.save(r"C:\Users\Hp\Desktop\Ejemplo\VINCULACION_S.xlsx")


if __name__ == "__main__":
    main()&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 08 Jun 2021 14:34:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-update-existing-excel-xlsx-file-using/m-p/1066007#M61313</guid>
      <dc:creator>BriamR</dc:creator>
      <dc:date>2021-06-08T14:34:10Z</dc:date>
    </item>
  </channel>
</rss>

