Members
WDataCsv
- Description:
讀寫CSV檔
- Source:
讀寫CSV檔
Example
import wdc from './src/WDataCsv.mjs'
let fpIn = './g-test-in.csv'
wdc.readCsv(fpIn)
.then((ltdtIn) => {
console.log(ltdtIn)
// => [ { NAME: 'Daffy Duck', AGE: '24' }, { NAME: 'Bugs 邦妮', AGE: '22' } ]
})
.catch((err) => {
console.log(err)
})
let ltdtOut = [{ name: '大福 Duck', value: 2.4 }, { name: 'Bugs 邦妮', value: '2.2' }]
let fpOut = './g-test-out.csv'
wdc.writeCsv(fpOut, ltdtOut)
.then((res) => {
console.log(res)
// => finish
})
.catch((err) => {
console.log(err)
})
Methods
(async) readCsv(fp) → {Promise}
- Description:
讀取CSV檔,自動清除BOM
- Source:
Example
import wdc from './src/WDataCsv.mjs'
let fp = './g-test-in.csv'
wdc.readCsv(fp)
.then((ltdt) => {
console.log(ltdt)
// => [ { NAME: 'Daffy Duck', AGE: '24' }, { NAME: 'Bugs 邦妮', AGE: '22' } ]
})
.catch((err) => {
console.log(err)
})
Parameters:
Name | Type | Description |
---|---|---|
fp |
String | 輸入檔案位置字串 |
Returns:
回傳Promise,resolve回傳ltdt(各數據列為物件陣列),reject回傳錯誤訊息
- Type
- Promise
(async) writeCsv(fp, data, optopt) → {Promise}
- Description:
輸出數據至CSV檔案
- Source:
Example
import wdc from './src/WDataCsv.mjs'
let ltdt = [{ name: '大福 Duck', value: 2.4 }, { name: 'Bugs 邦妮', value: '2.2' }]
let fp = './g-test-out.csv'
wdc.writeCsv(fp, ltdt)
.then((res) => {
console.log(res)
// => finish
})
.catch((err) => {
console.log(err)
})
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fp |
String | 輸入檔案位置字串 |
||||||||||||||||||||||
data |
Array | 輸入數據陣列,為mat或ltdt格式 |
||||||||||||||||||||||
opt |
Object |
<optional> |
{}
|
輸入設定物件,預設{} Properties
|
Returns:
回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
- Type
- Promise