如果要放在mounted里面的话,请参考以下代码:
- mounted() {
- let spread = this.$refs.spread.getSpread();
- let copiedText = "";
- let clipPasted = false;
- let pasteRange;
- spread.bind(GC.Spread.Sheets.Events.ClipboardPasted, function (sender, args) {
- console.log("bind");
- clipPasted = false;
- if (args.pasteData.html != "" && args.pasteData.text != "") {
- clipPasted = true;
- pasteRange = args.cellRange;
- console.log("pasteRange", pasteRange);
- }
- if (!navigator.clipboard) {
- setTextArray(copiedText);
- }
- });
- document.querySelector(".preview-excel").addEventListener('paste', function (event) {
- console.log("paste event");
- if (!navigator.clipboard) {
- if (event.clipboardData) {
- // Classic Edge
- copiedText = event.clipboardData.getData('text');
- } else {
- // IE11
- copiedText = window.clipboardData.getData('text');
- }
- return;
- }
- if (!clipPasted) return;
- // Chrome, FireFox
- let paste = (event.clipboardData || window.clipboardData).getData('text');
-
- setTextArray(paste);
- });
- function setTextArray(paste) {
- var textArray = [];
- var copyText = paste.split('\n');
- for (var i = 0; i < pasteRange.rowCount; i++) {
- var copyRow = copyText[i].replace(/\r/, "").split('\t');
- for (var j = 0; j < copyRow.length; j++) {
- if (copyRow[j] === "") {
- copyRow[j] = null;
- }
- }
- textArray.push(copyRow);
- }
- console.log("pasteRange.row", pasteRange.row);
- console.log("pasteRange.col", pasteRange.col);
- console.log("textArray", textArray);
- spread.getActiveSheet().setArray(pasteRange.row, pasteRange.col, textArray);
- };
- },
复制代码
关于第二个问题,代码中的逻辑是将粘贴的内容转换为了文本进行了处理后再设置到Sheet中,所以仍为1.0000,具体您可以看一下textArray这个变量中存储的值。
|