{"id":18723074,"url":"https://github.com/axiaoxin/json2xls","last_synced_at":"2025-04-12T14:53:28.868Z","repository":{"id":20937433,"uuid":"24225736","full_name":"axiaoxin/json2xls","owner":"axiaoxin","description":"{\"generate excel by json data\": \"根据json数据生成Excel表格\"}","archived":false,"fork":false,"pushed_at":"2019-05-28T12:46:29.000Z","size":67,"stargazers_count":31,"open_issues_count":1,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-26T09:22:41.301Z","etag":null,"topics":["excel","json","json-excel","json2xls","python","xls"],"latest_commit_sha":null,"homepage":"http://json2xls.readthedocs.org/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/axiaoxin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-19T10:21:36.000Z","updated_at":"2023-06-18T15:37:49.000Z","dependencies_parsed_at":"2022-08-28T05:40:15.959Z","dependency_job_id":null,"html_url":"https://github.com/axiaoxin/json2xls","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axiaoxin%2Fjson2xls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axiaoxin%2Fjson2xls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axiaoxin%2Fjson2xls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/axiaoxin%2Fjson2xls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/axiaoxin","download_url":"https://codeload.github.com/axiaoxin/json2xls/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248198879,"owners_count":21063628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["excel","json","json-excel","json2xls","python","xls"],"created_at":"2024-11-07T13:47:34.581Z","updated_at":"2025-04-12T14:53:28.845Z","avatar_url":"https://github.com/axiaoxin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"json2xls:Generate Excel by JSON data\n====================================\n\n[![](https://badge.fury.io/py/json2xls.png)](http://badge.fury.io/py/json2xls)\n[![](https://pypip.in/d/json2xls/badge.png)](https://pypi.python.org/pypi/json2xls)\n\n       _                 ____       _\n      (_)___  ___  _ __ |___ \\__  _| |___\n      | / __|/ _ \\| '_ \\  __) \\ \\/ / / __|\n      | \\__ \\ (_) | | | |/ __/ \u003e  \u003c| \\__ \\\n     _/ |___/\\___/|_| |_|_____/_/\\_\\_|___/\n    |__/\n\ngenerate excel by json string or json file or url which return a json\n\ntesting on python2.7 and python3.6.0\n\n**docs** \u003chttp://json2xls.readthedocs.org/en/latest/\u003e\n\n**install**\n\n    pip install json2xls\n\nor\n\n    python setup.py install\n\n\n## command usage:\n\n#### gen xls from json string\n\n    json2xls cmd_str_test.xls '{\"a\":\"a\", \"b\":\"b\"}'\n    json2xls cmd_str_test1.xls '[{\"a\":\"a\", \"b\":\"b\"},{\"a\":1, \"b\":2}]'\n\n#### gen xls from file: whole file is a complete json data\n\n    json2xls cmd_list_test.xls \"`cat tests/list_data.json`\"\n\n#### gen xls from file: each line is a json data\n\n    json2xls cmd_line_test.xls tests/line_data.json\n\n#### gen xls from a url which respond a json\n\n    json2xls cmd_get_test.xls http://httpbin.org/get\n    json2xls cmd_post_test.xls http://httpbin.org/post -m post -d '\"hello json2xls\"' -h \"{'X-Token': 'bolobolomi'}\"\n\n## coding usage (python2.7):\n\n#### gen xls from json string\n\n    #!/usr/bin/env python\n    #-*- coding:utf-8 -*-\n\n    from json2xls.json2xls import Json2Xls\n\n    json_data = u'''[\n        {\"姓名\": \"John\", \"年龄\": 30, \"性别\": \"男\"},\n        {\"姓名\": \"Alice\", \"年龄\": 18, \"性别\": \"女\"}\n    ]'''\n    obj = Json2Xls('json_strlist_test.xls', json_data)\n    obj.make()\n\n\n#### gen xls from a url which respond a json by GET\n\n    params = {\n        'location': u'上海',\n        'output': 'json',\n        'ak': '5slgyqGDENN7Sy7pw29IUvrZ'\n    }\n    Json2Xls('url_get_test.xls',\n             \"http://httpbin.org/get\",\n             params=params).make()\n\n\n#### gen xls from a url which respond a json by POST\n\n    post_data = {\n        'location': u'上海',\n        'output': 'json',\n        'ak': '5slgyqGDENN7Sy7pw29IUvrZ'\n    }\n    Json2Xls('url_post_test1.xls',\n             \"http://httpbin.org/post\",\n             method='post',\n             post_data=post_data,\n             form_encoded=True).make()\n\n#### gen xls from a url which respond a json by POST with file post data\n\n    post_data = 'tests/post_data.json'\n    Json2Xls('url_post_test2.xls',\n             \"http://httpbin.org/post\",\n             method='post',\n             post_data=post_data,\n             form_encoded=True).make()\n\n\n#### gen xls from file: whole file is a complete json data （从文件内容为一个json列表的文件生成excel）\n\n    Json2Xls('json_list_test.xls', json_data='tests/list_data.json').make()\n\n#### gen xls from file: each line is a json data （从文件内容为每行一个的json字符串的文件生成excel）\n\n    obj = Json2Xls('json_line_test.xls', json_data='tests/line_data.json')\n    obj.make()\n\n#### gen custom excel by define your title and body callback function\n\n    def title_callback(self, data):\n        '''use one of data record to generate excel title'''\n        self.sheet.write_merge(0, 0, 0, 3, 'title', self.title_style)\n        self.sheet.write_merge(1, 2, 0, 0, 'tag', self.title_style)\n        self.sheet.write_merge(1, 2, 1, 1, 'ner', self.title_style)\n        self.sheet.write_merge(1, 1, 2, 3, 'comment', self.title_style)\n        self.sheet.row(2).write(2, 'x', self.title_style)\n        self.sheet.row(2).write(3, 'y', self.title_style)\n\n        self.sheet.write_merge(0, 0, 4, 7, 'body', self.title_style)\n        self.sheet.write_merge(1, 2, 4, 4, 'tag', self.title_style)\n        self.sheet.write_merge(1, 2, 5, 5, 'ner', self.title_style)\n        self.sheet.write_merge(1, 1, 6, 7, 'comment', self.title_style)\n        self.sheet.row(2).write(6, 'x', self.title_style)\n        self.sheet.row(2).write(7, 'y', self.title_style)\n\n        self.start_row += 3\n\n    def body_callback(self, data):\n\n        key1 = ['title', 'body']\n        key2 = ['tag', 'ner', 'comment']\n\n        col = 0\n        for ii, i in enumerate(key1):\n            for ij, j in enumerate(key2):\n                if j != 'comment':\n                    value = ', '.join(data[ii][i][j])\n                    self.sheet.row(self.start_row).write(col, value)\n                    col += 1\n                else:\n                    for x in data[ii][i][j].values():\n                        self.sheet.row(self.start_row).write(col, x)\n                        col += 1\n        self.start_row += 1\n\n    data = 'tests/callback_data.json'\n    j = Json2Xls('tests/callback.xls', data)\n    j.make(title_callback=title_callback, body_callback=body_callback)\n\n\nDefault request method is `get`, request argument pass by `params`.\nand the `post` method's request argument pass by `data`, you can use `-d` to pass request data in command line, the data should be json or file\n\nDefault only support one layer json to generate the excel, the nested json will be flattened. if you want custom it,\nyou can write the `title_callback` function and `body_callback` function, the pass them in the `make` function.\nfor the `body_callback`, you just need to care one line data's write way, json2xls default think the data are all the same.\n\nThe test demo data file is in `tests` dir. and `demo.py` is all coding example to gen xls\n\n## Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/axiaoxin/json2xls.svg)](https://starchart.cc/axiaoxin/json2xls)\n      \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxiaoxin%2Fjson2xls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxiaoxin%2Fjson2xls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxiaoxin%2Fjson2xls/lists"}