Coder Social home page Coder Social logo

xlsx2json-cli's Introduction

@asamihsoy/xlsx2json

※ will be translated into English in near future

インストール・起動方法

npm i -D @asamihsoy/xlsx2json
npx xlsx2json ./sample.xlsx

※ npm scriptには xlsx2json ./sample.xlsx -o ./assets/src/ という形で指定できます。

基本の使い方

xlsxファイルを用意して xlsx2json を実行することで、JSONへ変換できます。

【INPUT】ファイル名: rostar.xlsx / シート名: member
id name company department
1 @asamihsoy fugafuga Inc division1
2 @person2 hogehoge Inc division2

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

npx xlsx2json ./member.xlsx

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

【OUTPUT】ファイル名: member.json
{
"data": [{
    "id": 1,
    "name": "@asamihsoy",
    "company": "fugafuga Inc",
    "department": "division1"
  },{
    "id": 2,
    "name": "@person2",
    "company": "hogehoge Inc",
    "department": "division2"
  }]
}

コマンドライン使用時のオプション確認

npx xlsx2json -h
フラグ 必須/任意 備考
-o 任意 実行場所からJSONの格納ディレクトリへの相対パス
-t 任意 JSONのトップレベルオブジェクトのタイプ arrayobject を指定

その他の使い方

シート名や見出しを一定の構文で記述することで、JSONのアウトプットを操作することができます。

アクション 設定箇所 設定構文 設定値 説明
JSONのトップレベルキーの変更 シート名 sheetName$key=altKey 任意の文字列 JSONのトップレベルのキーを変更できます。(※デフォルト値は data です。)
JSONのトップレベルへのキーの追加 シート名 !sheetName マージしたいシート名 !を頭につけたシートはJSON化されず、!のあとのsheetNameと同じ名前のシートのJSONのTOPレベルにマージされます。※ そのため、シート内のレコードは1行しか反映されません。
参照用途限定のシートを作成 シート名 __sheetName 参照用にしたいシート名 __を頭につけたシートはJSON化されず、参照用のみに使うことができます。
他シートの展開 見出し jsonKey:sheetName1$ref=key シート名 JSONの出力キーに:でシート名をつなぐことで、該当シートから生成されるJSONのキー(jsonKey)の中にシート1(sheetName1)の値を展開できます。sheetName1のデータ中でrefで指定したkeyの値がマッチするものだけが展開されます。 ※1キーに紐付けられるのは1シートのみです。
ネストの作成 見出し jsonKey1.jsonKey2.jsonKey3 キー名 JSONの出力キーを.でつなげることで階層構造を作成可能です。かぶるキーがある場合はオブジェクトはマージされます。

※ 機能は適宜追加していきます。
※ シート名/キー名は半角英数字のみサポートしています。
!__が頭についたシートはJSONとして出力されません
※ ~~シート名は半角英数字である必要があります。~~日本語のシート名も認識するようにしました。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.