标签: phpword

CodeIgniter PHPWord用作third_party

我正在尝试使用PHPWord并且难以使用它.

这是我在application/libraries/words.php中的代码

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH."/third_party/PhpWord/Autoloader.php"; 

\PhpOffice\PhpWord\Autoloader::register(); \\NOT SURE IF THIS IS CORRECT

class Word extends PhpWord { 
    public function __construct() { 
        parent::__construct(); 
    } 
}
Run Code Online (Sandbox Code Playgroud)

基于PHPWord github,我必须像这样使用它:

Alternatively, you can download the latest release from the releases page. In this case, you will have to register the autoloader.

require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register(); // WHERE SHOULD I PUT THIS?
Run Code Online (Sandbox Code Playgroud)

当我尝试从我的控制器加载库时:

$this->load->library('word');
Run Code Online (Sandbox Code Playgroud)

它给我的错误说:

Fatal error: Class 'PhpWord' not found in C:\xampp\htdocs\path\to\application\libraries\Word.php on line 7
Run Code Online (Sandbox Code Playgroud)

我试图扩展Autoloader类,但PHP仍然抱怨它找不到Autoloader.php. …

php codeigniter phpword

3
推荐指数
1
解决办法
6678
查看次数

如何在phpword表中的单元格中换行?

我想根据.docx数据库中存在的数据创建一个word文件。为此,我使用的是phpword 0.12.0。我需要画一张表将数据放入其中。之后,我需要从数据库的表中获取每一行以自动进入换行的单元格。我可以用

$section->addTextBreak();
Run Code Online (Sandbox Code Playgroud)

但是没有表,现在如何在表内的单元格中执行此工作?我正在使用下面的代码,但是它不起作用。

$area=array();
$axis=array();
$topic=array();
$table->addRow(900);
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('test1'), $fontStyle);
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('test2'), $fontStyle);
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('test3'), $fontStyle);
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('test4'), $fontStyle);
for ($i = 0; $i < 4; $i++) {
      $table->addRow();
      $table->addCell(2000)->addText(htmlspecialchars($topic{$i}),array('name' => 'Segoe UI Semilight'));
      $table->addCell(3000)->addText(htmlspecialchars($axis{$i}),array('rtl' => true,'name' => 'Segoe UI Semilight'));
      $table->addCell(2000)->addText(htmlspecialchars($area{$i}),array('rtl' => true,'name' => 'Segoe UI Semilight'));
      $table->addCell(2000)->addText(htmlspecialchars($i),array('rtl' => true,'name' => 'Segoe UI Semilight'));
}
Run Code Online (Sandbox Code Playgroud)

php mysql phpword

3
推荐指数
1
解决办法
4003
查看次数

用phpword设置全局段落样式

我正在使用PHPWord,并希望将每个段落的spaceAfter段落样式设置为0.不幸的是,我不知道如何在全球范围内做到这一点.您可以通过执行以下操作全局设置字体大小/名称:

$phpWord->setDefaultFontName('Times New Roman');
$phpWord->setDefaultFontSize(12);
Run Code Online (Sandbox Code Playgroud)

但是我如何设置spaceAfter默认段落样式?

根据http://phpword.readthedocs.org/en/latest/elements.html#paragraph-style我也可以在每次调用时设置它addText()(通过设置第三个参数),但这可能会变老,速度很快.

全局设置将是理想的方法.

我正在使用Beta 0.6.3.

有任何想法吗?

php phpword

3
推荐指数
1
解决办法
4178
查看次数

在PhpWord中创建正确的浮动图像

我想要一个右边的图像,左边的文字漂浮在图像周围.反过来非常好,在文档Recipies部分也有一个例子.但是,我没有使用浮在右边的图像.我尝试了什么:

addImage('myimage.png', 
   array(
       'width'=>320, 
       'height'=>240, 
       'align'=>'right',
       'wrappingStyle'=>'square',
       'positioning' => 'absolute'
   )
);
Run Code Online (Sandbox Code Playgroud)

要么

addImage('myimage.png', 
   array(
       'width'=>320, 
       'height'=>240, 
       'align'=>'right',
       'wrappingStyle'=>'square',
       'positioning' => 'absolute',
       'posHorizontalRel' => 'margin',
       'posVerticalRel' => 'line'
   )
);
Run Code Online (Sandbox Code Playgroud)

我还尝试了负像宽度等,但这两者都没有用.不幸的是,整个项目的文档真的很差,至少在phpword.readthedocs.org.

php phpword

3
推荐指数
1
解决办法
2440
查看次数

如何在PHPWord中合并单元格?或者每个表行中有不同数量的单元格?

尝试使用PHP库PHPWord创建MS Word文档.

你能帮我解决一下文档中两个或多个单元格的合并问题吗?或者如何在每个表行中有不同数量的单元格?

我尝试将单元格定义为:

$cell11 = array('gridSpan'=>2);
Run Code Online (Sandbox Code Playgroud)

但它没有奏效....

先感谢您!

phpword

2
推荐指数
1
解决办法
6602
查看次数

PHPWord - 未应用标题样式

我在使用 PHPWord 时遇到了一些麻烦。总的来说,该模块相当简单且易于使用,但我似乎无法做一件事:为标题添加样式(或添加标题,真的)。

背景:
我的文档生成正确,我正在从数据库加载变量和文本,它完全按照我的意愿生成(在实施了一些 \n 替换解决方法之后),但我的标题都保持 Arial、10pt,而不是标题样式。

这是我的代码(我删除了中间的一小块,它生成了我的介绍,但它不包含标题):

//############################### STARTING DOCUMENT AND DEFINING STYLES ###############################
$phpWord = new \PhpOffice\PhpWord\PhpWord(); //start new document
$file = $document->titel . '.docx';

// adding the necessary font styles
$phpWord->addFontStyle('font_default', array('name'=>'HelveticaNeueLT Std Lt', 'size'=>11, 'color'=>'000000'));
$phpWord->addFontStyle('font_h1', array('name'=>'HelveticaNeueLT Std Med', 'size'=>16, 'color'=>'990000'));
$phpWord->addFontStyle('font_h2', array('name'=>'HelveticaNeueLT Std Med', 'size'=>14, 'color'=>'6D6D6D'));
$phpWord->addFontStyle('font_h3', array('name'=>'HelveticaNeueLT Std Med', 'size'=>12, 'color'=>'949494'));

//adding the necessary header/title styles
$phpWord->addTitleStyle(1, "font_h1"); //h1
$phpWord->addTitleStyle(2, "font_h2"); //h2
$phpWord->addTitleStyle(3, "font_h3"); //h3

//adding the necessary paragraph styles
$phpWord->addParagraphStyle('paragraph_default', array('spaceBefore' => …
Run Code Online (Sandbox Code Playgroud)

php phpword

2
推荐指数
1
解决办法
5643
查看次数

如何使用phpWord和使用cloneBlock将变量复制到模板中

在我的应用程序中使用phpWord,我尝试在模板中克隆一个块,如下所示:

${CLONEME} <br>
     You may also notice that there’s one text break (empty paragraph) before this one that can be created also by PHPWord ${item}" <br>
${/CLONEME}
Run Code Online (Sandbox Code Playgroud)

在我的PHP代码中执行此操作: $document->cloneBlock('CLONEME', 2}

我获得:

"您可能还注意到,在此之前还有一个文本中断(空段落),也可以由PHPWord $ {item}创建.
您可能还注意到,在此之前还有一个文本中断(空段落)也可以通过PHPWord $ {item}"

${item}不要重复.

我希望有 :

"您可能还注意到,在此之前还有一个文本中断(空段落)也可以由PHPWord创建$ {item#1}您可能还注意到在此之前有一个文本中断(空段落)可以创建也是由PHPWord $ {item#2}"

我怎样才能做到这一点 ?谢谢

php phpword

2
推荐指数
1
解决办法
3796
查看次数

如何更改 phpword 中的字体(名称、大小、行距)?

您能否告诉我是否可以将 docx 文档加载到 phpword,然后更改加载的文档中的字体名称、大小、行距,然后将其保存到另一个 docx 文件中?

我现在正在阅读 phpword 官方 docx,但正如我所见,创建一个新文档(例如,通过段落的某些字体名称、大小和行间距设置)比更改加载的文档要多得多。或者也许我错了?

那么是否可以为加载的文档更改这些“字体设置”?或者也许可以对加载的文档进行一些解析,例如对所有段落进行一些解析,然后为每个文本段落更改“字体设置”?

预先感谢您的帮助!

真诚的你,

阿尔韦苏

php linux fonts docx phpword

2
推荐指数
1
解决办法
8100
查看次数

如何用phpword设置表格宽度?

文档说可以在 addTable 中设置表格宽度,但我不明白如何使其工作。另外我需要设置我尝试过的 100% 宽度:

$table = $section->addTable(array(
  'width' => 100
));
$table = $section->addTable(array(
  'width' => '100'
));
$table = $section->addTable(array(
  'width' => '100%'
));
Run Code Online (Sandbox Code Playgroud)

但似乎没有任何作用。我应该写什么才能让它发挥作用?

php phpword

2
推荐指数
1
解决办法
7873
查看次数

在phpWord模板文档中插入表格

我有里面template.docx有标记的模板${table}。我需要使用phpWord创建表,并在我的插入template.docx,而不是${table}标记内。这是我的代码示例

//Create simple table
$document_with_table = new PhpWord();
$section = $document_with_table->addSection();
$table = $section->addTable();
for ($r = 1; $r <= 8; $r++) {
    $table->addRow();
    for ($c = 1; $c <= 5; $c++) {
        $table->addCell(1750)->addText("Row {$r}, Cell {$c}");
    }
}

//Open template with ${table}
$template_document = new \PhpOffice\PhpWord\TemplateProcessor('template.docx');
// some code to replace ${table} with table from $document_with_table
// ???


//save template with table
$template_document->saveAs('template_with_table.docx');
Run Code Online (Sandbox Code Playgroud)

首先,我$document_with_table使用新的 PhpWord 实例在单独的变量中创建表。接下来我加载我的template.docxin$template_document …

php phpword phpoffice

2
推荐指数
2
解决办法
5867
查看次数

标签 统计

phpword ×10

php ×9

codeigniter ×1

docx ×1

fonts ×1

linux ×1

mysql ×1

phpoffice ×1