0

如何使用 OpenTBS 正确填充 PowerPoint 模板的嵌入工作表,其中工作表嵌入在 PowerPoint 演示文稿中?

我使用了子文件,但嵌入的工作表保留了输入标签并且没有替换值。

Excel 模板可正确合并为独立的 xls 文件,但嵌入演示文稿 (PPTX) 时不能。

+------------------------------+---------------------------------+
|                              |    [c.key;block=tbs:cell]       |
+------------------------------+---------------------------------+
|       [r.#;block=tbs:row]    |    [cell.val;block=tbs:cell]    |
+------------------------------+---------------------------------+

PHP 合并代码

$template = 'riskwaterfalltemplate.pptm';
$TBS->LoadTemplate($template.'#ppt/embeddings/Microsoft_Excel_Worksheet2.xlsx',  OPENTBS_ALREADY_UTF8);


// -----------------
// Output the result
// -----------------
$nbr_row = 5;
$nbr_col = 5;
// List of column's names
$columns = array();
for ($col=1; $col <= $nbr_col; $col++)
{
    $columns[$col]['key'] = $col;
}





$data = array();
$record = array();

for ($col=1; $col <= $nbr_col; $col++)
{
    $record[$col]['val'] = 1;
}
for ($row=0; $row < $nbr_row; $row++)
{

    $data[$row] = $record;
}

// Expanding columns
$TBS->MergeBlock('c',$columns);

//Expanding Cells
$TBS->MergeBlock('cell', $record);

// Merging rows
$TBS->MergeBlock('r',$data);

$TBS->Show();

调试输出

* OPENTBS DEBUG MODE: if the star, (*) on the left before the word OPENTBS, is not the very first character of this page, then your
merged Document will be corrupted when you use the OPENTBS_DOWNLOAD option. If there is a PHP error message, then you have to fix it.
If they are blank spaces, line beaks, or other unexpected characters, then you have to check your code in order to avoid them.

------------------------------
INFORMATION
------------------------------
* Debug command: OPENTBS_DEBUG_XML_CURRENT
* OpenTBS version: 1.9.9
* TinyButStrong version: 3.10.1
* PHP version: 5.6.25YES
* Opened document: riskwaterfalltemplate.pptm
* Activated features for document type: openxml/pptx
* Deleted files in the archive: none
* Added files in the archive: none
* Modified files in the archive:
  - ppt/embeddings/Microsoft_Excel_Worksheet2.xlsx

------------------------------
File merged with OpenTBS: ppt/embeddings/Microsoft_Excel_Worksheet2.xlsx
4

1 回答 1

0

如果您正在合并嵌入式 XLSX 以便在 PPTX 演示文稿中修改图表,这将不起作用。

在 Ms Word 和 Ms PowerPoint 中,附加到图表的嵌入 XLSX 不包含图表的真实数据。这是一个简单的副本,可帮助用户使用 Excel 女士编辑数据。真实数据存储在与图表相关的 XML 子文件中。

如果要编辑图表,请使用命令OPENTBS_CHART

如果您确实想要合并嵌入的 XLSX 文件,那么您的代码将无法正常工作,因为子文件ppt/embeddings/Microsoft_Excel_Worksheet2.xlsx不是 XML 文件,而是二进制文件。所以 TBS 不能直接合并其中的任何内容。

解决方案是:

  1. 使用加载 PPTX 模板$TBS->LoadTemplate('my_presentation.pptx')
  2. 加载ppt/embeddings/Microsoft_Excel_Worksheet2.xlsx子文件作为当前子文件使用$TBS->PlugIn(OPENTBS_SELECT_FILE, $SubFile)
  3. 将 XLSX 子文件的二进制文件保存在临时文件中,使用$handle = tmpfile(); fwrite($handle, $TBS->Source);
  4. 使用为此临时文件打开一个新的 TBS 实例$TBS2->LoadTemplate($handle);
  5. 用 $TBS2 合并 XLSX 中的数据,
  6. 使用完成 XLSX$TBS2->Show(OPENTBS_STRING);
  7. 使用将结果保存在 PPTX 中$TBS->Source = $TBS2->Source;
  8. 使用完成 PPTX$TBS->Show(...);
于 2017-07-03T23:58:48.137 回答