Forum


Replies: 8   Views: 4079
Header styles in wordstyles in embedhtml
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by garyhillerson  · 04-02-2013 - 04:17

The new update fixed most of my problems with embedHTML, but I have one thing I can't figure out with the wordstyles array param.

I can map a paragraph style into a word style, but can't get Css Header styles (like H1.MyHeading) to map into my word styles.

I tried mapping H1.MyHeading and .MyHeading, but those paragraphs get mapped to Normal in both cases. Is there a designator of
Some sort I can use to map that and other CSS Hx styles?

G

Posted by HalloWelt  · 11-04-2013 - 12:13

*push*

Hi @ all!
First of all I'd like to say that PHPDOCX is a great piece of software. But I also have got some trouble with the mapping of HTML elements to Word Styles.

I use something like this

[code]
$oPHPDocX->replaceTemplateVariableByHTML(
$sPlaceholder,
'block',
$sContent,
array(
'isFile' => false,
'parseDivsAsPs' => true,
'downloadImages' => true,
'wordStyles' => array(
'<p>' => 'Standard',
'<h1>' => 'Titel',
'<h2>' => 'Überschrift 1',
'<li>' => 'Listeneintrag 1'
)
)
);
[/code]

But in the resulting DOCX the headings [b]<h1>[/b] and [b]<h2>[/b] as well as list items [b]<li>[/b] have the style [b]Standard[/b].

I've already updated to v3.2.

Posted by admin  · 11-04-2013 - 12:13

Hello,

Did you import that styles before using them?.

Regards.

Posted by HalloWelt  · 11-04-2013 - 12:13

I've tried it, yes.

My code contains the following lines:
[code]
$oPHPDocX = new CreateDocx();
$oPHPDocX->addTemplate( $sUploadPath.'/template/Template.docx' );
$oPHPDocX->importStyles( $sUploadPath.'/template/Template.docx' );
foreach( $aPlaceholders as $sPlaceholder => $sHTMLContent ) {
$oPHPDocX->replaceTemplateVariableByHTML(
$sPlaceholder,
'block',
$sHTMLContent,
array(
'isFile' => false,
'parseDivsAsPs' => true,
'downloadImages' => true,
'wordStyles' =>array(
'<p>' => 'Standard',
'<h1>' => 'Titel',
'<h2>' => 'Überschrift 1',
'<li>' => 'Listeneintrag 1'
)
)
);
}
[/code]

Do I have to use IDs for the wordStyles mapping? Or anything like this?

Posted by admin  · 11-04-2013 - 12:13

Hello,

You can use parseStyles method to get all available paragraph styles.

Regards.

Posted by HalloWelt  · 11-04-2013 - 12:13

Hi,

Thanks for the hint.

[code]
$oPHPDocX = new CreateDocx();
$oPHPDocX->addTemplate( $sUploadPath.'/template/Template.docx' );
var_dump( $oPHPDocX->parseStyles() );

[/code]

returns null.

The same is

[code]
var_dump( $oPHPDocX->parseStyles( $sUploadPath.'/template/Template.docx' ) );
[/code]

Maybe there is a problem with my template?

Posted by admin  · 11-04-2013 - 12:13

Hello,

You must import the styles from the template used as base. Please refer to examples/easy/ParseStyles.php; you can set the basetemplate when you invoke the constructor.

Regards.

Posted by HalloWelt  · 11-04-2013 - 12:13

Hi,

thanks for your advice! But it seems I found another suitable solution. I used PackageExplorer ([url]http://packageexplorer.codeplex.com/[/url]) to analyse my template. And I found that I have to use the IDs of a styling. And I had to set 'strictWordStyles' => true.

[code]
$oPHPDocX = new CreateDocx();
$oPHPDocX->addTemplate( $sUploadPath.'/template/Template.docx' );
$oPHPDocX->importStyles( $sUploadPath.'/template/Template.docx' );
foreach( $aPlaceholders as $sPlaceholder => $sHTMLContent ) {
$oPHPDocX->replaceTemplateVariableByHTML(
$sPlaceholder,
'block',
$sHTMLContent,
array(
'isFile' => false,
'parseDivsAsPs' => true,
'downloadImages' => true,
'wordStyles' =>array(
'<p>' => 'Standard',
'<h1>' => 'berschrift1',
'<h2>' => 'berschrift2',
'<h3>' => 'berschrift3',
'<h4>' => 'berschrift4',
.mytable' => 'Tabellenraster',
),
'strictWordStyles' => true
)
);
}
[/code]
I'v still got some trouble to get the mappings for table cells/headings and listentries working...
[code]
'<th>' => 'Tabellenberschrift',
'<td>' => 'TabellentextArial',
'<li>' => 'Listenabsatz'
[/code]