jack
jack

Reputation: 505

Django 1.6 adding rows o excel sheet

I have one table in excel sheet with username and amount fields. I want to add additional rows to this table when user and number is incremented(by program). I am developing a application using django, excel file will be in local machine.

I will use workbook_open to open the excel file. I can't continue further because of adding rows to table with fields user name and amount in run time . However,I can't use xlwt module to do so. Can anyone suggest me to do so in django 1.6?

Upvotes: 0

Views: 200

Answers (1)

jack
jack

Reputation: 505

Finally I figured out the solution for adding rows to the table(with border) in excel sheet. I was using win32com port to do the task. Here is my code:

    import win32com.client as win32   

    exc = win32.gencache.EnsureDispatch("Excel.Application")

    exc.Workbooks.Open("E:\\Invoice.xls")



    exc.Visible = 1

    row = 1
    no=4
    i=1
    count=0
    for m in Eng_name:
        if(m!=""):
            count=count+1

    while True:
        exc.Range("B%d" % row).Select()
        data = exc.ActiveCell.FormulaR1C1
        exc.Range("A%d" % row).Select()
        condition = exc.ActiveCell.FormulaR1C1


        if condition == INSERT_THIS:
            if(i==count):
                 break
            exc.Rows("%d" %(row)).Select()
            exc.Selection.Insert(Shift=constants.xlDown)
            i=i+1
            print i


        else:

            row += 1

Upvotes: 1

Related Questions