33[ ![ PkgGoDev] ( https://pkg.go.dev/badge/github.com/noborus/xlsxsql )] ( https://pkg.go.dev/github.com/noborus/xlsxsql )
44[ ![ Actions Status] ( https://github.com/noborus/xlsxsql/workflows/Go/badge.svg )] ( https://github.com/noborus/xlsxsql/actions )
55
6- A CLI tool to execute SQL queries on xlsx files.
6+ A CLI tool that executes SQL queries on various files including xlsx files and outputs the results to various files.
77
88![ xlsxsql query -H -o md "SELECT a.id,a.name,b.price FROM testdata/test3.xlsx::.C1 AS a LEFT JOIN testdata/test3.xlsx::.F4 AS b ON a.id=b.id"] ( docs/xlsxsql.png )
99
@@ -13,8 +13,8 @@ A CLI tool to execute SQL queries on xlsx files.
1313| 2 | orange | 50 |
1414| 3 | melon | 500 |
1515
16- Execute SQL on xlsx files using [ xcelize ] ( https://github.com/qax-os/excelize ) and [ trdsql ] ( https://github.com/noborus/trdsql ) .
17- Output to various formats .
16+ A CLI tool that executes SQL queries on xlsx files and outputs the results to various files, and also executes SQL queries on various files and outputs them to xlsx files .
17+ Built using [ excelize ] ( https://github.com/qax-os/excelize ) and [ trdsql ] ( https://github.com/noborus/trdsql ) .
1818
1919## Install
2020
@@ -60,7 +60,7 @@ mv xlsxsql /usr/local/bin/
6060``` console
6161$ xlsxsql --help
6262Execute SQL against xlsx file.
63- output to CSV and various formats.
63+ Output to CSV and various formats.
6464
6565Usage:
6666 xlsxsql [flags]
@@ -74,11 +74,17 @@ Available Commands:
7474 table SQL(SELECT * FROM table) for xlsx
7575
7676Flags:
77- -H, --header Output header
78- -h, --help help for xlsxsql
79- -o, --out string Output Format[CSV|AT|LTSV|JSON|JSONL|TBLN|RAW|MD|VF|YAML] (default "CSV")
80- -s, --skip int Skip the number of lines
81- -v, --version display version information
77+ --clear-sheet Clear sheet when outputting to xlsx file
78+ --debug debug mode
79+ -H, --header Input header
80+ -h, --help help for xlsxsql
81+ -o, --out string Output Format[CSV|AT|LTSV|JSON|JSONL|TBLN|RAW|MD|VF|YAML|XLSX] (default "GUESS")
82+ --out-cell string Cell name to output to xlsx file
83+ -O, --out-file string File name to output to file
84+ --out-header Output header
85+ --out-sheet string Sheet name to output to xlsx file
86+ -s, --skip int Skip the number of lines
87+ -v, --version display version information
8288
8389Use "xlsxsql [command] --help" for more information about a command.
8490```
@@ -118,6 +124,23 @@ Bob,25
118124Carol,30
119125```
120126
127+ ` xlsxsql ` is an extended version of [ trdsql] ( https://github.com/noborus/trdsql ) ,
128+ so you can execute SQL on files such as CSV and JSON.
129+
130+ ``` console
131+ xlsxsql query "SELECT * FROM test.csv"
132+ ```
133+
134+ In other words, you can also do CSV and JOIN.
135+
136+ ``` console
137+ xlsxsql query -H -o md \
138+ "SELECT a.id,a.name,b.price
139+ FROM testdata/test3.xlsx::.C1 AS a
140+ LEFT JOIN test.csv AS b
141+ ON a.id=b.id"
142+ ```
143+
121144### Specify sheet
122145
123146The sheet can be specified by using a double colon "::" after the file name
@@ -141,7 +164,8 @@ Optional if the sheet is the first sheet.
141164xlsxsql query "SELECT * FROM test3.xlsx::.C1"
142165```
143166
144- Note: If cell is specified, the table up to the blank column is considered to be the table.
167+ > Note:
168+ > If cell is specified, the table up to the blank column is considered to be the table.
145169
146170This allows multiple tables to be specified on one sheet, and JOIN is also possible.
147171
@@ -165,32 +189,57 @@ Here is an example:
165189xlsxsql table test.xlsx::Sheet2.C1
166190```
167191
192+ It can be omitted for the first sheet.
193+
194+ ``` console
195+ xlsxsql table test.xlsx::.C1
196+ ```
197+
198+ ### Skip Options
199+
200+ The ` --skip ` or ` -s ` option skips the specified number of lines.
201+ For example, you would use it like this:
202+
203+ ``` console
204+ xlsxsql query --skip 1 "SELECT * FROM test.xlsx::Sheet2"
205+ ```
206+
207+ Skip is useful when specifying sheets, allowing you to skip unnecessary rows.
208+ (There seems to be no advantage to using skip when specifying Cell.)
209+
168210### Output format
169211
170212``` console
171213xlsxsql query --out JSONL "SELECT * FROM test.xlsx::Sheet2"
172214```
173215
174- You can choose from CSV, LTSV, JSON, JSONL, TBLN, RAW, MD, VF, YAML.
216+ You can choose from CSV, LTSV, JSON, JSONL, TBLN, RAW, MD, VF, YAML, (XLSX) .
175217
176- ### Header Options
218+ ### Output to xlsx file
177219
178- The ` --header ` or ` -H ` option treats the first line as a header.
179- Headers are treated as column names.
180- For example, use:
220+ You can output the result to an xlsx file by specifying a file name with the ` .xlsx ` extension as the ` --out-file ` option. For example:
181221
182222``` console
183- xlsxsql query --header -- out JSONL "SELECT * FROM test.xlsx::Sheet2"
223+ xlsxsql query --out-file test2.xlsx "SELECT * FROM test.xlsx::Sheet2"
184224```
185225
186- ### Skip Options
226+ > Note:
227+ > You can also output to the same xlsx file as the input file. Please be careful as the contents will be overwritten.
187228
188- The ` --skip ` or ` -s ` option skips the specified number of lines.
189- For example, you would use it like this:
229+ > Note:
230+ > Even if you specify XLSX with --out, you must specify a file name with the extension ` .xlsx ` .
231+
232+ This command will execute the SQL query on the Sheet1 of test.xlsx and output the result to result.xlsx.
233+ If the file does not exist, it will be created. If the file already exists, the results will be updated.
234+
235+ You can specify the ` sheet ` and ` cell ` to output, if you want to output to an xlsx file. For example:
190236
191237``` console
192- xlsxsql query --skip 1 "SELECT * FROM test.xlsx::Sheet2"
238+ xlsxsql query --out-file test2.xlsx --out-sheet Sheet2 --out-cell C1 "SELECT * FROM test.xlsx::Sheet2"
193239```
194240
195- Skip is useful when specifying sheets, allowing you to skip unnecessary rows.
196- (There seems to be no advantage to using skip when specifying Cell.)
241+ You can clear the sheet before outputting to an xlsx file by specifying the ` --clear-sheet ` option. For example:
242+
243+ ``` console
244+ xlsxsql query --out-file test2.xlsx --clear-sheet "SELECT * FROM test.xlsx::Sheet2"
245+ ```
0 commit comments