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



我有一个程序使用属性列表来生成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 个字符后停止吗?我毫无头绪。

这是WordDocumentProperties的内置限制。为了使用文档属性,需要将信息剪裁或分解为多个信息片段。

可能有其他选择。Word 还有其他方法可以在文档中存储信息,但我们需要知道信息会发生什么情况才能提供指导。涵盖这一点将属于需要解决的新问题:

文档内部如何处理这些信息?或者,换句话说,一旦信息进入文档,如何使用这些信息?

请改用文档变量。这些可以存储大量文本,并且可以通过 DocVariable 字段引用,其方式与使用 DocProperty 字段的方式完全相同。

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

最新更新