Untitled

 avatar
unknown
plain_text
2 months ago
2.5 kB
1
Indexable
from docx import Document

# Create a new MS Word document
doc = Document()

# Add a title
doc.add_heading('Loan Repayment Schedule', level=1)

# Add a table
data = [
    ["TL No", "Due Date", "Instl Amt", "Principal", "Interest", "O/s Principal", "Adv", "EMI", "Received", "Rate", "Type"],
    [1, "04-02-2025", "2,002.00", "1,614.00", 388, "30,614.00", "", "", "", "N", "Fixed"],
    [2, "04-03-2025", "2,002.00", "1,633.00", 369, "28,981.00", "", "", "", "N", "Fixed"],
    [3, "04-04-2025", "2,002.00", "1,653.00", 349, "27,328.00", "", "", "", "N", "Fixed"],
    [4, "04-05-2025", "2,002.00", "1,673.00", 329, "25,655.00", "", "", "", "N", "Fixed"],
    [5, "04-06-2025", "2,002.00", "1,693.00", 309, "23,962.00", "", "", "", "N", "Fixed"],
    [6, "04-07-2025", "2,002.00", "1,713.00", 289, "22,249.00", "", "", "", "N", "Fixed"],
    [7, "04-08-2025", "2,002.00", "1,734.00", 268, "20,515.00", "", "", "", "N", "Fixed"],
    [8, "04-09-2025", "2,002.00", "1,755.00", 247, "18,760.00", "", "", "", "N", "Fixed"],
    [9, "04-10-2025", "2,002.00", "1,776.00", 226, "16,984.00", "", "", "", "N", "Fixed"],
    [10, "04-11-2025", "2,002.00", "1,797.00", 205, "15,187.00", "", "", "", "N", "Fixed"],
    [11, "04-12-2025", "2,002.00", "1,819.00", 183, "13,368.00", "", "", "", "N", "Fixed"],
    [12, "04-01-2026", "2,002.00", "1,841.00", 161, "11,527.00", "", "", "", "N", "Fixed"],
    [13, "04-02-2026", "2,002.00", "1,863.00", 139, "9,664.00", "", "", "", "N", "Fixed"],
    [14, "04-03-2026", "2,002.00", "1,886.00", 116, "7,778.00", "", "", "", "N", "Fixed"],
    [15, "04-04-2026", "2,002.00", "1,908.00", 94, "5,870.00", "", "", "", "N", "Fixed"],
    [16, "04-05-2026", "2,002.00", "1,931.00", 71, "3,939.00", "", "", "", "N", "Fixed"],
    [17, "04-06-2026", "2,002.00", "1,955.00", 47, "1,984.00", "", "", "", "N", "Fixed"],
    [18, "04-07-2026", "2,002.00", "1,984.00", 18, "0.00", "", "", "", "N", "Fixed"],
    ["", "Total", "36,036.00", "32,228.00", 3808, "", "", "", "", "", ""],
]

# Create the table in the document
table = doc.add_table(rows=1, cols=len(data[0]))
table.style = 'Table Grid'

# Add header row
hdr_cells = table.rows[0].cells
for i, header in enumerate(data[0]):
    hdr_cells[i].text = str(header)

# Add data rows
for row in data[1:]:
    row_cells = table.add_row().cells
    for i, cell in enumerate(row):
        row_cells[i].text = str(cell)

# Save the document
file_path = "/mnt/data/Loan_Repayment_Schedule.docx"
doc.save(file_path)

file_path
Leave a Comment