Sometimes we want to read real time update data for excel that haven't save.
So below code is useful.
Python code:
import win32com.client as win32
import pandas as pd
#here we use win32com to save open excel
excel = win32.gencache.EnsureDispatch('Excel.Application')
print("Active WB:", excel.ActiveWorkbook.Name)
for wb in excel.Workbooks:
if wb.Name == 'da.xlsx' :
print("WB:",wb.Name)
wb.Save()
#here we use panda module to read and check
df = pd.read_excel (r'da.xlsx', sheet_name='Sheet1')
print (df)
First need to install module reportlab. Then create table using code below:
Output pdf:
Code:
from reportlab.lib import colors #import module
from reportlab.lib.pagesizes import letter, inch
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
doc = SimpleDocTemplate("simple_table_grid.pdf", pagesize=letter) #define pdf document name
# container for the 'Flowable' objects
elements = [] #define the data