| IN2CSV(1) | csvkit | IN2CSV(1) |
نام (NAME)
in2csv - تبدیل قالبهای مختلف دادههای جدولی به CSV
توضیحات (DESCRIPTION)
قالبهای گوناگون دادههای جدولی را به CSV تبدیل میکند.
تبدیل پروندههای با عرض ثابت (fixed width) مستلزم ارائه یک فایل طرحواره (schema) با گزینه "-s" است. فایل طرحواره باید ساختار زیر را داشته باشد:
column,start,length name,0,30 birthday,30,10 age,40,3
سطر سرایند الزامی است، اگرچه ستونها میتوانند به هر ترتیبی باشند:
usage: in2csv [-h] [-d DELIMITER] [-t] [-q QUOTECHAR] [-u {0,1,2,3}] [-b]
[-p ESCAPECHAR] [-z FIELD_SIZE_LIMIT] [-e ENCODING] [-L LOCALE]
[-S] [--blanks] [--null-value NULL_VALUES [NULL_VALUES ...]]
[--date-format DATE_FORMAT] [--datetime-format DATETIME_FORMAT]
[-H] [-K SKIP_LINES] [-v] [-l] [--zero] [-V]
[-f {csv,dbf,fixed,geojson,json,ndjson,xls,xlsx}] [-s SCHEMA]
[-k KEY] [-n] [--sheet SHEET] [--write-sheets WRITE_SHEETS]
[--use-sheet-names] [--reset-dimensions]
[--encoding-xls ENCODING_XLS] [-y SNIFF_LIMIT] [-I]
[FILE]
Convert common, but less awesome, tabular data formats to CSV.
positional arguments:
FILE The CSV file to operate on. If omitted, will accept
input as piped data via STDIN.
optional arguments:
-h, --help show this help message and exit
-f {csv,dbf,fixed,geojson,json,ndjson,xls,xlsx}, --format {csv,dbf,fixed,geojson,json,ndjson,xls,xlsx}
The format of the input file. If not specified will be
inferred from the file type.
-s SCHEMA, --schema SCHEMA
Specify a CSV-formatted schema file for converting
fixed-width files. See web documentation.
-k KEY, --key KEY Specify a top-level key to look within for a list of
objects to be converted when processing JSON.
-n, --names Display sheet names from the input Excel file.
--sheet SHEET The name of the Excel sheet to operate on.
--write-sheets WRITE_SHEETS
The names of the Excel sheets to write to files, or
"-" to write all sheets.
--use-sheet-names Use the sheet names as file names when --write-sheets
is set.
--reset-dimensions Ignore the sheet dimensions provided by the XLSX file.
--encoding-xls ENCODING_XLS
Specify the encoding of the input XLS file.
-y SNIFF_LIMIT, --snifflimit SNIFF_LIMIT
Limit CSV dialect sniffing to the specified number of
bytes. Specify "0" to disable sniffing entirely, or
"-1" to sniff the entire file.
-I, --no-inference Disable type inference (and --locale, --date-format,
--datetime-format, --no-leading-zeroes) when parsing
CSV input.
Some command-line flags only pertain to specific input formats.
همچنین ببینید: آرگومانهای مشترک میان تمام ابزارها.
نکته:
نکته:
نکته:
مثالها (EXAMPLES)
تبدیل فایل سرستونهای جغرافیایی سرشماری ۲۰۰۰ از عرض ثابت به CSV و از کدگذاری latin-1 به utf8:
in2csv -e iso-8859-1 -f fixed -s examples/realdata/census_2000/census2000_geo_schema.csv examples/realdata/census_2000/usgeo_excerpt.upl
نکته:
تبدیل یک فایل اکسل .xls:
in2csv examples/test.xls
استانداردسازی قالببندی یک فایل CSV (نقلقولها، انتهای خطوط و غیره):
in2csv examples/realdata/FY09_EDU_Recipients_by_State.csv
دریافت issueهای باز csvkit از وبسرویس گیتهاب، تبدیل پاسخ JSON به CSV و نوشتن آن در یک فایل:
curl https://api.github.com/repos/wireservice/csvkit/issues?state=open | in2csv -f json -v
تبدیل یک فایل DBase DBF به معادل CSV آن:
in2csv examples/testdbf.dbf
این ابزار به سرایندهای بدون نام، نام اختصاص میدهد. برای جلوگیری از این رفتار اجرا کنید:
in2csv --no-header-row examples/test.xlsx | tail -n +2
عیبیابی (TROUBLESHOOTING)
اگر هنگام ارائه فایل ورودی با قالب CSV یا اکسل خطایی مانند خطای زیر رخ دهد:
ValueError: Row 0 has 11 values, but Table only has 1 columns.
ممکن است فایل ورودی دارای سطرهای ابتدایی پیش از سطر سرایند و سطرهای داده باشد. میتوانید با استفاده از --skip-lines (-K) این ردیفها را نادیده بگیرید:
in2csv --skip-lines 3 examples/test_skip_lines.csv
اگر یک فایل XLSX سطرها یا ستونهای بسیار کمی تولید کند، ممکن است برنامهای که فایل را ایجاد کرده ابعاد کاربرگ را اشتباه تنظیم کرده باشد. دوباره با گزینه --reset-dimensions امتحان کنید.
نویسنده (AUTHOR)
Christopher Groskopf و مشارکتکنندگان
حق نشر (COPYRIGHT)
2016, Christopher Groskopf and James McKinney
| August 16, 2024 | 2.2.0 |