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
a8602e78
Commit
a8602e78
authored
Oct 12, 2017
by
spiritree
Committed by
花裤衩
Oct 12, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refine:export adaptive colwidth in excel
parent
516897b9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
1 deletion
+19
-1
Export2Excel.js
src/vendor/Export2Excel.js
+19
-1
No files found.
src/vendor/Export2Excel.js
View file @
a8602e78
...
...
@@ -100,7 +100,6 @@ export function export_table_to_excel(id) {
/* original data */
var
data
=
oo
[
0
];
var
ws_name
=
"SheetJS"
;
console
.
log
(
data
);
var
wb
=
new
Workbook
(),
ws
=
sheet_from_array_of_arrays
(
data
);
...
...
@@ -127,6 +126,25 @@ export function export_json_to_excel(th, jsonData, defaultTitle) {
var
wb
=
new
Workbook
(),
ws
=
sheet_from_array_of_arrays
(
data
);
/*设置worksheet每列的最大宽度*/
const
colWidth
=
data
.
map
(
row
=>
row
.
map
(
val
=>
{
/*判断是否为中文*/
if
(
val
.
toString
().
charCodeAt
(
0
)
>
255
)
{
return
{
'wch'
:
val
.
toString
().
length
*
2
};
}
else
{
return
{
'wch'
:
val
.
toString
().
length
};
}
}))
/*以第一行为初始值*/
let
result
=
colWidth
[
0
];
for
(
let
i
=
1
;
i
<
colWidth
.
length
;
i
++
)
{
for
(
let
j
=
0
;
j
<
colWidth
[
i
].
length
;
j
++
)
{
if
(
result
[
j
][
'wch'
]
<
colWidth
[
i
][
j
][
'wch'
])
{
result
[
j
][
'wch'
]
=
colWidth
[
i
][
j
][
'wch'
];
}
}
}
ws
[
'!cols'
]
=
result
;
/* add worksheet to workbook */
wb
.
SheetNames
.
push
(
ws_name
);
...
...
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