TXT2DOCX

Transforms plain text into WordML with custom styles.

PRO, PRO+ and CORPORATE PHPDocX >= 2.6

Description

public TXT2DOCX (string $source [, array $options])

This method allows to insert contents from a txt file into a Word document applying Word styles to it.

You may check the available styles for paragraphs, tables and lists with the help of the parseStyles method.

Parameters

source

The path to the txt file which contents we want to insert into a Word document.

options

The posible keys and values are:

key Type Description
styleTbl array The table style that you want to use.
styleLst array The list style that you want to use.
styleP array The paragraph style that you want to use.

Return values

Void.

Code samples

Example #1: converts a txt file to Word with different styling options


require_once '../../classes/CreateDocx.inc';
$docx->TXT2DOCX('../files/test.txt');
$docx->TXT2DOCX('../files/test.txt', array('styleTbl' => array('TBLSTYLEval' => 'LightShadingAccent1PHPDOCX'), 'styleLst' => array('val' => 2)));
$docx->TXT2DOCX('../files/test.txt', array('styleTbl' => array('TBLSTYLEval' => 'LightListAccent1PHPDOCX'), 'styleLst' => array('val' => 3) ));
$docx->TXT2DOCX('../files/test.txt', array('styleTbl' => array('TBLSTYLEval' => 'MediumShading2-accent2PHPDOCX'), 'styleLst' => array('val' => 4)));

$widthTableCols = array(
    1000,
    2500,
    3000
);
$docx->TXT2DOCX('../files/test_eduardo.txt', array('styleTbl' => array('border' => 'single', 'border_sz' => 20, 'size_col' => $widthTableCols), 'styleLst' => array('val' => 5)));

$docx->createDocxAndDownload('../docx/template_text_file');

The resulting Word document looks like (download .docx file):

Change log

  • Available since 2.6

See also