|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
以下代码是PYTHON访问EXCEL,然后我怎么才能把不同单元格的值,赋值给我的类?
目前遇到的问题就是,赋值的时候,都是指向同一个内存,怎么处理才能把它变成不同的内存地址?现在输出的都是最后一个单元格的数值.
出问题的代码:
Seg[Base_Count][SegMent_Count].Name = ws.cell(row=7, column=xx).value
print('Name:', Seg[Base_Count][SegMent_Count].Name, 'Base:', Base_Count,'SegMent:', SegMent_Count, 'ID:', id(Seg[Base_Count][SegMent_Count]))
以下是完整代码:
# -*- coding: UTF-8 -*-
import openpyxl
class SegMent_Property:
Top = 'N'
Down = 'N'
Left = 'N'
Right = 'N'
Front = 'N'
Back = 'N'
Name = 'N'
Len = 0
Panel_Wide = 0
Panel_Len = 0
Pressure = '-'
Panel_Intensity = 1
class Panel:
Wide = 0
Len = 0
Max_Wide = 0
Max_Len = 0
Pressure = '-'
Name = 'N'
In_Material = 'N'
Out_Material = 'N'
wb = openpyxl.load_workbook('2018-2-4 new temp -V1.xlsx',read_only=True,data_only=True)
ws = wb['功能段排布']
while ws.cell(row = 7 , column = xx).value != None:
if ws.cell(row = 7 , column = xx).value == '断点':
All_SegMent.append(SegMent_Count - 1)
Base_Count += 1
SegMent_Count = 0
Seg[Base_Count][SegMent_Count].Name = ws.cell(row=7, column=xx).value
Seg[Base_Count][SegMent_Count].Len = ws.cell(row=8, column=xx).value
Seg[Base_Count][SegMent_Count].Top = ws.cell(row=13, column=xx).value
Seg[Base_Count][SegMent_Count].Down = ws.cell(row=14, column=xx).value
Seg[Base_Count][SegMent_Count].Left = ws.cell(row=15, column=xx).value
Seg[Base_Count][SegMent_Count].Right = ws.cell(row=16, column=xx).value
Seg[Base_Count][SegMent_Count].Front = ws.cell(row=16, column=xx).value
Seg[Base_Count][SegMent_Count].Back = ws.cell(row=16, column=xx).value
print('Name:', Seg[Base_Count][SegMent_Count].Name, 'Base:', Base_Count,'SegMent:', SegMent_Count, 'ID:', id(Seg[Base_Count][SegMent_Count]))
SegMent_Count += 1
xx += 1
|
|