xlsx2csv icon indicating copy to clipboard operation
xlsx2csv copied to clipboard

Function only reading filtered rows. How do I read all rows from a sheet?

Open abhi250372 opened this issue 3 years ago • 13 comments

Here is my code - filepath = os.path.join(FolderPath, FileName) a = load_workbook(filepath, read_only=True)

def read_excel_file(path: str, sheet_index: int) -> pd.DataFrame: buffer = StringIO() Xlsx2csv(path, outputencoding="utf8").convert(buffer,sheetid=sheet_index) buffer.seek(0) df = pd.read_csv(buffer) return df

dfinal=read_excel_file(filepath,a.index(a.get_sheet_by_name('Sheetname'))+1)

abhi250372 avatar Dec 15 '22 01:12 abhi250372

I am using XLSX2CSV because it is faster in reading excel files as compared to read_excel() from openpyxl. But using XLSX2CSV only reads filtered rows of a sheet whereas read_excel reads all rows regardless if the sheet is filtered or not.

abhi250372 avatar Dec 15 '22 01:12 abhi250372

Hello, I have just experimented it also. Is there a way/option that XLSX2CSV would read all rows of a sheet ?

tongngo avatar Dec 21 '22 17:12 tongngo

what is a filtered row? can you share a sample xlsx file?

serene-dev avatar Dec 21 '22 18:12 serene-dev

In the attached file, ColumnA is filtering rows only showing 'A' value in ColumnA (not showing the rows beginning with 'B' value) The xlsx2csv would only convert the visible rows, not all rows as Excel would do. Samplefile.xlsx

tongngo avatar Dec 21 '22 18:12 tongngo

Here is another example. The openpyxl function returns all rows regardless if the sheet is pre filtered or not but the XLSX2CSV only returns the pre filtered rows.

Abhishek

On Wed, 21 Dec 2022 at 12:08, TongsasTong @.***> wrote:

In the attached file, ColumnA is filtering rows only showing 'A' value in ColumnA (not showing the rows beginning with 'B' value) The xlsx2csv would only convert the visible rows, not all rows as Excel would do. Samplefile.xlsx https://github.com/dilshod/xlsx2csv/files/10280128/Samplefile.xlsx

— Reply to this email directly, view it on GitHub https://github.com/dilshod/xlsx2csv/issues/246#issuecomment-1361789157, or unsubscribe https://github.com/notifications/unsubscribe-auth/A4YGWD75OHFZGECCBFZEN7TWONBR7ANCNFSM6AAAAAAS7F2HWU . You are receiving this because you authored the thread.Message ID: @.***>

abhi250372 avatar Dec 21 '22 23:12 abhi250372

Here is sample file Car.xlsx

abhi250372 avatar Dec 22 '22 14:12 abhi250372

Looks like dilshod has fixed the issue. I downloaded the xlsx2csvc.py file in the repository and replaced the old file in my local machine with this new one. I added the skip_hidden_rows as False in my function mentioned above and now it works. However, I need to know when this version will be available via pip install command so that all the users can get the updated version instead of manually downloading this file. Can someone please help with that? def read_excel_file(path: str, sheet_index: int) -> pd.DataFrame: buffer = StringIO() Xlsx2csv(path, outputencoding="utf-8",skip_hidden_rows = False).convert(buffer,sheetid = sheet_index) buffer.seek(0) df = pd.read_csv(buffer) return df

abhi250372 avatar Dec 23 '22 23:12 abhi250372

Looks like dilshod has fixed the issue. I downloaded the xlsx2csvc.py file in the repository and replaced the old file in my local machine with this new one. I added the skip_hidden_rows as False in my function mentioned above and now it works. However, I need to know when this version will be available via pip install command so that all the users can get the updated version instead of manually downloading this file. Can someone please help with that? def read_excel_file(path: str, sheet_index: int) -> pd.DataFrame: buffer = StringIO() Xlsx2csv(path, outputencoding="utf-8",skip_hidden_rows = False).convert(buffer,sheetid = sheet_index) buffer.seek(0) df = pd.read_csv(buffer) return df

Thank you again @dilshod !!

tongngo avatar Dec 26 '22 16:12 tongngo

@dilshod When will the latest version be released so that I can do pip install?

abhi250372 avatar Dec 29 '22 18:12 abhi250372

@dilshod is there an update on this?

abhi250372 avatar Jan 07 '23 00:01 abhi250372

It is available via pip now, this issue can be closed!

hendrikschafer avatar May 26 '23 13:05 hendrikschafer

I think skip_hidden_rows=False should be the default. Nobody expects filtered rows to be removed when reading an Excel.

mcrumiller avatar Jun 27 '23 13:06 mcrumiller

I think skip_hidden_rows=False should be the default. Nobody expects filtered rows to be removed when reading an Excel.

Yes, also, this is the default beahvior of excel when saviong to csv file

tongngo avatar Jun 27 '23 13:06 tongngo