gpt4 book ai didi

java - 在文档文件中使用 1 代替 true 是否有效?

转载 作者:行者123 更新时间:2023-11-30 07:34:34 25 4
gpt4 key购买 nike

我正在尝试解析由 Google doc 生成的 docx 文件。我正在查看一个名为 run 的 XWPFRun 元素。如果我调用 run.isBold() 它会返回 false,即使元素是粗体也是如此。如果我查看 run.getCTR(),我会得到下面的 xml。正如你所看到的,它说

<w:b w:val="1"/> 

而不是

<w:b w:val="true"/> 

这会导致 isBold() 返回 false(我猜)。如果我在 LibreOffice 中导入文件,然后再次导出 isBold() 返回 true,那么这是 google doc 导出或 poi 中的错误吗?还是我做错了什么?

<xml-fragment w:rsidDel="00000000" w:rsidR="00000000" w:rsidRPr="00000000" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:lc="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup">
<w:rPr>
<w:rFonts w:ascii="Verdana" w:cs="Verdana" w:eastAsia="Verdana" w:hAnsi="Verdana"/>
<w:b w:val="1"/>
<w:sz w:val="36"/>
<w:szCs w:val="36"/>
<w:rtl w:val="0"/>
</w:rPr>
<w:t xml:space="preserve">Kapitel 1: Digitale tømmermænd</w:t>
<w:br w:type="textWrapping"/>
</xml-fragment>

最佳答案

根据 POI ooxml-lib/OpenOfficeXML-XMLSchemas.zip 中的 wml.xsd,我得出结论:1|true|on 都是可接受且等效的 True 值,0|false|off 都是可接受且等效的 False 值。任何应用程序都应该能够将其选择的这 6 个值中的任何一个写入 XML 文件,并且任何应用程序都应该能够以 100% 的清晰度读取这 6 个值中的任何一个。

您发现 POI 中存在错误。看着implementation isBold(以及 isItalic 和使用 isCTOnOff 的其他任何内容)时,代码会忽略您发现的“1”/“0”情况。该代码还应使用 STOnOff.X_1。

现在是fixed on POI trunk并将在下一个 POI 版本(3.15 beta 1)中提供。

<xsd:element name="b" type="CT_OnOff" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Bold</xsd:documentation>
</xsd:annotation>
</xsd:element>

<xsd:complexType name="CT_OnOff">
<xsd:attribute name="val" type="ST_OnOff">
<xsd:annotation>
<xsd:documentation>On/Off Value</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>

<xsd:simpleType name="ST_OnOff">
<xsd:annotation>
<xsd:documentation>On/Off Value</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="true">
<xsd:annotation>
<xsd:documentation>True</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="false">
<xsd:annotation>
<xsd:documentation>False</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="on">
<xsd:annotation>
<xsd:documentation>True</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="off">
<xsd:annotation>
<xsd:documentation>False</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="0">
<xsd:annotation>
<xsd:documentation>False</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="1">
<xsd:annotation>
<xsd:documentation>True</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

关于java - 在文档文件中使用 1 代替 true 是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35583073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com