Code Monkey home page Code Monkey logo

Comments (17)

starYellow966 avatar starYellow966 commented on May 26, 2024 2

when i modify my sheet'name to my class name, it works!!

from flask-excel.

chfw avatar chfw commented on May 26, 2024

It means you have more sheets in your excel file than the number of tables to be written into.

from flask-excel.

chfw avatar chfw commented on May 26, 2024

pyexcel/pyexcel-io#42

https://github.com/pyexcel/pyexcel-io/blob/a94f937bba3a13ca952b03cd488c509adf2338ff/pyexcel_io/database/importers/sqlalchemy.py#L85

from flask-excel.

AnastasiaLd avatar AnastasiaLd commented on May 26, 2024

Thank you. The problem is that i have one excel file with one single sheet (is a log file so i won't always be able to identify the sheet name). What i would like, and i don't know if this extensions supports this, is to write certain columns of my file into different tables of my database (col 1, col 2, col 6 into table a / col 8 col 3 into table b...). How would i do this?
Again thank you so much for your help.

from flask-excel.

chfw avatar chfw commented on May 26, 2024

I think you should get a sheet instance from your upload, and then use sheet.Column to choose your columns and then sheet.save_to_database.

from flask-excel.

AnastasiaLd avatar AnastasiaLd commented on May 26, 2024

Thanks but are the initializers required? I am still having problems between my file and my models.
Basically i have an excel/csv file like this (only one sheet/ sheet name changes so i can't indicate it):

Logs.csv
name | phone_num | account_code

Then in my models i have:

class Logs(db.Model):
    __tablename__ = 'Logs'
    id = db.Column(db.Integer, primary_key = True, unique = True)
    name = db.Column(db.String, nullable = False)
    phone_num = db.Column(db.Integer, nullable = False)
    account_code = db.Column(db.VARCHAR(120), nullable = True)

#My table has no foreign keys or dependencies from other tables

    def __init__(**kwargs):
        super(Rates, self).__init__(**kwargs)

This is in my views.py file:

@upload.route('/upload', methods = ['GET', 'POST'])
def upload_new_cdr():
	form = UploadForm()
	if form.validate_on_submit():

		#Get a sheet instance
		uploaded_file = request.get_sheet(field_name = 'upload')

		#Select columns by name
		uploaded_file.name_columns_by_row(0)
		uploaded_file.column.select(['name' , 'phone_num', 'account_code',])
                #This works fine an it prints
                name | phone_num | account_code
                Ana     5567584         112
                Lana   995588            122
                Diana  676768            130
		print uploaded_file

		#Save to database
                #This is where it fails (i have both tried to put and not the initializers)
		uploaded_file.save_to_database(session = db.session, table = Logs)
		return 'SAVED!'

	return render_template('upload/upload.html', form=form)

I get an argment error from pyexcel_io and i am not sure what argument am i missing or what's happening:

TypeError: init() takes exactly 0 arguments (1 given)

Erro line:

        if self._native_sheet.row_initializer:

            # allow initinalizer to return None

            # if skipping is needed

            obj = self._native_sheet.row_initializer(row)

        if obj is None:

            obj = self._native_sheet.table() #<--- ERROR -->

            for name in self._native_sheet.column_names:

                if self._native_sheet.column_name_mapping_dict is not None:

                    key = self._native_sheet.column_name_mapping_dict[name]

                else:

                    key = name

Really sorry for this many questions( and for the begginer mistakes)

from flask-excel.

chfw avatar chfw commented on May 26, 2024

Why is this?

#My table has no foreign keys or dependencies from other tables

    def __init__(**kwargs):
        super(Rates, self).__init__(**kwargs)

And can you initialize a Logs instance elsewhere (I means outside pyexcel's context)? and how do you initialized one?

from flask-excel.

AnastasiaLd avatar AnastasiaLd commented on May 26, 2024

from flask-excel.

chfw avatar chfw commented on May 26, 2024

And can you initialize a Logs instance elsewhere (I means outside pyexcel's context)? and how do you initialized one?

from flask-excel.

AnastasiaLd avatar AnastasiaLd commented on May 26, 2024

When i indicate an initializer i use this:

		def logs_init_func(row):
			logs = Caller(row['name'], row['phone_num'],
			, row['account_code'])
			return caller

		uploaded_file.save_to_database(
            session=db.session,
            table=Logs,
            initializer=caller_init_func)

Not sure however if the initializing functions are for the tables or for the sheet?
By doing that i still get an argument error, same as if i don't use the initializer.

Models
class Logs(db.Model):
tablename = 'Logs'
id = db.Column(db.Integer, primary_key = True, unique = True)
name = db.Column(db.VARCHAR(256), nullable = False)
phonw_number = db.Column(db.VARCHAR, nullable = False)
account_code = db.Column(db.Integer, nullable = False)

In models.py

def __init__(**kwargs):
        super(Logs, self).__init__(**kwargs)

from flask-excel.

chfw avatar chfw commented on May 26, 2024

For the table

from flask-excel.

AnastasiaLd avatar AnastasiaLd commented on May 26, 2024

Thank you, however why am i getting an argument error? I don't understand what i am doing wrong

from flask-excel.

chfw avatar chfw commented on May 26, 2024

Could you please post me all the code about class Logs? You can email me the code to [email protected] if you want some privacy around your code. I don't think it is rocket science.

from flask-excel.

LukasSliacky avatar LukasSliacky commented on May 26, 2024

Hi chfw, any news? I use version 0.0.7 and i have same problem :/

from flask-excel.

chfw avatar chfw commented on May 26, 2024

@LukasSliacky , the problem was resolved offline. Can you briefly describe your problem? How did you get this database adapter not found?

from flask-excel.

juso avatar juso commented on May 26, 2024

Sorry for writing in already close issue, but I think it's the best place since I face the same issue while running flask-excel examples (database_example.py and database_example_formatted.py) in python3. Let me know if it's better to open a new issue on this matter.

from flask-excel.

chfw avatar chfw commented on May 26, 2024

Please create a new issue.

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.