fdo#76312: LO crashes - endTableCell is called before StartTable.

- m_oldTableReference values were not being reset.
- A call for DocxAttributeOutput::switchHeaderFooter from
  DocxExport::WriteHeadersFooters would end up using the m_oldTableReference
  value saved by DocxAttributeOutput::EndParagraph, which is incorrect.
- Fixed this issue and added an UT for the same.

Change-Id: I5ac51c3449e78bd26389e93e0d733d429dcc6874
Reviewed-on: https://gerrit.libreoffice.org/8659
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>