Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wangzishuai5499
js-xlsx
提交
9add78a2
J
js-xlsx
项目概览
wangzishuai5499
/
js-xlsx
与 Fork 源项目一致
从无法访问的项目Fork
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
js-xlsx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9add78a2
编写于
7月 07, 2020
作者:
S
Srijon Saha
提交者:
Srijon Saha
7月 07, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix write not working and refactor
[ci skip]
上级
57b296e5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
73 addition
and
88 deletion
+73
-88
demos/electron/index.html
demos/electron/index.html
+3
-3
demos/electron/index.js
demos/electron/index.js
+70
-85
未找到文件。
demos/electron/index.html
浏览文件 @
9add78a2
...
...
@@ -26,12 +26,12 @@ a { text-decoration: none }
<a
href=
"https://github.com/SheetJS/js-xlsx"
>
Source Code Repo
</a>
<a
href=
"https://github.com/SheetJS/js-xlsx/issues"
>
Issues? Something look weird? Click here and report an issue
</a>
<br
/>
<button
id=
"read
f
"
>
Click here to select a file from your computer
</button><br
/>
<button
id=
"read
Btn
"
>
Click here to select a file from your computer
</button><br
/>
<div
id=
"drop"
>
Drop a spreadsheet file here to see sheet data
</div>
<input
type=
"file"
name=
"xlfile"
id=
"
xlf
"
/>
... or click here to select a file
<input
type=
"file"
name=
"xlfile"
id=
"
readIn
"
/>
... or click here to select a file
</pre>
<p><input
type=
"submit"
value=
"Export Data!"
id=
"
xport"
onclick=
"export_xlsx();
"
disabled=
"true"
></p>
<p><input
type=
"submit"
value=
"Export Data!"
id=
"
exportBtn
"
disabled=
"true"
></p>
<div
id=
"htmlout"
></div>
<br
/>
<script
src=
"index.js"
></script>
...
...
demos/electron/index.js
浏览文件 @
9add78a2
/* xlsx.js (C) 2013-present SheetJS -- https://sheetjs.com */
/* global Uint8Array, console */
/* exported export_xlsx */
/* eslint no-use-before-define:0 */
var
XLSX
=
require
(
'
xlsx
'
);
var
electron
=
require
(
'
electron
'
).
remote
;
const
XLSX
=
require
(
'
xlsx
'
);
const
electron
=
require
(
'
electron
'
).
remote
;
var
process_wb
=
(
function
()
{
var
HTMLOUT
=
document
.
getElementById
(
'
htmlout
'
);
var
XPORT
=
document
.
getElementById
(
'
xport
'
);
const
EXTENSIONS
=
"
xls|xlsx|xlsm|xlsb|xml|csv|txt|dif|sylk|slk|prn|ods|fods|htm|html
"
.
split
(
"
|
"
);
return
function
process_wb
(
wb
)
{
XPORT
.
disabled
=
false
;
HTMLOUT
.
innerHTML
=
""
;
wb
.
SheetNames
.
forEach
(
function
(
sheetName
)
{
var
htmlstr
=
XLSX
.
utils
.
sheet_to_html
(
wb
.
Sheets
[
sheetName
],{
editable
:
true
});
HTMLOUT
.
innerHTML
+=
htmlstr
;
});
};
})();
const
processWb
=
function
(
wb
)
{
const
HTMLOUT
=
document
.
getElementById
(
'
htmlout
'
);
const
XPORT
=
document
.
getElementById
(
'
exportBtn
'
);
XPORT
.
disabled
=
false
;
HTMLOUT
.
innerHTML
=
""
;
wb
.
SheetNames
.
forEach
(
function
(
sheetName
)
{
const
htmlstr
=
XLSX
.
utils
.
sheet_to_html
(
wb
.
Sheets
[
sheetName
],{
editable
:
true
});
HTMLOUT
.
innerHTML
+=
htmlstr
;
});
};
var
do_file
=
(
function
()
{
return
function
do_file
(
files
)
{
var
f
=
files
[
0
];
var
reader
=
new
FileReader
();
reader
.
onload
=
function
(
e
)
{
var
data
=
e
.
target
.
result
;
data
=
new
Uint8Array
(
data
);
process_wb
(
XLSX
.
read
(
data
,
{
type
:
'
array
'
}));
};
reader
.
readAsArrayBuffer
(
f
);
const
readFile
=
function
(
files
)
{
const
f
=
files
[
0
];
const
reader
=
new
FileReader
();
reader
.
onload
=
function
(
e
)
{
let
data
=
e
.
target
.
result
;
data
=
new
Uint8Array
(
data
);
processWb
(
XLSX
.
read
(
data
,
{
type
:
'
array
'
}));
};
})();
(
function
()
{
var
drop
=
document
.
getElementById
(
'
drop
'
);
function
handleDrop
(
e
)
{
e
.
stopPropagation
();
e
.
preventDefault
();
do_file
(
e
.
dataTransfer
.
files
);
}
reader
.
readAsArrayBuffer
(
f
);
};
function
handleDragover
(
e
)
{
e
.
stopPropagation
();
e
.
preventDefault
();
e
.
dataTransfer
.
dropEffect
=
'
copy
'
;
}
const
handleReadBtn
=
async
function
()
{
const
o
=
await
electron
.
dialog
.
showOpenDialog
({
title
:
'
Select a file
'
,
filters
:
[{
name
:
"
Spreadsheets
"
,
extensions
:
EXTENSIONS
}],
properties
:
[
'
openFile
'
]
});
if
(
o
.
filePaths
.
length
>
0
)
processWb
(
XLSX
.
readFile
(
o
.
filePaths
[
0
]));
};
drop
.
addEventListener
(
'
dragenter
'
,
handleDragover
,
false
);
drop
.
addEventListener
(
'
dragover
'
,
handleDragover
,
false
);
drop
.
addEventListener
(
'
drop
'
,
handleDrop
,
false
);
})();
const
exportXlsx
=
async
function
()
{
const
HTMLOUT
=
document
.
getElementById
(
'
htmlout
'
);
const
wb
=
XLSX
.
utils
.
table_to_book
(
HTMLOUT
);
const
o
=
await
electron
.
dialog
.
showSaveDialog
({
title
:
'
Save file as
'
,
filters
:
[{
name
:
"
Spreadsheets
"
,
extensions
:
EXTENSIONS
}]
});
console
.
log
(
o
.
filePath
);
XLSX
.
writeFile
(
wb
,
o
.
filePath
);
electron
.
dialog
.
showMessageBox
({
message
:
"
Exported data to
"
+
o
.
filePath
,
buttons
:
[
"
OK
"
]
});
};
(
function
()
{
var
readf
=
document
.
getElementById
(
'
readf
'
);
async
function
handleF
(
/*e*/
)
{
var
o
=
await
electron
.
dialog
.
showOpenDialog
({
title
:
'
Select a file
'
,
filters
:
[{
name
:
"
Spreadsheets
"
,
extensions
:
"
xls|xlsx|xlsm|xlsb|xml|xlw|xlc|csv|txt|dif|sylk|slk|prn|ods|fods|uos|dbf|wks|123|wq1|qpw|htm|html
"
.
split
(
"
|
"
)
}],
properties
:
[
'
openFile
'
]
});
if
(
o
.
filePaths
.
length
>
0
)
process_wb
(
XLSX
.
readFile
(
o
.
filePaths
[
0
]));
}
readf
.
addEventListener
(
'
click
'
,
handleF
,
false
);
})();
// add event listeners
const
readBtn
=
document
.
getElementById
(
'
readBtn
'
);
const
readIn
=
document
.
getElementById
(
'
readIn
'
);
const
exportBtn
=
document
.
getElementById
(
'
exportBtn
'
);
const
drop
=
document
.
getElementById
(
'
drop
'
);
(
function
()
{
var
xlf
=
document
.
getElementById
(
'
xlf
'
);
function
handleFile
(
e
)
{
do_file
(
e
.
target
.
files
);
}
xlf
.
addEventListener
(
'
change
'
,
handleFile
,
false
);
})();
var
export_xlsx
=
(
function
()
{
var
HTMLOUT
=
document
.
getElementById
(
'
htmlout
'
);
var
XTENSION
=
"
xls|xlsx|xlsm|xlsb|xml|csv|txt|dif|sylk|slk|prn|ods|fods|htm|html
"
.
split
(
"
|
"
)
return
async
function
()
{
var
wb
=
XLSX
.
utils
.
table_to_book
(
HTMLOUT
);
var
o
=
await
electron
.
dialog
.
showSaveDialog
({
title
:
'
Save file as
'
,
filters
:
[{
name
:
"
Spreadsheets
"
,
extensions
:
XTENSION
}]
});
console
.
log
(
o
.
filePath
);
XLSX
.
writeFile
(
wb
,
o
.
filePath
);
electron
.
dialog
.
showMessageBox
({
message
:
"
Exported data to
"
+
o
.
filePath
,
buttons
:
[
"
OK
"
]
});
};
})();
void
export_xlsx
;
readBtn
.
addEventListener
(
'
click
'
,
handleReadBtn
,
false
);
readIn
.
addEventListener
(
'
change
'
,
(
e
)
=>
{
readFile
(
e
.
target
.
files
);
},
false
);
exportBtn
.
addEventListener
(
'
click
'
,
exportXlsx
,
false
);
drop
.
addEventListener
(
'
dragenter
'
,
(
e
)
=>
{
e
.
stopPropagation
();
e
.
preventDefault
();
e
.
dataTransfer
.
dropEffect
=
'
copy
'
;
},
false
);
drop
.
addEventListener
(
'
dragover
'
,
(
e
)
=>
{
e
.
stopPropagation
();
e
.
preventDefault
();
e
.
dataTransfer
.
dropEffect
=
'
copy
'
;
},
false
);
drop
.
addEventListener
(
'
drop
'
,
(
e
)
=>
{
e
.
stopPropagation
();
e
.
preventDefault
();
readFile
(
e
.
dataTransfer
.
files
);
},
false
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录