old generate excel file

PHOTO EMBED

Tue Mar 14 2023 15:11:34 GMT+0000 (Coordinated Universal Time)

Saved by @jassembenrayana

private generateExcelParticipants() {
  let nbAccess = 0 ;
    this.accesss.forEach((access) => {
      if (access.show_in_register == 1) {
        this.userExcelData[0].push(access.name);
        nbAccess++;
      }
    });
    for (let i = 0; i < this.usersInfo.length; i++) {
      this.userExcelData.push([
        this.usersInfo[i].last_name.toUpperCase(),
        Utils.capitalizeFirstLetters(this.usersInfo[i].first_name),
        this.usersInfo[i].email,
        this.usersInfo[i].mobile,
        this.usersInfo[i].gender,
        this.usersInfo[i].payments.length > 0 ? this.usersInfo[i].payments[0].price + "" : "-",
        this.usersInfo[i].country ? this.usersInfo[i].country.name_fr : '-',
        Utils.getLabelONOFF(this.usersInfo[i].user_congresses.length > 0 ? this.usersInfo[i].user_congresses[0].isPresent : 0),
        Utils.getLabelONOFF(this.usersInfo[i].payments.length > 0 ? this.usersInfo[i].payments[0].isPaid : 0),
        this.congress.config_selection || this.congress.congress_type_id == 2 || this.congress.congress_type_id == 1 ? Utils.getUserStatus(this.usersInfo[i].user_congresses[0].isSelected) : '-',
        this.usersInfo[i].profile_img?.path ? environment.filesUrl+this.usersInfo[i].profile_img.path : '-',
        this.usersInfo[i].user_congresses[0].organization ? this.usersInfo[i].user_congresses[0].organization?.name : '-',
        Utils.getFriendlyFormatDate(this.usersInfo[i].user_congresses[0].created_at),
        Utils.getFriendlyFormatDate(this.usersInfo[i].user_congresses[0].updated_at),
        this.usersInfo[i].user_congresses[0].globale_score,
        this.usersInfo[i].user_congresses[0].duration == 0 ? 0 : Utils.formatTimeToHours(this.usersInfo[i].user_congresses[0].duration),
        this.usersInfo[i].packs.length > 0 ? this.usersInfo[i].packs[0]?.label : '-',
        this.usersInfo[i].user_congresses.length > 0  ? this.usersInfo[i].user_congresses[0].is_online == 0 ? 'Non' : 'Oui' : '-',
        this.usersInfo[i].user_congresses.length > 0  && this.usersInfo[i].user_congresses[0].date_scan ? Utils.getFriendlyFormatDate(this.usersInfo[i].user_congresses[0].date_scan) : '-',
        this.usersInfo[i].table.length > 0 ? this.usersInfo[i].table[0].label : ''
      ]);
      this.userExcelData[this.userExcelData.length - 1].push(...Utils.mappingInputResponse(this.formInputs, this.usersInfo[i].responses));
      for (let j = 0; j < this.usersInfo[i].accesses.length; j++) {
        if (this.usersInfo[i].accesses[j].show_in_register === 1) {
          let position = this.userExcelData[0].indexOf(this.usersInfo[i].accesses[j].name);
          if (position != -1) {
            this.userExcelData[this.userExcelData.length - 1][position] = (["x".toUpperCase()]);
          }
        }
      }
    }

    // generate worksheet
    const ws: XLSX.WorkSheet = XLSX.utils.aoa_to_sheet(this.userExcelData);
    // generate workbook and add the worksheet
    const wb: XLSX.WorkBook = XLSX.utils.book_new();
    XLSX.utils.book_append_sheet(wb, ws, "Result");

    // save to file
    XLSX.writeFile(wb, this.congress.name + '-list.xlsx');
    //reset user excel  table
    this.userExcelData = [
      ["last_name", "first_name", "email", "mobile", "gender", "price", "country", "presence", "paiement", "statut", "profile_image", "organisme", "created_at", "updated_at", "globale_score", "total_presence", "pack", "online", "date_scan", "meeting_table"]
    ];
  }
content_copyCOPY