'Generator that creates the XML file and the sheet header'

def _write_header(self):

    with xmlfile(self.filename) as xf:
        with xf.element('worksheet', xmlns=SHEET_MAIN_NS):
            if self.sheet_properties:
                pr = self.sheet_properties.to_tree()
            xf.write(pr)
            views = Element('sheetViews')
            views.append(self.sheet_view.to_tree())
            xf.write(views)
            xf.write(write_format(self))
            cols = write_cols(self)
            if (cols is not None):
                xf.write(cols)
            with xf.element('sheetData'):
                try:
                    while True:
                        r = (yield)
                        xf.write(r)
                except GeneratorExit:
                    pass
            if self.protection.sheet:
                xf.write(worksheet.protection.to_tree())
            af = write_autofilter(self)
            if (af is not None):
                xf.write(af)
            dv = write_datavalidation(self)
            if (dv is not None):
                xf.write(dv)
            drawing = write_drawing(self)
            if (drawing is not None):
                xf.write(drawing)
            if self._comments:
                legacyDrawing = Related(id='commentsvml')
                xml = legacyDrawing.to_tree('legacyDrawing')
                xf.write(xml)
