禁用 Pyexcel 排序
Disable Pyexcel sorting
我正在使用 pyexcel,当我从字典中得到 sheet 时,它会按字母顺序排序。我怎样才能禁用该功能?
我尝试在文档中搜索有关排序的信息,但没有找到任何内容。
例如,在这段代码中,我有两行:蔬菜和水果,按顺序排列。但是在输出中它改变了按字母顺序排序的顺序。
代码:
import pyexcel as p
vegetables = ['tomato', 'corn', 'onion']
fruits = ['banana', 'apple', 'orange']
food = {
'Vegetables': vegetables,
'Fruits': fruits,
}
sheet = p.get_sheet(adict=food)
print(sheet)
输出:
pyexcel_sheet1:
+--------+------------+
| Fruits | Vegetables |
+--------+------------+
| banana | tomato |
+--------+------------+
| apple | corn |
+--------+------------+
| orange | onion |
+--------+------------+
预期输出:
pyexcel_sheet1:
+------------+---------+
| Vegetables | Fruits |
+------------+---------+
| tomato | banana |
+------------+---------+
| corn | apple |
+------------+---------+
| onion | orange |
+------------+---------+
使用 OrderedDict() 制作collections.OrderedDict
food = OrderedDict({
'Vegetables': vegetables,
'Fruits': fruits,
})
我正在使用 pyexcel,当我从字典中得到 sheet 时,它会按字母顺序排序。我怎样才能禁用该功能?
我尝试在文档中搜索有关排序的信息,但没有找到任何内容。
例如,在这段代码中,我有两行:蔬菜和水果,按顺序排列。但是在输出中它改变了按字母顺序排序的顺序。
代码:
import pyexcel as p
vegetables = ['tomato', 'corn', 'onion']
fruits = ['banana', 'apple', 'orange']
food = {
'Vegetables': vegetables,
'Fruits': fruits,
}
sheet = p.get_sheet(adict=food)
print(sheet)
输出:
pyexcel_sheet1:
+--------+------------+
| Fruits | Vegetables |
+--------+------------+
| banana | tomato |
+--------+------------+
| apple | corn |
+--------+------------+
| orange | onion |
+--------+------------+
预期输出:
pyexcel_sheet1:
+------------+---------+
| Vegetables | Fruits |
+------------+---------+
| tomato | banana |
+------------+---------+
| corn | apple |
+------------+---------+
| onion | orange |
+------------+---------+
使用 OrderedDict() 制作collections.OrderedDict
food = OrderedDict({
'Vegetables': vegetables,
'Fruits': fruits,
})