Skip to main content
deleted 6 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Brian yourYour code should look something more like this:

import arcpy
import openpyxl as px


def main():
    wb = px.load_workbook(r"C:\Downloads\Ejemplo\VINCULACION.S.xlsx")
    ws = wb["VINCULACION_SH_NUE"]
    in_features = r"C:\Downloads\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:\Downloads\Ejemplo\VINCULACION_v2.xlsx")


if __name__ == "__main__":
    main()

Brian your code should look something more like this:

import arcpy
import openpyxl as px


def main():
    wb = px.load_workbook(r"C:\Downloads\Ejemplo\VINCULACION.S.xlsx")
    ws = wb["VINCULACION_SH_NUE"]
    in_features = r"C:\Downloads\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:\Downloads\Ejemplo\VINCULACION_v2.xlsx")


if __name__ == "__main__":
    main()

Your code should look something more like this:

import arcpy
import openpyxl as px


def main():
    wb = px.load_workbook(r"C:\Downloads\Ejemplo\VINCULACION.S.xlsx")
    ws = wb["VINCULACION_SH_NUE"]
    in_features = r"C:\Downloads\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:\Downloads\Ejemplo\VINCULACION_v2.xlsx")


if __name__ == "__main__":
    main()
Source Link
Mark Bryant
  • 1.4k
  • 8
  • 7

Brian your code should look something more like this:

import arcpy
import openpyxl as px


def main():
    wb = px.load_workbook(r"C:\Downloads\Ejemplo\VINCULACION.S.xlsx")
    ws = wb["VINCULACION_SH_NUE"]
    in_features = r"C:\Downloads\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:\Downloads\Ejemplo\VINCULACION_v2.xlsx")


if __name__ == "__main__":
    main()