Convert SQLITE tables to CSV, MS Excel, MS Word, ODS, JSON, and LaTex
pip install pandas==2.1.2 openpyxl==3.1.2 docx==0.2.4
or
pip install -r requirements.txt
import sqlite3
import pandas as pd
from docx import Document
from openpyxl import Workbook
from openpyxl.utils.dataframe import dataframe_to_rows
- export_to_excel
- export_to_libreoffice_calc
- export_to_csv
- export_to_word
- export_to_json
- export_to_latex
All these functions have the same input parameters and as output the file in the format associated with the function.
Input arguments
db_name
: The name of the SQLite database file.
table_name
: The name of the table in the database you want to export.
output_filename
: The name of the output JSON file where the exported data will be saved.
selected_columns
(optional): A list of column names you want to export. If provided, only the specified columns will be exported. If not provided, all columns in the table will be exported.Returns:
None
databasename = "news.db"
tablename = "news"
excel_filename = "exported_data.xlsx"
ods_filename = "exported_data.ods"
csv_filename = "exported_data.csv"
word_filename = "exported_data.docx"
json_filename = "exported_data.json"
latex_filename = "exported_data.tex"
selected_columns = ["title", "source", "relevance"]
export_to_word(databasename, tablename, word_filename, selected_columns)
export_to_excel(databasename, tablename, excel_filename, selected_columns)
export_to_libreoffice_calc(databasename, tablename, ods_filename, selected_columns)
export_to_csv(databasename, tablename, csv_filename, selected_columns)
export_to_json(databasename, tablename, json_filename, selected_columns)
export_to_latex(databasename, tablename, latex_filename, selected_columns)