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

error when reading worksheets, the indexes of the columns read in dart do not match excel, it is as if the columns change order randomly #159

Closed
insinfo opened this issue May 31, 2022 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@insinfo
Copy link
Contributor

insinfo commented May 31, 2022

error when reading spreadsheets, the indexes of the columns read in dart do not match excel, which makes it impossible to import to the database because there is inconsistency, it is as if the columns change order randomly.

given this worksheet.

image

AUTO DE INFRACAO e AUTO DE CONSTATACAO.xlsx

the reading result is this: see that the columns do not match

image

void main(List<String> args) async {

  var spreadsheetFilePath =
      'C:/MyDartProjects/notifis/notifis_backend/db/planilhas/AUTO DE INFRACAO e AUTO DE CONSTATACAO.xlsx';
  var bytes = File(spreadsheetFilePath).readAsBytesSync();
  var excel = Excel.decodeBytes(bytes);
  var worksheetsNames = excel.tables.keys;
  for (var sheetName in worksheetsNames) {
    
    if (sheetName == 'AUTO DE INFRACAO') {
      var sheet = excel.tables[sheetName];
      var sheetRows = sheet.rows;
      var rowsLength = sheetRows.length;

      for (var idx = 0; idx < rowsLength; idx++) {
        var row = sheetRows[idx];
        // print(" ${row.map((e) => '${e?.value}').join(' | ')}");
        print(
            "${row[0]?.value} | ${row[1]?.value} | ${row[2]?.value} | ${row[3]?.value} | ${row[4]?.value} | ${row[5]?.value} | ${row[6]?.value} | ${row[7]?.value} | ${row[8]?.value}");
      
      }
      break;
    }    
  }
  exit(0);
}

the column with the value "ENEL" was supposed to be in index 2 but to be in index 4, there is also a confusion regarding row data appearing in the wrong row and wrong column.

@alexandremcp
Copy link

The Lib is experiencing errors when importing the data, shuffling the information displaying in incorrect order.

@ldsouza93
Copy link

same problem here

@justkawal
Copy link
Owner

Sorry for the trouble.
Can you please confirm that are you having this trouble in latest version: excel: 2.0.1

@YancyHsu
Copy link

YancyHsu commented Feb 4, 2023

Sorry for the trouble. Can you please confirm that are you having this trouble in latest version: excel: 2.0.1

version 2.0.1 has the problem

@DaKar00
Copy link

DaKar00 commented Feb 14, 2023

i am working on a project to extract some data from an excel file, when the project was almost done i noticed that some rows had "shifted" the array one step and was giving me the data from the wrong cell. I have tried changeing the data in the excel file, changed the order of the rows but it just wont give me the correct data, at this point i dont know how to proceed. Is there a another package i can try?

@navyzhou926

This comment was marked as duplicate.

@marcoredz

This comment was marked as duplicate.

@youssefhegab14

This comment was marked as duplicate.

@danielR2001

This comment was marked as duplicate.

@insinfo
Copy link
Contributor Author

insinfo commented May 24, 2023

@FauconSpartiate @justkawal @take4blue any updates?

@FauconSpartiate
Copy link
Collaborator

Nope, but any help from anyone that is motivated is welcome 👍

@FauconSpartiate
Copy link
Collaborator

FauconSpartiate commented May 30, 2023

@YancyHsu @insinfo @danielR2001 @youssefhegab14 @marcoredz @navyzhou926 @DaKar00 @ldsouza93

I managed to reproduce the error with the test file on the original comment, but only on 2.0.0-null-safety-3. On all versions since 2.0.1, the columns seem to be at the right index.
Are you sure that you're using the latest version of the package? Are you using the correct version dependency excel: ^2.0.0 in your pubspec.yaml and have executed flutter pub upgrade in your terminal?
If yes, could you provide another file where the issue is still reproducible?

@FauconSpartiate
Copy link
Collaborator

Closing, as this has been fixed.

@insinfo
Copy link
Contributor Author

insinfo commented Oct 28, 2023

I just did a test with version 3.0.0 and it seems to be working correctly now

image

image

import 'dart:io';
import 'package:excel/excel.dart';
import 'package:http/http.dart' as http;

void main(List<String> args) async {
  final url =
      'https://github.com/justkawal/excel/files/8808016/AUTO.DE.INFRACAO.e.AUTO.DE.CONSTATACAO.xlsx';
  final resp = await http.get(Uri.parse(url));

  final bytes = resp.bodyBytes;
  final excel = Excel.decodeBytes(bytes);
  final worksheetsNames = excel.tables.keys;
  for (var sheetName in worksheetsNames) {
    if (sheetName == 'AUTO DE INFRACAO') {
      final sheet = excel.tables[sheetName]!;
      final sheetRows = sheet.rows;
      final rowsLength = sheetRows.length;

      for (var idx = 0; idx < rowsLength; idx++) {
        final row = sheetRows[idx];
        // print(" ${row.map((e) => '${e?.value}').join(' | ')}");
        print(
            '${row[0]?.value} | ${row[1]?.value} | ${row[2]?.value} | ${row[3]?.value} | ${row[4]?.value} | ${row[5]?.value} | ${row[6]?.value} | ${row[7]?.value} | ${row[8]?.value}');
      }
      break;
    }
  }
  exit(0);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests