为什么我的字字段限制为 257 个字符?

Why is my word field limited to 257 character?

我有一个使用属性列表生成 Word 文档的程序:

        // Open the docx (is a zip).
        $zip = new ZipArchive();
        if ($zip->open($fileName, ZIPARCHIVE::CHECKCONS) !== TRUE) {
            return false; // failed opening. The template must be docx (xml in zip archive).
        }

        // Get the filename of the document into the archive (depend by the format).
        $file = substr($templateFileName, -4) == '.odt' ? 'custom.xml' : 'docProps/custom.xml';

        // Load the data.
        $data = $zip->getFromName($file);

        // The data is an XML document, so we use DOMDocument to work on it.
        $XML_doc = new DOMDocument();
        $XML_doc->loadXML($data);

        // Replace the properties.
        $properties = $XML_doc->getElementsByTagName("property");
        foreach ($properties as $property)
        {
            if ( isset($replaceData[$property->getAttribute("name")]) )
            {
                $property->firstChild->nodeValue = $replaceData[$property->getAttribute("name")];
            }
        }

问题:这些属性之一是用户列表,包含邮件和公司。但是当你有四个以上的用户时,第五个被中间切掉,接下来的不在文档中。

尝试了几种方法后,我注意到用于创建列表的字符串的长度始终为 257 个字符。你们知道为什么它总是在 257 个字符后停止吗?我一头雾水

这是 Word DocumentProperties 的内置限制。信息需要修剪或分解成多条信息才能使用文档属性。

可能有其他选择。 Word 有其他方法在文档中存储信息,但我们需要知道这些信息发生了什么以提供指导。覆盖属于需要解决的新问题:

文档中的这些信息有何用途?或者,换句话说,信息在文档中后如何使用?

看看如何使用文档变量。它们可以存储大量文本,并且可以通过 DocVariable 字段引用,就像您使用 DocProperty 字段一样。

与文档属性不同,文档变量不能通过 GUI 访问以进行查看或编辑。这对您来说可能是也可能不是(不利)优势。