bug 57919: add functions to write and close a POIDocument, guaranteeing closure of the output stream and document.