[Libreoffice-bugs] [Bug 131025] Writer document with tables lost data in cells (apparently) replacing with 0

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Tue Dec 8 11:06:15 UTC 2020


https://bugs.documentfoundation.org/show_bug.cgi?id=131025

--- Comment #15 from Jim DeLaHunt <from+documentfoundation at jdlh.com> ---
I encountered this problem with the following current LibreOffice version on
macOS:

Version: 7.0.3.1
Build ID: d7547858d014d4cf69878db179d326fc3483e082
CPU threads: 8; OS: Mac OS X 10.13.6; UI render: default; VCL: osx
Locale: en-CA (en_CA.UTF-8); UI: en-US
Calc: threaded

I had success fixing the problem, guided by Mark van Rossum's comment12. I
unzipped the .odt file, edited contents.xml, changed the value of
"office:value-type" attributes from "float" to "string", and deleted
"office:value" attributes.

I did this with the following XSLT file. I won't attempt to explain how to use
XSLT here. It is tough to get working, but once it works, it's a great tool for
the job (of patching XML files).

Once I edited contents.xml, re-zipped the document directory, and opened the
new .odt file in LibreOffice, I saw a "document corrupted" message as Mark did.
LibreOffice was able to repair the document, and it seems OK.

=====
<?xml version="1.0" encoding="UTF-8"?>
<!-- Restore_odt_table_cell_text.xslt
  by Jim DeLaHunt (jdlh.com), 2020-12-08. Donated to the public domain (cc0).

  This XSLT fixes a LibreOffice bug where Writer table cells containing 
  text turn into digit 0 when the document is re-opened. 
  This is Bug 131025 - Writer document with tables lost data in cells
(apparently) replacing with 0
  <https://bugs.documentfoundation.org/show_bug.cgi?id=131025>
  It does this by fixing table cells like
  <table:table-cell table:style-name="…" office:value-type="float" 
  office:value="0">
        <text:p text:style-name="P71">desired text</text:p>
  </table:table-cell>

  by changing to office:value-type="string" and deleting office:value="0".
  -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0">

        <xsl:output method="xml" indent="no" encoding="UTF-8" />

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

        <xsl:template
match="/office:document-content/office:body/office:text/table:table/table:table-row/table:table-cell[@office:value-type='float'][@office:value='0'][not(text()='')]"
>
                <xsl:copy>
                        <xsl:attribute
name="office:value-type">string</xsl:attribute>
                        <xsl:apply-templates select="@*[name(.)!='office:value'
and name(.)!='office:value-type']" />
            <xsl:apply-templates select="node()"/>
                </xsl:copy>
        </xsl:template>
</xsl:stylesheet>
=====

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20201208/5a112a2c/attachment-0001.htm>


More information about the Libreoffice-bugs mailing list