Created
January 1, 2019 22:17
-
-
Save JasonCrowe/1a8e063ae56900aa4ce81f90aa41030e to your computer and use it in GitHub Desktop.
Snippet that shows saving multiple database table to a tabbed excel spreadsheet.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
import pandas as pd | |
conn = sqlite3.connect("database.db") | |
writer = pd.ExcelWriter('order_inv_output.xlsx', engine='xlsxwriter') | |
pd.read_sql_query('select * from tbl_1', conn).to_excel(writer, sheet_name='Sheet 1', index=False) | |
pd.read_sql_query('select * from tbl_2', conn).to_excel(writer, sheet_name='Sheet 2', index=False) | |
pd.read_sql_query('select * from tbl_3', conn).to_excel(writer, sheet_name='Sheet 3', index=False) | |
writer.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment