Replies: 1 comment
-
I added excel export myself using https://github.com/estie-inc/wasm-xlsxwriter Here's a basic version that creates an excel table out of a perspective view, rendering it in the worksheet (without support for grouped cols) import type { View } from "@finos/perspective";
import xlsxInit, { Workbook, Table, TableColumn } from "wasm-xlsxwriter/web";
async function toExcel(view: View, sheetName: string) {
await xlsxInit();
const workbook = new Workbook();
const worksheet = workbook.addWorksheet();
worksheet.setName(sheetName);
const table = new Table();
const data = (await view.to_columns()) as Record<string, Array<unknown>>;
const columns: TableColumn[] = [];
const dataRowIndexStart = 2; // 3rd row;
const dataColIndexStart = 1; // 2nd col;
Object.entries(data).forEach(([columnName, value], index) => {
const tblCol = new TableColumn().setHeader(columnName);
columns.push(tblCol);
worksheet.writeColumn(
dataRowIndexStart,
index + dataColIndexStart,
// TODO: Handle other types
value,
);
});
const rows = await view.num_rows();
const cols = await view.num_columns();
const tbl = table.setName(sheetName).setColumns(columns);
worksheet.addTable(
dataRowIndexStart - 1,
dataColIndexStart,
dataRowIndexStart + rows - 1,
dataColIndexStart + cols - 1,
tbl,
);
return workbook.saveToBufferSync();
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently it's difficult to export data from perspective to excel since excel by default cannot guess separators in the csv, it uses a fixed separator based on the region/language which doesn't work for non-US installations.
For many people excel is the only tool to open csv's.
This can be solved by either a dedicated excel export or a csv format that excel can open easily in different regions/languages.
Beta Was this translation helpful? Give feedback.
All reactions