excel 中的重复行无法使用这组代码

Repeating rows in excel could not work with this set of codes

我的问题如下: 我的程序的目的:在继续下一组数据之前,重复另一个 excel 文件中的数据 3 次。 例如 期望的输出:

    23   25   27 
    23   25   27 
    23   25   27 
    28   4    21 
    28   4    21 
    28   4    21 

我当前的(错误)输出是: 例如 错误输出:

    23    25    27
    28    4    21

我的代码如下。为什么我不能通过重复代码并相应地更改行号来对 K、L 和 M 列重复我的代码 3 次?它显示错误输出而不是所需的输出。 :( 非常感谢您的阅读和帮助!

 #>>>>>>>>>>>SEPERATE LIST SHOWN IN PYTHON PROGRAM (i.e. dataX, data Y, data Z), -START- <<<<<<<<<<<<<<<#

     CRS=[] 
     dataX=[sheet.cell_value(1, col) for col in range(sheet.ncols)]
     dataY=[sheet.cell_value(2, col) for ju in range(4)for col in range(sheet.ncols)]
     dataBin = [sheet.cell_value(6, col) for col in range(sheet.ncols)]

     for nm in range (int(ND)):         #for nm in range of ND
         CRS.append((dataX[nm+6],dataY[nm+6],dataBin[nm+6]))

     print CRS
     print ""

     workbook = xlwt.Workbook()
     sheet = workbook.add_sheet('sheet1')

     for index, value in enumerate(dataBin):

         sheet.write( 3, index, value)
         sheet.write( 1, index, value)
         sheet.write( 2, index, value)

(下面继续)#ERROR 最有可能从这里开始

         for np in range(int(ND)):          

        #COLUMN K = X COORDINATE
             sheet1.write(np+30,10,CRS[np][0])  #np+30 == row. 10== column K
             sheet1.write(np+31,10,CRS[np][0])  #np+31 == row. 11== column K,
             sheet1.write(np+32,10,CRS[np][0])  #np+32 == row. 12== column K

        #COLUMN L = Y COORDINATE
             sheet1.write(np+30,11,CRS[np][1])  #np+30 == row. 10 == column L
             sheet1.write(np+31,11,CRS[np][1])  #np+31 == row. 11 == column L
             sheet1.write(np+32,11,CRS[np][1])  #np+32 == row. 12 == column L

        #COLUMN M = SOFT BIN
             sheet1.write(np+30,12,CRS[np][2])  #np+30 == row. 10 == column M
             sheet1.write(np+31,12,CRS[np][2])  #np+31 == row. 11 == column M
             sheet1.write(np+32,12,CRS[np][2])  #np+32 == row. 12 == column M

在 np = 10 的循环中,您的三行(np+30、np+31、np+32)将等于第 40、41 和 42 行。

在 np = 11 的下一个循环中,您的三行将等于 41、42、43,从而覆盖您之前的两行。

我希望如果您查看您的输出,最后一项将根据需要一式三份。

尝试将 np 乘以 3。

(np*3)+30...

10*3+30=60
10*3+31=61
10*3+32=62
11*3+30=63
11*3+31=64
11*3+32=65
12*3+30=66 etc