Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
admin-fe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pleroma
admin-fe
Commits
a8602e78
Commit
a8602e78
authored
7 years ago
by
spiritree
Committed by
花裤衩
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refine:export adaptive colwidth in excel
parent
516897b9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/vendor/Export2Excel.js
+19
-1
19 additions, 1 deletion
src/vendor/Export2Excel.js
with
19 additions
and
1 deletion
src/vendor/Export2Excel.js
+
19
−
1
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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment