在docs文件中使用1而不是true有效吗?

时间:2016-02-23 16:37:03

标签: java apache-poi

我正在尝试解析由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 export或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>

1 个答案:

答案 0 :(得分:1)

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

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

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

var x = new Proxy({},{get(target,name) {
  return "Its hilarious you think I have "+name
}})

console.log(x.hair) // logs: "Its hilarious you think I have hair"
相关问题