Skip to content

How to add a paragraph to the front of the document? #1760

Open
@HuPengCheng1994

Description

@HuPengCheng1994

How do I add a paragraph in front of a document? I am loading a document now. I need to add a paragraph to the front of the loaded file. How do I do this? Currently only added to the last.

//读取文件
$file = "./正文.docx";
$word = \PhpOffice\PhpWord\IOFactory::load($file);

$section = $word->addSection();
$section->addTitle('所添加的标题内容', 1);

//生成文件
$name       = "HelloWorld.docx";
$wordWriter = \PhpOffice\PhpWord\IOFactory::createWriter($word, "Word2007");
$wordWriter->save($name);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions