Author Topic: Putting borders on cells  (Read 760 times)

jonesrl

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Putting borders on cells
« on: March 13, 2015, 12:33:18 AM »
When I use the statement
xla = xl_app()
    workbook = xla.ActiveWorkbook
    sheet = workbook.Sheets(str(node_type+"-Tags"))
    #win32api.MessageBox(0, "Check for "+str(node_type)+" Tags", "New Menu button eg")
    #sheet = workbook.Sheets("Provider-Tags")
    sheet.Activate()
    # Put in short and long names into current sheet
    xl_app().Cells(3, 2).Value=provider_name
    xl_app().Cells(4, 2).Value=report_name
    xl_app().Cells(4, 2).Borders.LineStyle = "xlDouble"


I get the following error
2015-03-13 10:27:13,986 - ERROR :     xl_app().Cells(4, 2).Borders.LineStyle = "xlDouble"
2015-03-13 10:27:13,986 - ERROR :   File "C:\Program Files\Python\Lib\site-packages\win32com\client\__init__.py", line 474, in __setattr__
2015-03-13 10:27:13,990 - ERROR :     self._oleobj_.Invoke(*(args + (value,) + defArgs))
2015-03-13 10:27:13,990 - ERROR : pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Office Excel', 'Unable to set the LineStyle property of the Borders class', 'C:\\Program Files\\Microsoft Office\\Office12\\1033\\XLMAIN11.CHM', 0, -2146827284), None)

The code works without the Borders statement. What am I doing wrong??

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 599
  • Karma: +14/-1
    • View Profile
Re: Putting borders on cells
« Reply #1 on: March 15, 2015, 05:50:40 PM »
Hi,

xlDouble is an integer constant, not a string. You need to do something like

from win32com.client import constants
LineStyle = constants.xlDouble

Best regards,
Tony

jonesrl

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Putting borders on cells
« Reply #2 on: March 16, 2015, 12:59:54 AM »
Thank you v much :)