Help:CSV format

From Linux Web Expert

Revision as of 06:39, 13 April 2020 by >Kghbln (chg)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

CSV format
Outputs results in Windows-style Comma Separated Value format.
Further Information
Provided by: Semantic MediaWiki
Added: 1.2.1
Removed: still supported
Requirements: none
Format name: csv
Enabled? Indicates whether the result format is enabled by default upon installation of the respective extension. yes
Authors: Nathan Yergler , Markus Krötzsch , James Hong Kong
Categories: export · plaintext
Table of Contents

The result format csv is used to produce links to CSV files which allow to export the result of a query. See also result format "DSV"Outputs results in *NIX-style Delimiter Separated Value format. with is similar to this one.

Semantic MediaWiki 3.0.0Released on an unknown date unknown versions of MediaWiki introduced a set of predefined classes supporting a datatable output12 which also allows for CSV export via result format "Table"Outputs the results in a table (default for queries with printout statements)..

Parameters

Format specific
⧼validator-describe-header-parameter⧽ ⧼validator-describe-header-type⧽ ⧼validator-describe-header-default⧽ ⧼validator-describe-header-description⧽
sep ⧼validator-type-string⧽ , Specifies a column separator
valuesep ⧼validator-type-string⧽ , Specifies a value separator
showsep ⧼validator-type-boolean⧽ no Show separator in top of CSV file ("sep=<value>")
filename ⧼validator-type-string⧽ result.csv The name for the output file
merge ⧼validator-type-boolean⧽ no Merge rows and column values with an identical subject identifier (aka first column)
bom ⧼validator-type-boolean⧽ no Add a BOM (character to signal endianness) at the top of the output file
Semantic MediaWiki 3.0.0Released on an unknown date unknown versions of MediaWiki brought the "valuesep"3, "merge"45 and "bom"6 parameters.

Remarks

  • All numeric or named entities in the generated output are decoded as UTF-8 strings. Therefore the character set in your application has to be set accordingly (UTF-8).
  • On most platforms, CSV files will be automatically opened by the default application for using spreadsheets.

Examples

Default

Syntax
{{#ask:
 [[Category:City]]
 [[Located in::Germany]] 
 |?Population
 |?Area#km²=Area
 |mainlabel=City
 |format=csv
}}
Result

CSV

Change file name

Another file name for exporting the results can be specified by changing the filename parameter:

Syntax
{{#ask:
 [[Category:City]]
 [[Located in::Germany]] 
 |?Population
 |?Area#km²=Area
 |mainlabel=City
 |format=csv
 |filename=example.csv
}}
Result

CSV

Change separators

Between results

Another separator between results than "," e.g. ";" can be used if specified by the sep parameter:

Syntax
{{#ask:
 [[Category:City]]
 [[Located in::Germany]]
 |?Population
 |?Area#km²=Area
 |mainlabel=City
 |format=csv
 |sep=;
}}
Result

CSV

Best used in combination with outputting the separator.

Between property values

Another separator between results than "," e.g. "~" can be used if specified by the valuesep parameter:

Syntax
{{#ask:
 [[Category:City]]
 [[Located in::Germany]]
 |?Population
 |?Area#km²=Area
 |?Has zoo=Zoo
 |mainlabel=City
 |format=csv
 |valuesep=~
}}
Result

CSV

Output separator used

The separator used between results can be listed too in the exported file by setting the showsep parameter to yes:

Syntax
{{#ask:
 [[Category:City]]
 [[Located in::Germany]]
 |?Population
 |?Area#km²=Area
 |?Has zoo=Zoo
 |mainlabel=City
 |format=csv
 |showsep=yes
}}
Result

CSV

Best used if the separator between results was changed from the default value.

Combine results for identical subject identifiers

Subject identifier with identical row and column values can be merged by setting the merge parameter to yes, e.g. lines containing "Foo", "1", "2", "3" and "Foo", "4", "5", "6" will result in "Foo", "1,4", "2,5", "3,6".5. Such a situation can normally only appear when mainlabel=- is used that creates a specific first column and contains identical identifier.

Add the byte order mark

The byte order mark (BOM) can be added to the exported file by setting the bom parameter to yes:

Syntax
{{#ask:
 [[Category:City]]
 [[Located in::Germany]]
 |?Population
 |?Area#km²=Area
 |?Has zoo=Zoo
 |mainlabel=City
 |format=csv
 |bom=yes
}}
Result

CSV

This is especially useful for Microsoft compilers and interpreters as well as many pieces of software on Microsoft Windows such as Notepad since they treat the BOM as a required magic number rather than use heuristics for interpreting the file content.
#scite could not render a citation text for reference "gh:smw:2822" because type "pullrequest" was not assigned to a template.
#scite could not render a citation text for reference "sb:smw:2822" because type "example" was not assigned to a template.
#scite could not render a citation text for reference "gh:smw:2824" because type "pullrequest" was not assigned to a template.
#scite could not render a citation text for reference "gh:smw:2826" because type "pullrequest" was not assigned to a template.

References

  1. ^ gh:smw:2420 
  2. ^ gh:smw:2718 
  3. ^ gh:smw:2826 
  4. ^ gh:smw:2822 
  5. a b sb:smw:2822 
  6. ^ gh:smw:2824