Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voting: import of voters from CSV/Excel #46

Closed
uatisdeproblem opened this issue Dec 22, 2023 · 2 comments
Closed

Voting: import of voters from CSV/Excel #46

uatisdeproblem opened this issue Dec 22, 2023 · 2 comments
Assignees

Comments

@uatisdeproblem
Copy link
Owner

uatisdeproblem commented Dec 22, 2023

The placeholder button is already in place. More or less, this is the expected result:

Screenshot 2023-12-22 at 19 50 37

Everything must happen front-end.

If possible, let's also add the export of the same list.

Note: the maximum amount of voters is 1000.

The import substitute the previous values (i.e., remove all → import).

@uatisdeproblem uatisdeproblem mentioned this issue Dec 22, 2023
@uatisdeproblem
Copy link
Owner Author

On a branch of the branch voting (coming soon).

@uatisdeproblem
Copy link
Owner Author

If possible, let's use Sheet.js (aka XLSX): https://docs.sheetjs.com/docs/getting-started/installation/nodejs. 🙂

Example export:

  private downloadDataAsExcel(flatData: any[], title: string): any {
    // prepare the Excel's workbook
    const wb: WorkBook = { SheetNames: [], Sheets: {}, Props: { Title: title, Author: env.idea.app.title } };
    // add the spreadsheet with users data to the workbook
    utils.book_append_sheet(wb, utils.json_to_sheet(flatData), '1');
    // generate a buffer of the Excel file
    return writeFile(wb, title.concat('.xlsx'));
  }

Example import

private parseRecordsFromExcel(excelContent: File): any[] {
    try {
      const workbook = read(excelContent, { type: 'binary' });
      // acquire the header in a preliminar step,
      // to avoid a bug that occurs when the last column of the first not-header row is empty
      const header = utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]], { raw: true, header: 1 })[0];
      // acquire the rows, forcing the header read in the first row
      const rows = utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]], {
        raw: true,
        header: header as any,
        defval: '',
        range: 1 // skip header row
      });
      return rows;
    } catch (err) {
      return [];
    }
  }

uatisdeproblem added a commit that referenced this issue Dec 28, 2023
uatisdeproblem added a commit that referenced this issue Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants