Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
excelTable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
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
周田
excelTable
Commits
646e8768
Commit
646e8768
authored
May 06, 2024
by
周田
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:监听单元格数据
parent
adbaad16
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
4 deletions
+23
-4
ExcelTable.vue
src/components/ExcelTable.vue
+23
-4
No files found.
src/components/ExcelTable.vue
View file @
646e8768
<
template
>
<button
id=
"toggleButton"
@
click=
"changeMode"
>
{{
buttonMsg
}}
</button>
<button
id=
"exportData"
@
click=
"exportData"
>
export data
</button>
<div
id=
"tableDiv"
></div>
</
template
>
...
...
@@ -22,8 +23,26 @@ const changeMode = () => {
}
}
const
exportData
=
()
=>
{
if
(
isEditable
)
{
alert
(
'请切换至预览模式后再导出数据'
);
return
;
}
}
const
cellChanged
=
(
cell
:
HTMLTableCellElement
)
=>
{
console
.
log
(
"单元格内容发生改变:"
+
cell
.
textContent
);
console
.
log
(
"所在行:"
+
(
cell
.
parentElement
as
HTMLTableRowElement
).
rowIndex
);
console
.
log
(
"所在列:"
+
cell
.
cellIndex
);
let
row
=
(
cell
.
parentElement
as
HTMLTableRowElement
).
rowIndex
;
let
col
=
cell
.
cellIndex
;
tableData
[
row
][
col
].
value
=
cell
.
textContent
||
""
;
console
.
log
(
tableData
);
}
// 生成表格
onMounted
(()
=>
{
console
.
log
(
tableData
)
// 读取数据
let
tableDiv
=
document
.
getElementById
(
'tableDiv'
)
!
let
table
=
document
.
createElement
(
'table'
)
...
...
@@ -33,7 +52,7 @@ onMounted(() => {
for
(
let
i
=
0
;
i
<
tableData
.
length
;
i
++
)
{
let
tr
=
document
.
createElement
(
'tr'
)
for
(
let
j
=
0
;
j
<
tableData
[
i
].
length
;
j
++
)
{
for
(
let
j
=
0
;
j
<
tableData
[
i
].
length
;
j
++
)
{
if
(
tableData
[
i
][
j
].
value
===
undefined
)
continue
;
let
td
=
null
;
...
...
@@ -43,14 +62,14 @@ onMounted(() => {
td
=
document
.
createElement
(
'td'
)
}
td
.
textContent
=
String
(
tableData
[
i
][
j
].
value
)
td
.
oninput
=
()
=>
cellChanged
(
td
)
// 处理合并单元格问题
td
.
rowSpan
=
tableData
[
i
][
j
].
rowSpan
td
.
colSpan
=
tableData
[
i
][
j
].
colSpan
tr
.
appendChild
(
td
)
}
table
.
appendChild
(
tr
)
}
tableDiv
.
appendChild
(
table
)
...
...
@@ -66,7 +85,7 @@ onMounted(() => {
}
:deep
(
th
,
td
)
{
td
)
{
border
:
1px
solid
#ddd
;
padding
:
8px
;
text-align
:
center
;
...
...
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