2016-09-02 4 views
0

私は以下に添付したjsonファイルを持っています。私はPythonでjsonファイルを読む必要があります。このファイルには、複数のシートを含むxlsファイルのパスが含まれています。このファイルは、各シートを個別のcsvファイルとして出力して出力する必要があります。どのように私が行くことができるかについての任意のアイデア?複数のシートを含むxlsファイルをPythonで別々のcsvに変換する

{ "file":{ 
       "path":"C:/.../xyz.xlsx", 
       "sheetname":"Sheet1" 
       "Clean":{    
       "1":"A", 
       "2":"B", 
       "3":"C" 
       }, 
       "Delete":{ 
       "1":"D", 
       "2":"E" 
       }, 
       "outfile":"C:/.../out_xyz.csv" 
       } 
} 

私は下に添付したリンクをいくつか引用しましたが、私はまだ無駄です!これについて
Reading JSON from a file?
How can i split an Excel (.xls) file that contains multiple sheets into separate excel files?
Save each sheet in a workbook to separate CSV files

答えて

0

どのように?

Pythonとxlrdを使用します。& xlwt。次のスクリプトは、あなたが望む何をすべきhttp://www.python-excel.org

参照してください:

import xlrd, xlwt, sys 

def raj_split(in_path, out_stem): 
    in_book = xlrd.open_workbook(in_path) 
    in_sheet = in_book.sheet_by_index(0) 
    first_row = in_sheet.row_values(0) 
    # find the rightmost 1 value in the first row 
    split_pos = max(
     colx for colx, value in enumerate(first_row) if value == 1.0 
     ) + 1 
    out_book = xlwt.Workbook() 
    out_sheet = out_book.add_sheet("Sheet1", cell_overwrite_ok=True) 
    # copy the common cells 
    for rowx in xrange(in_sheet.nrows): 
     row_vals = in_sheet.row_values(rowx, end_colx=split_pos) 
     for colx in xrange(split_pos): 
      out_sheet.write(rowx, colx, row_vals[colx]) 
    out_num = 0 
    # for each output file ... 
    for out_col in range(split_pos, in_sheet.ncols): 
     out_num += 1 
     # ... overwrite the `split_pos` column 
     for rowx, value in enumerate(in_sheet.col_values(colx=out_col)): 
      out_sheet.write(rowx, split_pos, value) 
     # ... and save the file. 
     out_book.save("%s_%03d.xls" % (out_stem, out_num)) 

raj_split(*sys.argv[1:3]) 
関連する問題