本文介绍了OpenTBS/PHP - 将内容合并到 PowerPoint 模板内的嵌入式工作表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I properly fill an embedded worksheet of a PowerPoint template with data using OpenTBS, where the worksheet is embedded inside of a PowerPoint presentation?

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

I used sub files but the embedded worksheet retains the input tags and no replaced values.

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

推荐答案

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

If you are merging the embedded XLSX in order to have a chart modified in the PPTX Presentation, this will not work.

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

In both Ms Word ans Ms PowerPoint, embedded XLSX attached to chart does not contains the true data of the chart. It is a simple copy that helps the user for editing the data using Ms Excel. The true data are stored in the XML sub-file related to the chart.

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

If you want to edit the chart, use command OPENTBS_CHART.

如果您真的想合并嵌入的 XLSX 文件,您的代码将不起作用,因为子文件 ppt/embeddings/Microsoft_Excel_Worksheet2.xlsx 不是 XML 文件,而是二进制文件.所以TBS不能直接在里面合并任何东西.

If you actually want to merge the embedded XLSX file, your code is not working because the sub-file ppt/embeddings/Microsoft_Excel_Worksheet2.xlsx is not an XML file, it is a binary file. So TBS cannot merge anything in it directly.

解决办法是:

  1. 使用 $TBS->LoadTemplate('my_presentation.pptx') 加载 PPTX 模板,
  2. 使用$TBS->PlugIn(OPENTBS_SELECT_FILE, $SubFile)ppt/embeddings/Microsoft_Excel_Worksheet2.xlsx 子文件作为当前子文件加载/li>
  3. 使用 $handle = tmpfile() 将 XLSX 子文件的二进制文件保存在临时文件中;fwrite($handle, $TBS->Source);
  4. 使用 $TBS2->LoadTemplate($handle);
  5. 为这个临时文件打开一个新的 TBS 实例
  6. 使用 $TBS2 在 XLSX 中合并数据
  7. 使用 $TBS2->Show(OPENTBS_STRING);
  8. 完成 XLSX
  9. 使用 $TBS->Source = $TBS2->Source;
  10. 将结果保存在 PPTX 中
  11. 使用 $TBS->Show(...);
  12. 完成 PPTX
  1. load the PPTX template using $TBS->LoadTemplate('my_presentation.pptx'),
  2. the load the ppt/embeddings/Microsoft_Excel_Worksheet2.xlsx sub-file as the current sub-file using $TBS->PlugIn(OPENTBS_SELECT_FILE, $SubFile)
  3. save the binary of the XLSX sub-file in a temp file using $handle = tmpfile(); fwrite($handle, $TBS->Source);
  4. open a new TBS instance for this temp file using $TBS2->LoadTemplate($handle);
  5. do your data merging in the XLSX with $TBS2,
  6. finalize the XLSX using $TBS2->Show(OPENTBS_STRING);
  7. save the result in the PPTX using $TBS->Source = $TBS2->Source;
  8. finalize the PPTX using $TBS->Show(...);

这篇关于OpenTBS/PHP - 将内容合并到 PowerPoint 模板内的嵌入式工作表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 07:23