我正在尝试创建一个json文件,该文件从test.xlsx读取数据。我的示例代码如下。
我希望从excel工作表中读取而不是“ WO-12345”和其他值,就像我希望从excel中的特定单元格中读取它一样。
import xlrd
from collections import OrderedDict
import simplejson as json
import json
jsonfile = open('data1.json', 'w')
data_list = []
data = OrderedDict()
data['workOrder'] = "WO-12345"
data['alternateStart'] = "2018-01-13T10:00:00Z"
data['mobileNumber'] = "(555) 555-5555"
data['officeNumber'] = "(555) 555-5554"
data['description'] = "Testing"
data['equipment'] = "Testing"
data_list.append(data)
j = json.dumps(data_list)
json.dump(data, jsonfile, indent=3, sort_keys=False)
jsonfile.write('\n')
答案 0 :(得分:1)
如果要阅读Excel,则有public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
var rectangle = new System.Drawing.Rectangle(100, 100, 200, 200);
e.Graphics.DrawRectangle(System.Drawing.Pens.Black, rectangle);
base.OnPaint(e);
}
}
个熊猫,它将返回一个具有pandas.read_excel
方法的pandas.DataFrame
。
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html