In the game client, it is generally impossible to read the planned Excel configuration table, which needs to be converted into a format that can be used, such as Json,xml format.
The tool I used is a Python script, the power of Python script is not mentioned here, a variety of cattle x mature Library ...
Execute the script as follows:
[CPP]View Plaincopy
- Import OS
- Import Sys
- Import Codecs
- Import JSON
- From XLRD import Open_workbook
- # "<type ' Unicode ' >"
- # "<type ' float ' >"
- def my_text_ (text):
- "" " Return the translated text from JSON text." ""
- v = ("<type", "' >")
- if Text[:len (V[0])]! = V[0]: return text
- if Text[-len (V[1]):]! = v[1]: return text
- return Text[len (V[0]):-len (v[1])
- def sheet2json (sheet, jsonfile):
- Row = 0
- Attribute_row = []
- For col in Range (sheet.ncols):
- Attribute_row.append (Sheet.cell (Row, col). Value)
- attribute = {}
- Row=1
- For col in Range (sheet.ncols):
- Attribute[attribute_row[col]] = My_text_ (repr (Type (sheet.cell_value (row, col)))
- entities = []
- for row in range (2, sheet.nrows):
- entity = {}
- For col in Range (sheet.ncols):
- Entity[attribute_row[col]] = Sheet.cell (row, col). Value
- Row_dict = {}
- row_dict["Entity" = Entity
- Entities.append (row_dict)
- Sheet_dict = {}
- sheet_dict["entities"] = entities
- Filed = Codecs.open (".. /.. /jsonsfromexcel/"+jsonfile, " W ", " Utf-8 ") #输出目录
- Filed.write ("%s"% Json.dumps (sheet_dict, Ensure_ascii=false, indent=4))
- #print json.dumps (sheet_dict, Ensure_ascii=false, indent=4)
- Filed.close ()
- If Len (sys.argv)! = 2:
- Print "Usage:%s [input xls file]"% sys.argv[0]
- Print "e.g.:%s Myinput.xls"% sys.argv[0]
- Print "note:the input file should be MS Excel doc.\n"
- Sys.exit ()
- Xls_file = sys.argv[1]
- Workbook = Open_workbook (xls_file)
- For sheet in workbook.sheets ():
- Jsonfile = Sheet.name + ". JSON"
- #print "Converting%s '%s from EXCEL's sheet to JSON as%s"% (Xls_file, sheet.name, Jsonfile)
- Sheet2json (sheet, jsonfile)
You need to install the XLRD library in the system before using this command, a third-party library that parses Excel files
Original address: http://blog.csdn.net/zhuangyou123/article/details/10068729
(reprint) Game Planner Excel config table to turn into JSON file (i)