将所有行值放入单元格

2024-09-27 17:55:37 发布

您现在位置:Python中文网/ 问答频道 /正文

如何将所有行的值放入单元格

rows = db().select(i.INV_ITEMCODE, n.INV_NAME, orderby=i.INV_ITEMCODE, join=n.on(i.POS_TASKCODE == n.POS_TASKCODE))
for r in rows:
    code = str(r.db_i_item.INV_ITEMCODE)
    desc = str(r.db_i_name.INV_NAME)     
    row = [dict(rows=rows)]
    cell = [code, desc]
    row = [dict(cell=cell, id=str(+1))]
    records = []
    total = [] 
    result = None
    result = dict(records=str(total), total='1', row=row , page='1') #records should get the total cell
    return result

结果只返回一个单元格值 dict:{'records':'[]','total':'1','page':'1','row':[{'cell':['LUBS001','Hav。全合成1L'],'id':'1'}]}

但是行有一个查询:

Rows: db_i_item.INV_ITEMCODE,db_i_name.INV_NAME
LUBS001,Hav. Fully Synthetic 1L
LUBS002,Hav. Formula 1L
LUBS003,Hav. SF 1L
LUBS004,Hav. Plus 2T 200ML
LUBS005,Havoline Plus 2T 1L
LUBS006,Havoline Super 4T 1L
LUBS007,Havoline EZY 4T 1L
LUBS008,Delo Sports 1L
LUBS009,Delo Gold Multigrade 1L
LUBS010,Delo Gold Monograde 1L
LUBS011,Delo Silver 1L
LUBS012,Super Diesel 1L
LUBS013,Brake Fluid 250ML
LUBS014,Brake Fluid 500ML
LUBS015,Brake Fluid 1L
LUBS016,Texamatic ATF 1L
LUBS020,Coolant
LUBS21,Delo
PET001,DIESEL
PET002,SILVER
PET003,GOLD
PET004,REGULAR
PET005,KEROSENE

你知道吗


Tags: namedbcellresultdictrowsrowtotal
1条回答
网友
1楼 · 发布于 2024-09-27 17:55:37

明白了:D

'items=db(q1&q2&search)。选择(i.INV\u ITEMCODE,n.INV\u NAME,m.INV\u KIND,p.INV\u PRICE,m.INV\u DRTABLE,p.INV\u PRICECODE,p.INV\u ITEMCODEX,orderby=o) ri=0 行=[]

    for ri, r in enumerate(items):
        if r.db_i_matrix.INV_KIND == 'W':
            kind = 'Wet'
        else:
            kind = 'Dry'
        cell = [ str(ri + 1), str(r.db_i_item.INV_ITEMCODE), str(r.db_i_name.INV_NAME), str(kind), str(r.db_i_price.INV_PRICE),
                 str(r.db_i_matrix.INV_DRTABLE), str(r.db_i_price.INV_PRICECODE), str(r.db_i_price.INV_ITEMCODEX)] 
        records = ri + 1
        rows += [dict(id=str(ri + 1), cell=cell)]
    ikind = dict(records=records, totals='1', rows=rows)'

相关问题 更多 >

    热门问题