Ho un foglio excel pieno di dati. Voglio gli stessi dati nella tabella del database sqlite. Attualmente devo inserire manualmente il campo 1 per 1. Esiste un modo per dirigere l'esportazione dei dati nella tabella del database sqlite?esportazione dati da excel a database sqlite
risposta
Il tuo percorso è in formato CSV (devi esportare i tuoi dati in formato CSV), vedi di più qui ad esempio.
Questo sito converte i file di Excel in file SQLite http://converttosqlite.com/
Questo sito converte in sqlite2 che non è compatibile con sqlite3! – MOHRE
C'è anche uno script python (xl2sqlite.py) che farà il lavoro.
Prova questo codice fresca exceltosql:
'''
This code uses the openpyxl package for playing around with excel using Python code
to convert complete excel workbook (all sheets) to an SQLite database
The code assumes that the first row of every sheet is the column name
Every sheet is stored in a separate table
The sheet name is assigned as the table name for every sheet
'''
import sqlite3
import openpyxl
from openpyxl import load_workbook
import re
def slugify(text, lower=1):
if lower == 1:
text = text.strip().lower()
text = re.sub(r'[^\w _-]+', '', text)
text = re.sub(r'[- ]+', '_', text)
return text
#Replace with a database name
con = sqlite3.connect('test.db')
#replace with the complete path to youe excel workbook
wb = load_workbook(filename=r'abc.xlsx')
sheets = wb.get_sheet_names()
for sheet in sheets:
ws = wb[sheet]
columns= []
query = 'CREATE TABLE ' + str(slugify(sheet)) + '(ID INTEGER PRIMARY KEY AUTOINCREMENT'
for row in ws.rows[0]:
query += ', ' + slugify(row.value) + ' TEXT'
columns.append(slugify(row.value))
query += ');'
con.execute(query)
tup = []
for i, rows in enumerate(ws):
tuprow = []
if i == 0:
continue
for row in rows:
tuprow.append(unicode(row.value).strip()) if unicode(row.value).strip() != 'None' else tuprow.append('')
tup.append(tuple(tuprow))
insQuery1 = 'INSERT INTO ' + str(slugify(sheet)) + '('
insQuery2 = ''
for col in columns:
insQuery1 += col + ', '
insQuery2 += '?, '
insQuery1 = insQuery1[:-2] + ') VALUES('
insQuery2 = insQuery2[:-2] + ')'
insQuery = insQuery1 + insQuery2
con.executemany(insQuery, tup)
con.commit()
con.close()
Funziona benissimo, ma deve essere modificato "per la riga in ws.rows [0]:" a "per la riga successiva (ws.rows):" nella riga 33. Grazie! – Zalakain
- 1. Esportazione da PHP a Excel
- 2. Esportazione dei dati da R a Excel: formule non ricalcolare
- 3. esportazione sqlite in csv
- 4. JavaScript - esportazione dati tabella HTML in Excel
- 5. Convertire da infissi dati Database/Excel/CSV a YAML?
- 6. Esportazione Excel file da visualizzare (MVC)
- 7. esportazione in Excel C#
- 8. Esportazione da maiale a CSV
- 9. Database di esportazione MSSQL con dati
- 10. Esportazione da SQL Server a Excel con intestazioni di colonna?
- 11. Esportazione di database SQLite in file csv in Android
- 12. Esportazione di dati MySQL in Excel/CSV tramite php
- 13. Esportazione dei dati dei difetti QC HP in Excel
- 14. Esportare dati da un DBGrid a Excel
- 15. Come memorizzare i dati da edittext al database SQL sqlite?
- 16. esportazione dei dati in un file CSV - Excel VBA
- 17. Problemi di esportazione di un file Excel da Crystal Reports
- 18. dati Esportazione in cellule specifiche in foglio di Excel
- 19. Come leggere i dati dal database SQLite?
- 20. php esportazione in Excel non mostrare griglia
- 21. Laravel Excel, esportazione da un modello, problemi di stile
- 22. problemi RadGrid Telerik con esportazione in Excel
- 23. Come accedere a SQLite da VBA?
- 24. Inserimento a database utilizzando SQLite in xcode4.6
- 25. esportazione IEnumerable <T> in Excel
- 26. Importazione dati da Excel in PHP
- 27. Esportazione di un ListView in formato Excel
- 28. ASP.NET Problema di codifica esportazione Excel
- 29. Esporta dati SQLite in Excel in iOS a livello di programmazione
- 30. SQLite formati da lunghi a larghi?
Usa SQLite Expert Professional 3 –
Eventuali duplicati di [Importa CSV per SQLite] (http://stackoverflow.com/questions/14947916/import-csv-to- sqlite) – zero323