pc4xlsl.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { round, toDegrees } from "./";
  2. import { saveAs } from "./file-serve";
  3. import * as URL from "@/request/URL";
  4. import { basePath, gHeaders } from "@/request/state";
  5. // const genXLSLByTemp = (data: ArrayBuffer, tabs: any[][], name: string) => {
  6. // const workbook = XLSX.read(data, {
  7. // type: "binary",
  8. // cellStyles: true,
  9. // cellNF: true,
  10. // cellDates: true,
  11. // sheetStubs: true,
  12. // raw: true,
  13. // bookDeps: true,
  14. // bookVBA: true,
  15. // // bookProps: true,
  16. // // bookSheets: true,
  17. // WTF: true,
  18. // PRN: true,
  19. // xlfn: true,
  20. // });
  21. // const sheetName = workbook.SheetNames[0];
  22. // const worksheet = workbook.Sheets[sheetName];
  23. // XLSX.utils.sheet_add_aoa(worksheet, tabs, { origin: "A2" });
  24. // const wbout = XLSX.writeFile(workbook, `${name}.xlsx`);
  25. // return saveAs(wbout, `${name}.xlsx`);
  26. // };
  27. export const downloadPointsXLSL1 = async (
  28. points: number[][],
  29. desc: { title: string; desc: string }[] = [],
  30. name: string
  31. ) => {
  32. const tabs = points.map((point, i) => {
  33. const des = desc[i] || { title: "无", desc: "无" };
  34. return {
  35. fid: i.toString(),
  36. name: des.title,
  37. latitude: toDegrees(point[1], 4),
  38. longitude: toDegrees(point[0], 4),
  39. };
  40. });
  41. const data = await fetch(basePath + URL.exportVectorData, {
  42. headers: gHeaders,
  43. method: "post",
  44. body: JSON.stringify(tabs),
  45. }).then((res) => res.blob());
  46. return saveAs(data, `${name}.xls`);
  47. };
  48. export const downloadPointsXLSL2 = async (
  49. points: number[][],
  50. desc: { title: string; desc: string }[] = [],
  51. name: string
  52. ) => {
  53. const tabs = points.map((point, i) => {
  54. const des = desc[i] || { title: "无", desc: "无" };
  55. return {
  56. latitude: toDegrees(point[1], 4),
  57. longitude: toDegrees(point[0], 4),
  58. altitude: round(point[2], 4),
  59. description: des.title,
  60. remark: des.desc,
  61. };
  62. });
  63. const data = await fetch(basePath + URL.exportCoordinateData, {
  64. headers: gHeaders,
  65. method: "post",
  66. body: JSON.stringify(tabs),
  67. }).then((res) => res.blob());
  68. return saveAs(data, `${name}.xls`);
  69. };
  70. export const downloadPointsXLSL = async (
  71. points: number[][],
  72. desc: { title: string; desc: string }[] = [],
  73. name: string
  74. ) => {
  75. downloadPointsXLSL1(points, desc, name);
  76. downloadPointsXLSL2(points, desc, name + "本体边界坐标");
  77. };