Skip to content

Instantly share code, notes, and snippets.

@garymanley
Created December 28, 2017 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garymanley/19a981c7eacebfa9db476a020c749357 to your computer and use it in GitHub Desktop.
Save garymanley/19a981c7eacebfa9db476a020c749357 to your computer and use it in GitHub Desktop.
Use XL Formatter
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 28 20:21:04 2017
@author: garym
"""
import xlwings as xw
## I know that doing it this way is not recommended for code that gets shared but it works for me for this purpose
import sys
sys.path.append(r'C:\Users\garym\Documents\Python From Work\Python\Other')
import XLFormatting as XL
## Open Workbook
wb = xw.Book()
## Set value to Hellow World
xw.Range('A1').value = 'Hello World'
xw.Range('B5').value = 'Abc 123'
## Format the range using the function
XL.formatrange('A1','White','Black',1,1,'A1:A2','Right')
XL.formatrange('B5','Pink','Turq',1,2,'B5:B6','Center')
## Autofit the columns
xw.Range('A1:AI100').autofit()
## Save workbook
filename = (r'C:\Users\garym\Documents\Python From Work\Python\Other\test.xlsx')
wb.save(filename)
wb.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment