Comments (17)
when i modify my sheet'name to my class name, it works!!
from flask-excel.
It means you have more sheets in your excel file than the number of tables to be written into.
from flask-excel.
from flask-excel.
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.
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.
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.
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.
from flask-excel.
And can you initialize a Logs instance elsewhere (I means outside pyexcel's context)? and how do you initialized one?
from flask-excel.
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.
For the table
from flask-excel.
Thank you, however why am i getting an argument error? I don't understand what i am doing wrong
from flask-excel.
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.
Hi chfw, any news? I use version 0.0.7 and i have same problem :/
from flask-excel.
@LukasSliacky , the problem was resolved offline. Can you briefly describe your problem? How did you get this database adapter not found?
from flask-excel.
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.
Please create a new issue.
from flask-excel.
Related Issues (20)
- Only in wsgi environment, occur response type error HOT 3
- How can I make the query result collection incrementally join the file stream of the flask-excel interface HOT 2
- docs build failure
- Where does Flask-Excel save uploaded file? HOT 2
- How can I used make_response_from_query_sets() where column_names change to new name HOT 3
- Sheet: Category does not match any given tables.Please be aware of case sensitivity. HOT 3
- csv utf8-sig HOT 1
- auto_commit=False in save_to_database and save_book_to_database to allow rollback HOT 3
- IndexError: Index out of range HOT 2
- AttributeError: 'Request' object has no attribute 'get_array' HOT 1
- Interoperability with uWSGI? HOT 8
- How to change the sheet name when using make_response() (or its variants) HOT 2
- Multiple Sheet using Flask Excel HOT 1
- Update existing rows in database HOT 1
- Export Template HOT 1
- New Line HOT 1
- write a csv file using semicolon as delimiter HOT 1
- make_response_from_records sorts keys
- AttributeError for quickstart sample
- SQLAlchemy's Enum-Type unsupported
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-excel.