Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
VueElementTemplate
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄瑜
VueElementTemplate
Commits
ffec6b6d
Commit
ffec6b6d
authored
Sep 11, 2017
by
Pan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add:upload excel
parent
f0afbf7e
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
1 deletion
+111
-1
README-en.md
README-en.md
+1
-0
README.md
README.md
+1
-0
index.vue
src/components/UploadExcel/index.vue
+78
-0
index.js
src/router/index.js
+2
-1
uploadExcel.vue
src/views/excel/uploadExcel.vue
+29
-0
No files found.
README-en.md
View file @
ffec6b6d
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
-
401, 404 error page
-
401, 404 error page
-
Error log
-
Error log
-
Exporting to Excel
-
Exporting to Excel
-
Upload Excel
-
Table example
-
Table example
-
Interactive table example
-
Interactive table example
-
Drag & drop table example
-
Drag & drop table example
...
...
README.md
View file @
ffec6b6d
...
@@ -63,6 +63,7 @@
...
@@ -63,6 +63,7 @@
-
401,404错误页面
-
401,404错误页面
-
错误日志
-
错误日志
-
导出excel
-
导出excel
-
前端可视化excel
-
table example
-
table example
-
动态table example
-
动态table example
-
拖拽table example
-
拖拽table example
...
...
src/components/UploadExcel/index.vue
0 → 100644
View file @
ffec6b6d
<
template
>
<div>
<el-button
:loading=
"loading"
type=
"primary"
@
click=
"handleUpload"
>
select excel file
</el-button>
<input
id=
"excel-upload-input"
type=
"file"
accept=
".xlsx, .xls"
class=
"c-hide"
@
change=
"handkeFileChange"
>
</div>
</
template
>
<
script
>
import
XLSX
from
'xlsx'
export
default
{
data
()
{
return
{
loading
:
false
,
excelData
:
{
header
:
null
,
results
:
null
}
}
},
methods
:
{
generateDate
({
header
,
results
})
{
this
.
excelData
.
header
=
header
this
.
excelData
.
results
=
results
this
.
loading
=
false
this
.
$emit
(
'on-selected-file'
,
this
.
excelData
)
},
handleUpload
()
{
document
.
getElementById
(
'excel-upload-input'
).
click
()
},
handkeFileChange
(
e
)
{
this
.
loading
=
true
const
files
=
e
.
target
.
files
const
itemFile
=
files
[
0
]
// only use files[0]
const
reader
=
new
FileReader
()
reader
.
onload
=
e
=>
{
const
data
=
e
.
target
.
result
const
fixedData
=
this
.
fixdata
(
data
)
const
workbook
=
XLSX
.
read
(
btoa
(
fixedData
),
{
type
:
'base64'
})
const
firstSheetName
=
workbook
.
SheetNames
[
0
]
const
worksheet
=
workbook
.
Sheets
[
firstSheetName
]
const
header
=
this
.
get_header_row
(
worksheet
)
const
results
=
XLSX
.
utils
.
sheet_to_json
(
worksheet
)
this
.
generateDate
({
header
,
results
})
}
reader
.
readAsArrayBuffer
(
itemFile
)
},
fixdata
(
data
)
{
let
o
=
''
let
l
=
0
const
w
=
10240
for
(;
l
<
data
.
byteLength
/
w
;
++
l
)
o
+=
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
data
.
slice
(
l
*
w
,
l
*
w
+
w
)))
o
+=
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
data
.
slice
(
l
*
w
)))
return
o
},
get_header_row
(
sheet
)
{
const
headers
=
[]
const
range
=
XLSX
.
utils
.
decode_range
(
sheet
[
'!ref'
])
let
C
const
R
=
range
.
s
.
r
/* start in the first row */
for
(
C
=
range
.
s
.
c
;
C
<=
range
.
e
.
c
;
++
C
)
{
/* walk every column in the range */
var
cell
=
sheet
[
XLSX
.
utils
.
encode_cell
({
c
:
C
,
r
:
R
})]
/* find the cell in the first row */
var
hdr
=
'UNKNOWN '
+
C
//
<--
replace
with
your
desired
default
if
(
cell
&&
cell
.
t
)
hdr
=
XLSX
.
utils
.
format_cell
(
cell
)
headers
.
push
(
hdr
)
}
return
headers
}
}
}
</
script
>
<
style
scoped
>
#excel-upload-input
{
display
:
none
;
z-index
:
-9999
;
}
</
style
>
src/router/index.js
View file @
ffec6b6d
...
@@ -150,7 +150,8 @@ export const asyncRouterMap = [
...
@@ -150,7 +150,8 @@ export const asyncRouterMap = [
icon
:
'EXCEL'
,
icon
:
'EXCEL'
,
children
:
[
children
:
[
{
path
:
'download'
,
component
:
_import
(
'excel/index'
),
name
:
'导出excel'
},
{
path
:
'download'
,
component
:
_import
(
'excel/index'
),
name
:
'导出excel'
},
{
path
:
'download2'
,
component
:
_import
(
'excel/selectExcel'
),
name
:
'导出已选择项'
}
{
path
:
'download2'
,
component
:
_import
(
'excel/selectExcel'
),
name
:
'导出已选择项'
},
{
path
:
'upload'
,
component
:
_import
(
'excel/uploadExcel'
),
name
:
'upload excel'
}
]
]
},
},
{
{
...
...
src/views/excel/uploadExcel.vue
0 → 100644
View file @
ffec6b6d
<
template
>
<div
class=
"app-container"
>
<upload-excel
@
on-selected-file=
'selected'
></upload-excel>
<el-table
:data=
"tableData"
border
highlight-current-row
style=
"width: 100%;margin-top:20px;"
>
<el-table-column
v-for=
'item of tableHeader'
:prop=
"item"
:label=
"item"
:key=
'item'
>
</el-table-column>
</el-table>
</div>
</
template
>
<
script
>
import
uploadExcel
from
'components/UploadExcel/index.vue'
export
default
{
components
:
{
uploadExcel
},
data
()
{
return
{
tableData
:
[],
tableHeader
:
[]
}
},
methods
:
{
selected
(
data
)
{
this
.
tableData
=
data
.
results
this
.
tableHeader
=
data
.
header
}
}
}
</
script
>
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