Method
#Setting the alignments of cell C3
sht.api.Range(‘C3’).HorizontalAlignment = xw.constants.Constants.xlCenter
#sht.api.Range(‘C3’).VerticalAlignment = xw.constants.Constants.xlCenter
sht.api.Range(‘C3′).Value=’Test1’
Sample Code
#Cell Alignment
import xlwings as xw #Import the xlwings package
app=xw.App()
bk=app.books.active #Get the active workbook
sht=bk.sheets.active #Get the active worksheet
#Setting the alignments of cell C3
sht.api.Range('C3').HorizontalAlignment = xw.constants.Constants.xlCenter
sht.api.Range('C3').VerticalAlignment = xw.constants.Constants.xlCenter
sht.api.Range('C3').Value='Test1'
#bk.close()
#app.kill()

Leave a Reply