Code Monkey home page Code Monkey logo

Comments (8)

chfw avatar chfw commented on June 5, 2024 1

You would need to apply a custom filter. At the moment, what you can do is to obtain a sheet instance via get_sheet. Then you can do the following:

>>> import pyexcel as pe
>>> sheet = pe.Sheet([[1,2,3],['','',''],['','',''],[1,2,3]])
>>> sheet
pyexcel sheet:
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
+---+---+---+
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
>>> def filter_row(row):
...     result = [element for element in row if element != '']
...     return len(result)==0
...
>>> sheet.filter(pe.RowValueFilter(filter_row))
>>> sheet
pyexcel sheet:
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+

from flask-excel.

yaoelvon avatar yaoelvon commented on June 5, 2024

Thanks, the following is my way:

excel_data = request.get_records(field_name='file')
not_null_line_data = []
for d in excel_data:
    if all(map(lambda x: x == '', d.values())):
        continue
    not_null_line_data.append(d)

from flask-excel.

yaoelvon avatar yaoelvon commented on June 5, 2024

image
something is wrong...

from flask-excel.

chfw avatar chfw commented on June 5, 2024

Oh... my fault. It should be 'filter' instead of 'apply_filter', which does not exist. See my updated code above.

from flask-excel.

yaoelvon avatar yaoelvon commented on June 5, 2024

Thank you very much. I get it!

from flask-excel.

chfw avatar chfw commented on June 5, 2024

you will have to do this:

book = request.get_book(field_name='file')
book['Sheet1'].filter(...)

from flask-excel.

chfw avatar chfw commented on June 5, 2024

this issue has been a while and the api has changed since. I am starting to forget things.

The simplest way is:

excel_data = request.get_book_dict(field_name='file', skip_empty_row=True)

However, if your sheet data have white spaces, you will need the following solution:

def filter_empty_row(row_index, row_content):
    empty_row = [element for element in row_content if element.strip() != '']
    return len(emtpy_row)  # delete it if True

book = request.get_book(field_name='file')
for sheet in book:
    del sheet.row[filter_empty_row]  # delete the empty lines 

And now we can collapse all code in a simpler form:

book = request.get_book(field_name='file')
for sheet in book:
    del sheet.row[lambda _, row: len([element for element in row if row.strip() != '']) == 0]

from flask-excel.

chfw avatar chfw commented on June 5, 2024

It is my pleasure!

from flask-excel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.