PHPWordDocs062Word格式.docx
- 文档编号:16393148
- 上传时间:2022-11-23
- 格式:DOCX
- 页数:21
- 大小:35.94KB
PHPWordDocs062Word格式.docx
《PHPWordDocs062Word格式.docx》由会员分享,可在线阅读,更多相关《PHPWordDocs062Word格式.docx(21页珍藏版)》请在冰豆网上搜索。
Tosetthesepropertiesusethefollowingcode:
$properties=$PHPWord->
getProperties();
$properties->
setCreator('
Myname'
setCompany('
Myfactory'
setTitle('
Mytitle'
setDescription('
Mydescription'
setCategory('
Mycategory'
setLastModifiedBy('
setCreated(mktime(0,0,0,3,12,2010));
setModified(mktime(0,0,0,3,14,2010));
setSubject('
Mysubject'
setKeywords('
my,key,word'
Sections
Addasection
Everyvisibleelementinwordisplacedinsideofasection.Tocreateadefaultsectionusethefollowingcode:
$section=$PHPWord->
createSection();
Thecodeabovecreatesadefaultsection(portraitoriented)withdefaultmargins.
Stylesections
Therearetwowaystostyleyoursections:
Stylewithgivenarray:
$sectionStyle=array('
orientation'
=>
null,
'
marginLeft'
900,
marginRight'
marginTop'
marginBottom'
900);
createSection(sectionStyle);
Styleaftercreatingthesection:
$sectionStyle=$section->
getSettings();
$sectionStyle->
setLandscape();
setPortrait();
setMarginLeft(900);
setMarginRight(900);
setMarginTop(900);
setMarginBottom(900);
Availablestyleproperties
Propertiesareallcasesensitive!
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!
pageSizeW
Pagewidthintwips.
pageSizeH
Pageheightintwips.
TextElements
Addtextelements
ToaddtextelementstoyourworddocumentusethefunctionaddText.
$section->
addText($text,[$fontStyle],[$paragraphStyle]);
addText()
Parameters
$text
Textthatappearsinthedocument.
$fontStyle
String/Array
Fontstyleofthetext.
$paragraphStyle
Paragraphstyleofthetext.
Addtextrunelements
Atextrunelementcancontaintextorlinkelements.Allelementsareplacedinsideoneparagraphwiththeoptionallygivenparagraphstyle.ToaddatextrunusethefunctioncreateTextrun.
createTextRun()
Aftercreatingthetextrunyoucanaddtextorlinkelementswithindividualstyles.
$textrun=$section->
createTextRun();
$textrun->
addText('
Iambold'
array('
bold'
=>
true));
Iamitalic,array('
italic'
Iamcolored,array('
color'
'
AACC00'
));
Ofcourseyoucanusethepredefinedparagraphorfontstyles.Seechapter“Styletextelements”formoreinformation.
Styletextelements
Thereare2optionstostyletheinsertedtextelements:
InlineStyle:
$fontStyle=array('
006699'
'
size'
18,'
true);
helloWorld'
$fontStyle);
$text=$section->
$style=$text->
getStyle();
$style->
setColor('
setSize(18);
setBold();
Oryoucanstyleyourtextbyusingastyledefinition.Afterdefiningastyleyouhavetosetthesecondparametertothenameofyourstyle.UsethefunctionaddFontStyle:
addFontStyle($styleName,$fontStyle);
addFontStyle()
$styleName
Nameofthefontstyle.
Array
Fontstyle.
Example:
addFontStyle('
myOwnStyle'
Toaddaparagraphstyledefinition,usethefunctionaddParagraphStyle:
addParagraphStyle()
Nameoftheparagraphstyle.
Paragraphstyle.
FontStyle
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
align
Horizontalalignment.Possibleare:
▪left
▪right
▪center
▪both/justify
spaceBefore
Topmarginofthetextintwips.
spaceAfter
Bottommarginofthetextintwips
spacing
Marginbetweenthetextlinesintwips.
Addtextbreaks
ToaddatextbreakusethefunctionaddTextBreak:
addTextBreak();
Ifyouneedmorethanonetextbreakyoucansetamultipletextbreaklikethis:
addTextBreak(15);
Thecodeaboveinserts15textbreaks.
Addpagebreaks
ToaddamanualpagebreakyoucanusethefunctionaddPageBreak:
addPageBreak();
Listelements
Addlistelements
ToaddalistitemusethefunctionaddListItem:
addListItem($text,[$depth],[$styleText],[$styleList],[$styleParagraph]);
addListItem()
$depth
Integer
De
$styleText
Fontstyleofthecurrentlistelement.Seethechapter"
Styletextelements"
formoreinformation.
$styleList
Liststyleofthecurrentelement.
$styleParagraph
Paragraphstyleofthecurrentlistelement.Seethechapter"
Stylelistelements
Exampleofstylinglistelements:
$listStyle=array('
listType'
PHPWord_Style_ListItem:
TYPE_NUMBER);
addListItem('
Listitem1'
0,null,$listStyle);
Availableliststyleproperties
listType
Listpointstyle.
UsetheconstantsinPHPWord_Style_ListItem:
TYPE_...
Hyperlinks
AddHyperlinks
YoucanaddHyperlinkstothedocumentbyusingthefunctionaddLink:
addLink($linkSrc,[$linkName],[$styleFont],[$styleParagraph]);
$linkSrc
TheURLoftheLink.
$linkName
PlaceholderoftheURLthatappearsinthedocument.
$styleFont
StyleoftheLink.Seethechapter"
Paragraphstyleofthelink.Seethechapter"
StyleHyperlinks
Therearetwowaystostyleahyperlink.
$linkStyle=array('
0000FF'
underline'
UNDERLINE_SINGLE);
addLink('
http:
//www.google.de'
null,$linkStyle);
Oryoucanstylethehyperlinkbyusingastyledefinition.Afterdefiningastyleyouhavetosetthethirdparametertothenameofyourstyle.
addLinkStyle('
myHyperlinkStyle'
$linkStyle);
null,'
addLinkStyle()
ThenameoftheLinkstyle.
$styles
Linkstyle.Allfontstylepropertiesarepossible.Seethechapter"
Images
Addimages
ToaddanimageusethefunctionaddImage:
addImage($src,[$style]);
addImage()
$src
Pathtotheimageonthewebserver.Thepathcanbearelativeoraabsolutepath.
$style
Imagestyle.
Styleimages
Tostyleanimageyoucanonlyuseanarray:
$imageStyle=array('
width'
350,'
height'
align'
center'
addImage('
EARTH.jpg'
$imageStyle);
width
Imagewidthinpixel
height
Imageheightinpixel
Imagealignmentinthedocument.Possibleare:
Ifnowidthandheightisgiven,PHPWordtriestodetectthewidth/heightpropertiesbyusingthenativePHPfunction"
getimagesize"
.
PHPWordsupportstheimagetypesgif,jpeg,png,bmp,tiff.
Addmemoryimages
YoucanalsoaddimagesthathavebeencreatedbyGD.ToaddanGDimageusethefunctionaddMemoryImage:
addMemoryImage($link,[$style]);
addMemoryImage()
$link
ThefirstparameterindicatesthesourcetothePHPFile.I
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- PHPWordDocs062