|
@@ -2,25 +2,10 @@ import * as XLSX from "xlsx";
|
|
|
import { round, toDegrees } from "./";
|
|
|
import { saveAs } from "./file-serve";
|
|
|
|
|
|
-export const downloadPointsXLSL = async (
|
|
|
- points: number[][],
|
|
|
- desc: { title: string; desc: string }[] = [],
|
|
|
- name: string
|
|
|
-) => {
|
|
|
- const data = await fetch("/template.xls").then((r) => r.arrayBuffer());
|
|
|
+const genXLSLByTemp = (data: ArrayBuffer, tabs: any[][], name: string) => {
|
|
|
const workbook = XLSX.read(data);
|
|
|
const sheetName = workbook.SheetNames[0];
|
|
|
const worksheet = workbook.Sheets[sheetName];
|
|
|
- const tabs = points.map((point, i) => {
|
|
|
- const des = desc[i] || { title: "无", desc: "无" };
|
|
|
- return [
|
|
|
- toDegrees(point[0], 4),
|
|
|
- toDegrees(point[1], 4),
|
|
|
- round(point[2], 4),
|
|
|
- des.title,
|
|
|
- des.desc,
|
|
|
- ];
|
|
|
- });
|
|
|
XLSX.utils.sheet_add_aoa(worksheet, tabs, { origin: "A2" });
|
|
|
|
|
|
const wbout = XLSX.write(workbook, {
|
|
@@ -40,3 +25,36 @@ export const downloadPointsXLSL = async (
|
|
|
});
|
|
|
return saveAs(blob, `${name}.xls`);
|
|
|
};
|
|
|
+
|
|
|
+export const downloadPointsXLSL = async (
|
|
|
+ points: number[][],
|
|
|
+ desc: { title: string; desc: string }[] = [],
|
|
|
+ name: string
|
|
|
+) => {
|
|
|
+ const temps = await Promise.all([
|
|
|
+ fetch("/templaten.xls").then((r) => r.arrayBuffer()),
|
|
|
+ fetch("/本体边界坐标.xls").then((r) => r.arrayBuffer()),
|
|
|
+ ]);
|
|
|
+ const tabsArray = [
|
|
|
+ points.map((point, i) => {
|
|
|
+ const des = desc[i] || { title: "无", desc: "无" };
|
|
|
+ return [i, des.title, toDegrees(point[1], 4), toDegrees(point[0], 4)];
|
|
|
+ }),
|
|
|
+ points.map((point, i) => {
|
|
|
+ const des = desc[i] || { title: "无", desc: "无" };
|
|
|
+ return [
|
|
|
+ toDegrees(point[1], 4),
|
|
|
+ toDegrees(point[0], 4),
|
|
|
+ round(point[2], 4),
|
|
|
+ des.title,
|
|
|
+ des.desc,
|
|
|
+ ];
|
|
|
+ }),
|
|
|
+ ];
|
|
|
+ const names = [name, name + "本体边界坐标"];
|
|
|
+
|
|
|
+ return Promise.all([
|
|
|
+ genXLSLByTemp(temps[0], tabsArray[0], names[0]),
|
|
|
+ genXLSLByTemp(temps[1], tabsArray[1], names[1]),
|
|
|
+ ]);
|
|
|
+};
|