humbertovarona / table2x

Convert SQLITE tables to CSV, MS Excel, MS Word, ODS, JSON, and LaTex

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

table2x

Convert SQLITE tables to CSV, MS Excel, MS Word, ODS, JSON, and LaTex

Version

Release date

License

Programming language

OS

Requirements

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

Function list

  1. export_to_excel
  2. export_to_libreoffice_calc
  3. export_to_csv
  4. export_to_word
  5. export_to_json
  6. 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

How to run

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)

About

Convert SQLITE tables to CSV, MS Excel, MS Word, ODS, JSON, and LaTex

License:MIT License


Languages

Language:Python 100.0%