Hi, maybe a workaround. I recently had this issue, am having this issue, where named ranges / database named ranges just disappeared, lost a stack of named ranges, but 4 stayed, don’t know why. Cell references change to #NAME? and don’t magically return to normal when the named ranges are added back.
Here’s what I did: More carefully handling the contents.xml file got a result for me, putting the named ranges back into my calc workbook. That is, changing calc sheet from .ods file extension to .zip, extracting the content.xml file, extremely carefully copying and pasting the named ranges section of the xml file from another sheet [that had most but not all the namedranges] into this extracted content.xml file [everything between the table:named-expressions/ and </table:database-ranges> tags, saving it, copying it back into the .zip package replacing the existing copy there, then renaming the extension back from .zip to .ods.
This put the named ranges back BUT as you all know the cell references were still damaged, referencing #NAME? where each named range was. By using FileCompare, EditMenu → TrackChanges → CompareDocument, and comparing to another earlier copy of the file [same one as i got the content.xml tag section from], it somehow found the changes to cell formula when the sheet lost the named ranges. Using the filter in the file comparison dialog to narrow to #NAME?, i was able to undo many of those changes, reverting back to correct formula for many, not all, of the unexpected screwing up of named ranges. !!! Remember to do this on copies of the .ods files… just in case.
Also, being slightly a noob[ish] to libreoffice calc’s features on this front, i had no idea calc has 2 very separate but confusingly similar ways of naming ranges… both called fairly similarly, in my mind, named ranges and named database ranges… this is a bit weird when coming from my background… it confused me, doh, exacerbated by panicking about the weird named ranges issue and my main sheets getting screwed up. Weirdly too, this named range issue just magically jumped files and occurred in another file too… an earlier saved version of the calc file with the issue.
Anyhoo, this approach may help a little hopefully, a kinda indirect working fix at least, that doesn’t require rebuilding everything from near scratch.
Also, sorry for my ignorance, how could we generate a list of all database named ranges too please? the code in this and other threads is for named ranges only…
Very best to everyone, jb