Search code examples
python-2.7python-3.xpywin32

Creation of excel file using python


Is there any way to create excel objects using pywin32 even if MS-OFFICE suite is not installed on windows based system ?


Solution

  • This will do what you want.

    from openpyxl import Workbook
    wb = Workbook()
    
    # grab the active worksheet
    ws = wb.active
    
    # Data can be assigned directly to cells
    ws['A1'] = 42
    
    # Rows can also be appended
    ws.append([1, 2, 3])
    
    # Python types will automatically be converted
    import datetime
    ws['A2'] = datetime.datetime.now()
    
    # Save the file
    wb.save("C:\\Users\\your_path_here\\Desktop\\sample.xlsx")
    

    See this link for details.

    https://pypi.python.org/pypi/openpyxl