# Write to Excel with formatting with pd.ExcelWriter(output_excel, engine='openpyxl') as writer: df.to_excel(writer, sheet_name='B2B', index=False) # Summary sheet summary = df.groupby('Rate').agg( 'Taxable Value': 'sum', 'CGST': 'sum', 'SGST': 'sum', 'IGST': 'sum' ).reset_index() summary.to_excel(writer, sheet_name='Summary', index=False)
b2b_records = [] # Flatten B2B section for fp in data.get('fp', []): # fp = tax period for b2b in fp.get('b2b', []): for inv in b2b.get('inv', []): for item in inv.get('itms', []): itm_det = item.get('itm_det', {}) b2b_records.append( 'Supplier GSTIN': b2b.get('ctin'), 'Invoice No': inv.get('inum'), 'Invoice Date': inv.get('idt'), 'Invoice Value': inv.get('val'), 'Taxable Value': itm_det.get('txval'), 'CGST': itm_det.get('iamt', 0), 'SGST': itm_det.get('samt', 0), 'IGST': itm_det.get('iamt', 0), 'Cess': itm_det.get('csamt', 0), 'Rate': itm_det.get('rt'), 'Place of Supply': inv.get('pos'), 'Reverse Charge': inv.get('rchrg') ) GSTR 2A - JSON to Excel Converter
df = pd.DataFrame(b2b_records)