PHPWordDocs062.docx

上传人:b****4 文档编号:3487752 上传时间:2022-11-23 格式:DOCX 页数:21 大小:35.94KB
下载 相关 举报
PHPWordDocs062.docx_第1页
第1页 / 共21页
PHPWordDocs062.docx_第2页
第2页 / 共21页
PHPWordDocs062.docx_第3页
第3页 / 共21页
PHPWordDocs062.docx_第4页
第4页 / 共21页
PHPWordDocs062.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

PHPWordDocs062.docx

《PHPWordDocs062.docx》由会员分享,可在线阅读,更多相关《PHPWordDocs062.docx(21页珍藏版)》请在冰豆网上搜索。

PHPWordDocs062.docx

PHPWordDocs062

PHPWordBeta0.6.2

DevelopersGuide

Tableofcontents

Whatthehellaretwips?

You'lloftenfindtheunittwipsinthisdocumentation.TwipsarethebaselengthunitinOpenOffice.Twipmeans"TWentiethofanInchPoint".So1twip=1/1440inch.

SetdefaultFont

BydefaulteverytextappearsinArialfontwithfontsizeof10point.Youcanalterthedefaultfontbyusingthefollowingtwofunctions:

$PHPWord->setDefaultFontName('Tahoma');

$PHPWord->setDefaultFontSize(12);

Setdocumentproperties

Youcansetthefollowingdocumentproperties:

Name

Type

Creator

String

Company

String

Title

String

Description

String

Category

String

Lastmodifiedby

String

Created

Datetime

Modified

Datetime

Subject

String

Keywords

String

Tosetthesepropertiesusethefollowingcode:

$properties=$PHPWord->getProperties();

$properties->setCreator('Myname');

$properties->setCompany('Myfactory');

$properties->setTitle('Mytitle');

$properties->setDescription('Mydescription');

$properties->setCategory('Mycategory');

$properties->setLastModifiedBy('Myname');

$properties->setCreated(mktime(0,0,0,3,12,2010));

$properties->setModified(mktime(0,0,0,3,14,2010));

$properties->setSubject('Mysubject');

$properties->setKeywords('my,key,word');

Sections

Addasection

Everyvisibleelementinwordisplacedinsideofasection.Tocreateadefaultsectionusethefollowingcode:

$section=$PHPWord->createSection();

Thecodeabovecreatesadefaultsection(portraitoriented)withdefaultmargins.

Stylesections

Therearetwowaystostyleyoursections:

Stylewithgivenarray:

$sectionStyle=array('orientation'=>null,

'marginLeft'=>900,

'marginRight'=>900,

'marginTop'=>900,

'marginBottom'=>900);

$section=$PHPWord->createSection(sectionStyle);

Styleaftercreatingthesection:

$section=$PHPWord->createSection();

$sectionStyle=$section->getSettings();

$sectionStyle->setLandscape();

$sectionStyle->setPortrait();

$sectionStyle->setMarginLeft(900);

$sectionStyle->setMarginRight(900);

$sectionStyle->setMarginTop(900);

$sectionStyle->setMarginBottom(900);

Availablestyleproperties

Propertiesareallcasesensitive!

Name

Description

Orientation

Pageorientation.Possiblevaluesare:

▪null(meansportraitorientation)

▪landscape

marginTop

Pagemargintopintwips.

marginLeft

Pagemarginleftintwips.

marginRight

Pagemarginrightintwips.

marginBottom

Pagemarginbottomintwips.

borderTopSize

Bordertopsizeintwips.

borderTopColor

BordertopcolorinHEX.

borderLeftSize

Borderleftsizeintwips.

borderLeftColor

BorderleftcolorinHEX.

borderRightSize

Borderrightsizeintwips.

borderRightColor

BorderrightcolorinHEX.

borderBottomSize

Borderbottomsizeintwips.

borderBottomColor

BorderbottomcolorinHEX.

Thefollowingtwopropertiesareautomaticallysetbytheuseoftheorientationproperty.Youcanalterthembutthat'snotrecommended!

Name

Description

pageSizeW

Pagewidthintwips.

pageSizeH

Pageheightintwips.

TextElements

Addtextelements

ToaddtextelementstoyourworddocumentusethefunctionaddText.

$section->addText($text,[$fontStyle],[$paragraphStyle]);

addText()

Parameters

Type

Description

$text

String

Textthatappearsinthedocument.

$fontStyle

String/Array

Fontstyleofthetext.

$paragraphStyle

String/Array

Paragraphstyleofthetext.

Addtextrunelements

Atextrunelementcancontaintextorlinkelements.Allelementsareplacedinsideoneparagraphwiththeoptionallygivenparagraphstyle.ToaddatextrunusethefunctioncreateTextrun.

createTextRun()

Parameters

Type

Description

$paragraphStyle

String/Array

Paragraphstyleofthetext.

Aftercreatingthetextrunyoucanaddtextorlinkelementswithindividualstyles.

$textrun=$section->createTextRun();

$textrun->addText('Iambold',array('bold'=>true));

$textrun->addText('Iamitalic,array('italic'=>true));

$textrun->addText('Iamcolored,array('color'=>'AACC00'));

Ofcourseyoucanusethepredefinedparagraphorfontstyles.Seechapter“Styletextelements”formoreinformation.

Styletextelements

Thereare2optionstostyletheinsertedtextelements:

InlineStyle:

$fontStyle=array('color'=>'006699','size'=>18,'bold'=>true);

$section->addText('helloWorld',$fontStyle);

$text=$section->addText('helloWorld');

$style=$text->getStyle();

$style->setColor('006699');

$style->setSize(18);

$style->setBold();

Oryoucanstyleyourtextbyusingastyledefinition.Afterdefiningastyleyouhavetosetthesecondparametertothenameofyourstyle.UsethefunctionaddFontStyle:

$PHPWord->addFontStyle($styleName,$fontStyle);

addFontStyle()

Parameters

Type

Description

$styleName

String

Nameofthefontstyle.

$fontStyle

Array

Fontstyle.

Example:

$fontStyle=array('color'=>'006699','size'=>18,'bold'=>true);

$PHPWord->addFontStyle('myOwnStyle',$fontStyle);

$text=$section->addText('helloWorld','myOwnStyle');

Toaddaparagraphstyledefinition,usethefunctionaddParagraphStyle:

addParagraphStyle()

Parameters

Type

Description

$styleName

String

Nameoftheparagraphstyle.

$paragraphStyle

Array

Paragraphstyle.

Availablestyleproperties

Propertiesareallcasesensitive!

FontStyle

Name

Description

size

Fontsizeinpoints.

name

Fontfamily

bold

Bold

italic

Italic

superScript

SuperScript

subScript

SubScript

underline

Usethedefinedconstants:

PHPWord_Style_Font:

:

UNDERLINE_...

Color

Fontcolor

fgColor

Foregroundcolor.Youcanonlyusethepredefinedconstants:

PHPWord_Style_Font:

:

FGCOLOR_...

ParagraphStyle

Name

Description

align

Horizontalalignment.Possibleare:

▪left

▪right

▪center

▪both/justify

spaceBefore

Topmarginofthetextintwips.

spaceAfter

Bottommarginofthetextintwips

spacing

Marginbetweenthetextlinesintwips.

Addtextbreaks

ToaddatextbreakusethefunctionaddTextBreak:

$section->addTextBreak();

Ifyouneedmorethanonetextbreakyoucansetamultipletextbreaklikethis:

$section->addTextBreak(15);

Thecodeaboveinserts15textbreaks.

Addpagebreaks

ToaddamanualpagebreakyoucanusethefunctionaddPageBreak:

$section->addPageBreak();

Listelements

Addlistelements

ToaddalistitemusethefunctionaddListItem:

$section->addListItem($text,[$depth],[$styleText],[$styleList],[$styleParagraph]);

addListItem()

Parameters

Type

Description

$text

String

Textthatappearsinthedocument.

$depth

Integer

De

$styleText

String/Array

Fontstyleofthecurrentlistelement.Seethechapter"Styletextelements"formoreinformation.

$styleList

Array

Liststyleofthecurrentelement.

$styleParagraph

String/Array

Paragraphstyleofthecurrentlistelement.Seethechapter"Styletextelements"formoreinformation.

Stylelistelements

Exampleofstylinglistelements:

$listStyle=array('listType'=>PHPWord_Style_ListItem:

:

TYPE_NUMBER);

$section->addListItem('Listitem1',0,null,$listStyle);

Availableliststyleproperties

Propertiesareallcasesensitive!

Name

Description

listType

Listpointstyle.

UsetheconstantsinPHPWord_Style_ListItem:

:

TYPE_...

Hyperlinks

AddHyperlinks

YoucanaddHyperlinkstothedocumentbyusingthefunctionaddLink:

$section->addLink($linkSrc,[$linkName],[$styleFont],[$styleParagraph]);

addListItem()

Parameters

Type

Description

$linkSrc

String

TheURLoftheLink.

$linkName

String

PlaceholderoftheURLthatappearsinthedocument.

$styleFont

String/Array

StyleoftheLink.Seethechapter"Styletextelements"formoreinformation.

$styleParagraph

String/Array

Paragraphstyleofthelink.Seethechapter"Styletextelements"formoreinformation.

StyleHyperlinks

Therearetwowaystostyleahyperlink.

InlineStyle:

$linkStyle=array('color'=>'0000FF',

'underline'=>PHPWord_Style_Font:

:

UNDERLINE_SINGLE);

$section->addLink('http:

//www.google.de',null,$linkStyle);

Oryoucanstylethehyperlinkbyusingastyledefinition.Afterdefiningastyleyouhavetosetthethirdparametertothenameofyourstyle.

$linkStyle=array('color'=>'0000FF',

'underline'=>PHPWord_Style_Font:

:

UNDERLINE_SINGLE);

$PHPWord->addLinkStyle('myHyperlinkStyle',$linkStyle);

$section->addLink('http:

//www.google.de',null,'myHyperlinkStyle');

addLinkStyle()

Parameters

Type

Description

$styleName

String

ThenameoftheLinkstyle.

$styles

Array

Linkstyle.Allfontstylepropertiesarepossible.Seethechapter"Styletextelements"formoreinformation.

Images

Addimages

ToaddanimageusethefunctionaddImage:

$section->addImage($src,[$style]);

addImage()

Parameters

Type

Description

$src

String

Pathtotheimageonthewebserver.Thepathcanbearelativeoraabsolutepath.

$style

Array

Imagestyle.

Styleimages

Tostyleanimageyoucanonlyuseanarray:

$imageStyle=array('width'=>350,'height'=>350,'align'=>'center');

$section->addImage('EARTH.jpg',$imageStyle);

Availablestyleproperties

Propertiesareallcasesensitive!

Name

Description

width

Imagewidthinpixel

height

Imageheightinpixel

align

Imagealignmentinthedocument.Possibleare:

▪left

▪right

▪center

Ifnowidthandheightisgiven,PHPWordtriestodetectthewidth/heightpropertiesbyusingthenativePHPfunction"getimagesize".

PHPWordsupportstheimagetypesgif,jpeg,png,bmp,tiff.

Addmemoryimages

YoucanalsoaddimagesthathavebeencreatedbyGD.ToaddanGDimageusethefunctionaddMemoryImage:

$section->addMemoryImage($link,[$style]);

addMemoryImage()

Parameters

Type

Description

$link

String

ThefirstparameterindicatesthesourcetothePHPFile.I

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 合同协议

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1