All Projects → axiaoxin → json2xls

axiaoxin / json2xls

Licence: BSD-2-Clause license
{"generate excel by json data": "根据json数据生成Excel表格"}

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to json2xls

Pyexcel
Single API for reading, manipulating and writing data in csv, ods, xls, xlsx and xlsm files
Stars: ✭ 902 (+2906.67%)
Mutual labels:  excel, xls
Myexcel
MyExcel, a new way to operate excel!
Stars: ✭ 1,198 (+3893.33%)
Mutual labels:  excel, xls
Desktopeditors
An office suite that combines text, spreadsheet and presentation editors allowing to create, view and edit local documents
Stars: ✭ 1,008 (+3260%)
Mutual labels:  excel, xls
Sheetjs
📗 SheetJS Community Edition -- Spreadsheet Data Toolkit
Stars: ✭ 28,479 (+94830%)
Mutual labels:  excel, xls
Xresloader
跨平台Excel导表工具(Excel=>protobuf/msgpack/lua/javascript/json/xml)
Stars: ✭ 161 (+436.67%)
Mutual labels:  excel, xls
Rows
A common, beautiful interface to tabular data, no matter the format
Stars: ✭ 739 (+2363.33%)
Mutual labels:  excel, xls
Documentbuilder
ONLYOFFICE Document Builder is powerful text, spreadsheet, presentation and PDF generating tool
Stars: ✭ 61 (+103.33%)
Mutual labels:  excel, xls
Easyexcel
快速、简单避免OOM的java处理Excel工具
Stars: ✭ 22,133 (+73676.67%)
Mutual labels:  excel, xls
Test files
📚 SheetJS Test Files (XLS/XLSX/XLSB and other spreadsheet formats)
Stars: ✭ 150 (+400%)
Mutual labels:  excel, xls
Libxls
Read binary Excel files from C/C++
Stars: ✭ 142 (+373.33%)
Mutual labels:  excel, xls
Readxl
Read excel files (.xls and .xlsx) into R 🖇
Stars: ✭ 585 (+1850%)
Mutual labels:  excel, xls
Documentserver
ONLYOFFICE Document Server is an online office suite comprising viewers and editors for texts, spreadsheets and presentations, fully compatible with Office Open XML formats: .docx, .xlsx, .pptx and enabling collaborative editing in real time.
Stars: ✭ 2,335 (+7683.33%)
Mutual labels:  excel, xls
Docjure
Read and write Office documents from Clojure
Stars: ✭ 510 (+1600%)
Mutual labels:  excel, xls
Tableexport
The simple, easy-to-implement library to export HTML tables to xlsx, xls, csv, and txt files.
Stars: ✭ 781 (+2503.33%)
Mutual labels:  excel, xls
Localizable.strings2excel
Python command line tool for conversion between iOS strings files and excel files & between android strings.xml files and excl files. & strings files to android strings.xml files.
Stars: ✭ 424 (+1313.33%)
Mutual labels:  excel, xls
Spreadsheet
The Ruby Spreadsheet by ywesee GmbH
Stars: ✭ 1,033 (+3343.33%)
Mutual labels:  excel, xls
J
❌ Multi-format spreadsheet CLI (now merged in http://github.com/sheetjs/js-xlsx )
Stars: ✭ 343 (+1043.33%)
Mutual labels:  excel, xls
Npoi.mapper
Use this tool to import or export data with Excel file. The tool is a convention based mapper between strong typed object and Excel data via NPOI.
Stars: ✭ 348 (+1060%)
Mutual labels:  excel, xls
Phpspreadsheet
A pure PHP library for reading and writing spreadsheet files
Stars: ✭ 10,627 (+35323.33%)
Mutual labels:  excel, xls
Excelmapper
Map POCO objects to Excel files
Stars: ✭ 166 (+453.33%)
Mutual labels:  excel, xls

json2xls:Generate Excel by JSON data

   _                 ____       _
  (_)___  ___  _ __ |___ \__  _| |___
  | / __|/ _ \| '_ \  __) \ \/ / / __|
  | \__ \ (_) | | | |/ __/ >  <| \__ \
 _/ |___/\___/|_| |_|_____/_/\_\_|___/
|__/

generate excel by json string or json file or url which return a json

testing on python2.7 and python3.6.0

docs http://json2xls.readthedocs.org/en/latest/

install

pip install json2xls

or

python setup.py install

command usage:

gen xls from json string

json2xls cmd_str_test.xls '{"a":"a", "b":"b"}'
json2xls cmd_str_test1.xls '[{"a":"a", "b":"b"},{"a":1, "b":2}]'

gen xls from file: whole file is a complete json data

json2xls cmd_list_test.xls "`cat tests/list_data.json`"

gen xls from file: each line is a json data

json2xls cmd_line_test.xls tests/line_data.json

gen xls from a url which respond a json

json2xls cmd_get_test.xls http://httpbin.org/get
json2xls cmd_post_test.xls http://httpbin.org/post -m post -d '"hello json2xls"' -h "{'X-Token': 'bolobolomi'}"

coding usage (python2.7):

gen xls from json string

#!/usr/bin/env python
#-*- coding:utf-8 -*-

from json2xls.json2xls import Json2Xls

json_data = u'''[
    {"姓名": "John", "年龄": 30, "性别": "男"},
    {"姓名": "Alice", "年龄": 18, "性别": "女"}
]'''
obj = Json2Xls('json_strlist_test.xls', json_data)
obj.make()

gen xls from a url which respond a json by GET

params = {
    'location': u'上海',
    'output': 'json',
    'ak': '5slgyqGDENN7Sy7pw29IUvrZ'
}
Json2Xls('url_get_test.xls',
         "http://httpbin.org/get",
         params=params).make()

gen xls from a url which respond a json by POST

post_data = {
    'location': u'上海',
    'output': 'json',
    'ak': '5slgyqGDENN7Sy7pw29IUvrZ'
}
Json2Xls('url_post_test1.xls',
         "http://httpbin.org/post",
         method='post',
         post_data=post_data,
         form_encoded=True).make()

gen xls from a url which respond a json by POST with file post data

post_data = 'tests/post_data.json'
Json2Xls('url_post_test2.xls',
         "http://httpbin.org/post",
         method='post',
         post_data=post_data,
         form_encoded=True).make()

gen xls from file: whole file is a complete json data (从文件内容为一个json列表的文件生成excel)

Json2Xls('json_list_test.xls', json_data='tests/list_data.json').make()

gen xls from file: each line is a json data (从文件内容为每行一个的json字符串的文件生成excel)

obj = Json2Xls('json_line_test.xls', json_data='tests/line_data.json')
obj.make()

gen custom excel by define your title and body callback function

def title_callback(self, data):
    '''use one of data record to generate excel title'''
    self.sheet.write_merge(0, 0, 0, 3, 'title', self.title_style)
    self.sheet.write_merge(1, 2, 0, 0, 'tag', self.title_style)
    self.sheet.write_merge(1, 2, 1, 1, 'ner', self.title_style)
    self.sheet.write_merge(1, 1, 2, 3, 'comment', self.title_style)
    self.sheet.row(2).write(2, 'x', self.title_style)
    self.sheet.row(2).write(3, 'y', self.title_style)

    self.sheet.write_merge(0, 0, 4, 7, 'body', self.title_style)
    self.sheet.write_merge(1, 2, 4, 4, 'tag', self.title_style)
    self.sheet.write_merge(1, 2, 5, 5, 'ner', self.title_style)
    self.sheet.write_merge(1, 1, 6, 7, 'comment', self.title_style)
    self.sheet.row(2).write(6, 'x', self.title_style)
    self.sheet.row(2).write(7, 'y', self.title_style)

    self.start_row += 3

def body_callback(self, data):

    key1 = ['title', 'body']
    key2 = ['tag', 'ner', 'comment']

    col = 0
    for ii, i in enumerate(key1):
        for ij, j in enumerate(key2):
            if j != 'comment':
                value = ', '.join(data[ii][i][j])
                self.sheet.row(self.start_row).write(col, value)
                col += 1
            else:
                for x in data[ii][i][j].values():
                    self.sheet.row(self.start_row).write(col, x)
                    col += 1
    self.start_row += 1

data = 'tests/callback_data.json'
j = Json2Xls('tests/callback.xls', data)
j.make(title_callback=title_callback, body_callback=body_callback)

Default request method is get, request argument pass by params. and 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

Default only support one layer json to generate the excel, the nested json will be flattened. if you want custom it, you can write the title_callback function and body_callback function, the pass them in the make function. for the body_callback, you just need to care one line data's write way, json2xls default think the data are all the same.

The test demo data file is in tests dir. and demo.py is all coding example to gen xls

Stargazers over time

Stargazers over time

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].