Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
am-xlsx2json
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Aksimaya
am-xlsx2json
Commits
649d15fa
Commit
649d15fa
authored
Nov 11, 2015
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
recode ... new version
parent
3cc48dc9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
51 deletions
+12
-51
index.js
lib/index.js
+12
-51
No files found.
lib/index.js
View file @
649d15fa
...
...
@@ -24,59 +24,20 @@ function XLSX_json(config, callback) {
function
CV
(
config
,
callback
)
{
var
wb
=
this
.
load_xlsx
(
config
.
input
)
var
ws
=
this
.
ws
(
config
,
wb
);
var
csv
=
this
.
csv
(
ws
)
this
.
cvjson
(
csv
,
config
.
output
,
callback
)
var
csv
=
this
.
to_json
(
wb
);
return
callback
(
null
,
csv
);
}
CV
.
prototype
.
load_xlsx
=
function
(
input
)
{
return
xlsx
.
readFile
(
input
);
}
CV
.
prototype
.
ws
=
function
(
config
,
wb
)
{
var
target_sheet
=
config
.
sheet
;
if
(
target_sheet
==
null
)
target_sheet
=
wb
.
SheetNames
[
0
];
ws
=
wb
.
Sheets
[
target_sheet
];
return
ws
;
}
CV
.
prototype
.
csv
=
function
(
ws
)
{
return
csv_file
=
xlsx
.
utils
.
make_csv
(
ws
)
}
CV
.
prototype
.
cvjson
=
function
(
csv
,
output
,
callback
)
{
var
record
=
[]
var
header
=
[]
cvcsv
()
.
from
.
string
(
csv
)
.
transform
(
function
(
row
)
{
row
.
unshift
(
row
.
pop
());
return
row
;
})
.
on
(
'
record
'
,
function
(
row
,
index
)
{
if
(
index
===
0
)
{
header
=
row
;
}
else
{
var
obj
=
{};
header
.
forEach
(
function
(
column
,
index
)
{
obj
[
column
.
trim
()]
=
row
[
index
].
trim
();
})
record
.
push
(
obj
);
}
})
.
on
(
'
end
'
,
function
(
count
)
{
if
(
output
!==
null
)
{
var
stream
=
fs
.
createWriteStream
(
output
,
{
flags
:
'
w
'
});
stream
.
write
(
JSON
.
stringify
(
record
));
callback
(
null
,
record
);
}
else
{
callback
(
null
,
record
);
}
})
.
on
(
'
error
'
,
function
(
error
)
{
console
.
error
(
error
.
message
);
});
}
CV
.
prototype
.
to_json
=
function
(
workbook
)
{
var
result
=
{};
workbook
.
SheetNames
.
forEach
(
function
(
sheetName
)
{
var
roa
=
xlsx
.
utils
.
sheet_to_row_object_array
(
workbook
.
Sheets
[
sheetName
]);
if
(
roa
.
length
>
0
){
result
[
sheetName
]
=
roa
;
}
});
return
result
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment