Angular CSV import error

Asked

Viewed 49 times

1

I have a ". csv" standard that I make available to the client to download, fill and after completing the fill, import to the platform.

It turns out that CSV when opened by excel, creates an empty line at the end of the file, which I could only see opening in a simple text editor, after closing and saving in excel.

When I import the platform, it breaks and returns me error. I go there in the file again through the text editor, delete the last line and ready. Works normal.

I want to try to make my code disregard any empty space after the last character of csv, not "comma". Or validating if there are blank lines and just disregard them.

Follows code: Use createUser pq implemented the component to validate if there is already a user with the sent registration

onEventSubmit(userList: User[]) {
this.modalService.close(this.importFormId);
if (userList) {
  userList.forEach(userInstance => {
    this.userService.createUser(userInstance).subscribe(
      _ => {
        this.refreshDatatable(),
          this.alertService.success('Cadastro bem sucedido');
      },
      error => {
        this.alertService.error(
          'Verifique seu CSV',
          'Erro ao cadastrar usuário'
        );
      }
    );
  });
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.