Skip to content

Commit

Permalink
主页面 编辑器 导出表格为csv
Browse files Browse the repository at this point in the history
  • Loading branch information
xushengfeng committed Apr 7, 2024
1 parent 0000226 commit ed1b2ce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"redom": "^4.0.0",
"uiohook-napi": "^1.5.3",
"x11": "^2.3.0",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz",
"xtranslator": "^1.0.6"
},
"devDependencies": {
Expand Down
11 changes: 0 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions src/renderer/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ var store = new Store({
});
import { MainWinType } from "../../ShareTypes";

import { utils as xlsxUtils, writeFile as xlsxWriteFile } from "xlsx";

import closeSvg from "../assets/icons/close.svg";
import reloadSvg from "../assets/icons/reload.svg";

Expand Down Expand Up @@ -546,15 +544,20 @@ document.getElementById("edit_b").onmousedown = (e) => {
switch ((<HTMLElement>e.target).id) {
case "excel_bar":
let text = editor.selections.get();
let t: string[][] = [];
let t: string[] = [];
text.split("\n").forEach((v) => {
let l = v.split("\t");
let l = v
.split("\t")
.map((i) => `"${i}"`)
.join(",");
t.push(l);
});
const worksheet = xlsxUtils.aoa_to_sheet(t);
const workbook = xlsxUtils.book_new();
xlsxUtils.book_append_sheet(workbook, worksheet, "Sheet1");
xlsxWriteFile(workbook, "eSearch.xlsx", { compression: true });
// 下载csv
let blob = new Blob([t.join("\n")], { type: "text/csv" });
let a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = "eSearch.csv";
a.click();
break;
case "md_table_bar":
let table = editor.selections.get();
Expand Down

0 comments on commit ed1b2ce

Please sign in to comment.