Skip to content

Commit

Permalink
#64 local excel data files read changes
Browse files Browse the repository at this point in the history
- switched to using new file.utils.ts for text excel data file reads
- changed binary .dif and .slk data file reads
- removed .prn files support (they are for print only)
- updated excel data files mappings in package.json, docs and config.ts
  • Loading branch information
RandomFractals committed Jun 25, 2019
1 parent 0eb50a1 commit 0fcfe6a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ Data File Extension(s) | File Type | Data Parsing Library/Method Used | Data For
`.ini` | text | [node-properties](https://github.com/gagle/node-properties)/[`properties.parse()`](https://github.com/gagle/node-properties#ini) | https://en.wikipedia.org/wiki/INI_file
`.yml` `.yaml` | text | [js-yaml](https://github.com/nodeca/js-yaml)/[`yaml.load()`](https://github.com/nodeca/js-yaml#load-string---options-) | https://yaml.org/
`.csv` `.tsv` `.txt` `.tab` | text | [perspective](https://github.com/finos/perspective/)/[`perspectiveViewer.load(text)`](https://github.com/finos/perspective/tree/master/packages/perspective-viewer#module_perspective-viewer..PerspectiveViewer+load) | https://en.wikipedia.org/wiki/Comma-separated_values https://en.wikipedia.org/wiki/Tab-separated_values
`.dif` `.slk` `.prn` `.xml` `.html` | text | [js-xlsx](https://github.com/SheetJS/js-xlsx)/[`XLSX.readFile(text)`](https://github.com/SheetJS/js-xlsx#parsing-functions) | See https://github.com/SheetJS/js-xlsx#file-formats for more info on text `Excel` file formats
`.ods` `.xls` `.xlsb` `.xlsx` `.xlsm` | binary | [js-xlsx](https://github.com/SheetJS/js-xlsx)/[`XLSX.readFile(binary)`](https://github.com/SheetJS/js-xlsx#parsing-functions) | See https://github.com/SheetJS/js-xlsx#file-formats for more info on binary `Excel` file formats
`.xml` `.html` | text | [js-xlsx](https://github.com/SheetJS/js-xlsx)/[`XLSX.readFile(text)`](https://github.com/SheetJS/js-xlsx#parsing-functions) | See https://github.com/SheetJS/js-xlsx#file-formats for more info on text `Excel` file formats
`.dif` `.ods` `.slk` `.xls` `.xlsb` `.xlsx` `.xlsm` | binary | [js-xlsx](https://github.com/SheetJS/js-xlsx)/[`XLSX.readFile(binary)`](https://github.com/SheetJS/js-xlsx#parsing-functions) | See https://github.com/SheetJS/js-xlsx#file-formats for more info on binary `Excel` file formats

![Data Preview Data](https://github.com/RandomFractals/vscode-data-preview/blob/master/images/vscode-data-preview-data.png?raw=true
"Data Preview Data")
Expand Down
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"tab",
"dif",
"ods",
"prn",
"slk",
"xls",
"xlsb",
Expand Down Expand Up @@ -208,7 +207,6 @@
".xlsm",
".dif",
".ods",
".prn",
".slk"
],
"aliases": [
Expand Down Expand Up @@ -250,36 +248,36 @@
"explorer/context": [
{
"command": "data.preview",
"when": "resourceFilename =~ /.*\\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|prn|slk|xls|xlsb|xlsx|xlsm|xml|html)/",
"when": "resourceFilename =~ /.*\\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|slk|xls|xlsb|xlsx|xlsm|xml|html)/",
"group": "navigation"
},
{
"command": "data.preview.on.side",
"when": "resourceFilename =~ /.*\\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|prn|slk|xls|xlsb|xlsx|xlsm|xml|html)/",
"when": "resourceFilename =~ /.*\\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|slk|xls|xlsb|xlsx|xlsm|xml|html)/",
"group": "navigation"
}
],
"editor/title": [
{
"command": "data.preview",
"when": "resourceFilename =~ /.*\\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|prn|slk|xls|xlsb|xlsx|xlsm|xml|html)/",
"when": "resourceFilename =~ /.*\\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|slk|xls|xlsb|xlsx|xlsm|xml|html)/",
"group": "navigation"
},
{
"command": "data.preview.on.side",
"when": "resourceFilename =~ /.*\\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|prn|slk|xls|xlsb|xlsx|xlsm|xml|html)/",
"when": "resourceFilename =~ /.*\\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|slk|xls|xlsb|xlsx|xlsm|xml|html)/",
"group": "navigation"
}
],
"editor/title/context": [
{
"command": "data.preview",
"when": "resourceFilename =~ /.*\\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|prn|slk|xls|xlsb|xlsx|xlsm|xml|html)/",
"when": "resourceFilename =~ /.*\\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|slk|xls|xlsb|xlsx|xlsm|xml|html)/",
"group": "navigation"
},
{
"command": "data.preview.on.side",
"when": "resourceFilename =~ /.*\\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|prn|slk|xls|xlsb|xlsx|xlsm|xml|html)/",
"when": "resourceFilename =~ /.*\\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|slk|xls|xlsb|xlsx|xlsm|xml|html)/",
"group": "navigation"
}
]
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { LogLevel } from "./logger";
// log level setting for prod. vs. dev run of this ext.
export const logLevel: LogLevel = LogLevel.Info; // change to .Debug for ext. dev debug

export const supportedDataFiles: RegExp = /.*\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|prn|slk|xls|xlsb|xlsx|xlsm|xml|html)/;
export const supportedDataFiles: RegExp = /.*\.(json|json5|hjson|arrow|arr|avro|parquet|parq|config|env|properties|ini|yaml|yml|csv|tsv|txt|tab|dif|ods|slk|xls|xlsb|xlsx|xlsm|xml|html)/;

export const supportedBinaryDataFiles: RegExp = /.*\.(arrow|arr|avro|parquet|parq|ods|xls|xlsb|xlsx|xlsm)/;
export const supportedBinaryDataFiles: RegExp = /.*\.(arrow|arr|avro|parquet|parq|dif|ods|slk|xls|xlsb|xlsx|xlsm)/;

// arrow to data view type mappings
// see: https://github.com/finos/perspective/blob/master/packages/perspective/src/js/utils.js
Expand Down
13 changes: 5 additions & 8 deletions src/data.preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,16 +473,15 @@ export class DataPreview {
case '.tab':
data = fileUtils.readDataFile(dataFilePath, 'utf8'); // file encoding to read data as string
break;
case '.dif':
case '.ods':
case '.slk':
case '.xls':
case '.xlsb':
case '.xlsx':
case '.xlsm':
case '.ods':
data = this.getBinaryExcelData(dataFilePath);
break;
case '.dif':
case '.slk':
case '.prn':
case '.xml':
case '.html':
data = this.getTextExcelData(dataFilePath);
Expand All @@ -503,7 +502,6 @@ export class DataPreview {
data = this.getJsonData(dataFilePath);
break;
case '.json5':
// see https://json5.org/ for more info
data = this.getJson5Data(dataFilePath);
break;
case '.hjson':
Expand Down Expand Up @@ -550,9 +548,8 @@ export class DataPreview {
* @returns Array of row objects.
*/
private getTextExcelData(dataFilePath: string): any[] {
// load Excel workbook
const workbook: xlsx.WorkBook = xlsx.readFile(dataFilePath, {
type: 'file',
const dataString: string = fileUtils.readDataFile(dataFilePath, 'utf8');
const workbook: xlsx.WorkBook = xlsx.read(dataString, {
cellDates: true,
});
return this.getExcelData(workbook);
Expand Down

0 comments on commit 0fcfe6a

Please sign in to comment.