我有这段代码:
func clipboardContent() -> String?
{
return NSPasteboard.general.pasteboardItems?.first?.string(forType: .string)
}
我想在Excel上提取"result": [{
"Name": "Jean",
"LastName": "xxx",
"Salaire": xxx,
"hire": "2015-07-25",
"numerobadge": 0000111 ",
"worked_per_week": 35,
}, {
"Name": "Catherine",
"LastName": "xxx",
"Salaire": xxx,
"hire": "2016-11-09",
"numerobadge": 0000127 ",
"worked_per_week": 25,
}, {
"Name": "George",
"LastName": "xxx",
"Salaire": xxx,
"hire": "2016-12-05",
"numerobadge": 0000144 ",
"worked_per_week": 35,
},
和hours_per_week
。我找不到dict和list以及xlsxwriter的好教程。
答案 0 :(得分:1)
结果是一个列表,您可以通过循环提取信息,如:
for p in result:
name = p['Name']
w_p_w = p['worked_per_week']
答案 1 :(得分:1)
import json
import xlsxwriter
workbook = xlsxwriter.Workbook('Expenses01.xlsx')
worksheet = workbook.add_worksheet()
"result":[
{ "Name":"Jean", "LastName":"xxx", "Salaire":xxx, "hire":"2015-07-25", "numerobadge":0000111", "worked_per_week":35, }, { "Name":"Catherine", "LastName":"xxx", "Salaire":xxx, "hire":"2016-11-09", "numerobadge":0000127", "worked_per_week":25, }, { "Name":"George", "LastName":"xxx", "Salaire":xxx, "hire":"2016-12-05", "numerobadge":0000144", "worked_per_week":35, },
]
row = 0
col = 0
a=['result']
for p in result
name = p['Name']
w_p_w = p['worked_per_week']
workbook.close()