Below is the complete code:
import lxml.etree
import lxml.builder
import openpyxl
wb = openpyxl.load_workbook('C:\Users\powell.mittra\Excel.xlsx')
sheet = wb.get_sheet_by_name('Sheet1')
x = sheet.cell(row=12, column=1).value
E = lxml.builder.ElementMaker()
ROOT = E.x
DOC = E.doc
FIELD1 = E.field1
FIELD2 = E.field2
the_doc = ROOT(
DOC(
FIELD1('some value1', name='blah'),
FIELD2('some value2', name='asdfasd'),
)
)
print lxml.etree.tostring(the_doc, pretty_print=True)
I am getting the following output where 'x' is taken as a string instead of taking the value from x = sheet.cell(row=12, column=1).value :
<x>
<doc>
<field1 name="blah">some value1</field1>
<field2 name="asdfasd">some value2</field2>
</doc>
</x>
Can someone please let me know if I can pass values in ROOT and other elements from excel sheet or it is not possible using LXML?