样式

一、样式是什么

样式是包含格式的列表。它们应用于所有libreOffice应用程序,有助于大大简化格式设置过程。如果用户更改了样式的某个属性,libreOffice将根据此属性自动调整文档的所有部分。例如,通过对文档进行集中修改,用户可以更改所有一级标题的字体类型。根据相关的文档类型,libreOffice可以识别各种不同的样式类型。

libreOffice Writer支持以下样式:
字符样式
段落样式
框架样式
页面样式
编号样式
libreOffice Calc支持以下样式:
单元格样式
页面样式
libreOffice Impress支持以下样式:
字符元素样式
演示文稿样式
以上样式都是com.sun.star.style.Style服务
多个com.sun.star.style.Style服务组成一个com.sun.star.style.StyleFamily服务
所有StyleFamily包含在com.sun.star.style.StyleFamilies服务中
有如下StyleFamily
CharacterStyles
the container of style sheets for sequences of characters within a text
ParagraphStyles
the container of style sheets for text paragraphs
FrameStyles
the container of style sheets for text frames
PageStyles
the container of style sheets for pages
NumberingStyles
the container for style sheets for numbering
CellStyles
the container for style sheets for cells
ShapeStyles
the container for style sheets for shapes

二、样式包含的属性

每种样式都提供了多种格式属性。

(一)字符样式包含字符属性,com.sun.star.style.CharacterProperties 服务

module com { module sun { module star { module style {
published service CharacterStyle
{
service Style;
service CharacterProperties;
[property] float CharDiffHeight;
[property] short CharPropHeight;
[property] float CharDiffHeightAsian;
[property] short CharPropHeightAsian;
[property] float CharDiffHeightComplex;
[property] short CharPropHeightComplex;
};
}; }; }; };

(二)段落样式包含段落属性,com.sun.star.text.Paragraph 服务

module com { module sun { module star { module style {
published service ParagraphStyle
{
service Style;
[optional] service com::sun::star::xml::ParaUserDefinedAttributesSupplier;
service ParagraphProperties;
[property] long ParaLeftMarginRelative;
[property] long ParaRightMarginRelative;
[property] long ParaTopMarginRelative;
[property] long ParaBottomMarginRelative;
[property] short Category;
[property] float CharDiffHeight;
[property] short CharPropHeight;
[property] float CharDiffHeightAsian;
[property] short CharPropHeightAsian;
[property] float CharDiffHeightComplex;
[property] short CharPropHeightComplex;
[optional, readonly, property] string PageStyleName;
};
}; }; }; };

(三)页面样式包括页面属性,com.sun.star.style.PageProperties 服务

module com { module sun { module star { module style {
published service PageStyle
{
service com::sun::star::style::Style;
service com::sun::star::style::PageProperties;
};
}; }; }; };

(四)单元格样式包含单元格属性,com.sun.star.table.CellProperties 服务

module com { module sun { module star { module sheet {
published service TableCellStyle
{
service com::sun::star::table::CellProperties;
service com::sun::star::style::CellStyle;
service com::sun::star::style::CharacterProperties;
service com::sun::star::style::CharacterPropertiesAsian;
service com::sun::star::style::CharacterPropertiesComplex;
service com::sun::star::style::ParagraphProperties;
};
}; }; }; };

三、获得style对象

Doc = StarDesktop.CurrentComponent
StyleFamilies = Doc.StyleFamilies
CellStyles = StyleFamilies.getByName("CellStyles")
For I = 0 To CellStyles.Count - 1
	CellStyle = CellStyles(I)
	MsgBox CellStyle.Name
Next I
Sub DisplayAllUsedParagraphStyles
oStyles = ThisComponent.StyleFamilies.getByName("ParagraphStyles")
For i = 0 To oStyles.getCount() -1
	oStyle = oStyles.getByIndex(i)
	If oStyle.isInUse() Then
		s = s & oStyle.DisplayName & CHR(10)
	End if
Next
MsgBox s,0,"Paragraph Styles In Use"
End Sub
Sub StyleProperties
oStyles = ThisComponent.StyleFamilies.getByName("ParagraphStyles")
Props = oStyles.getByName("_body text").getPropertySetInfo().getProperties()
For i = 0 To UBound(Props) 
	s = s & Props(i).Name & CHR$(10) 
	If (i+1) MOD 30 = 0 Then
		MsgBox s,0,"Style Properties" 
		s = "" 
	End If
Next
If Len(s) <> 0 Then
	MsgBox s,0,"Style Properties"
end if
End Sub

四、创建style

Sub CreateCharacterStyle(sStyleName$, oProps())
oFamilies = ThisComponent.StyleFamilies
oStyles = oFamilies.getByName("CharacterStyles")
If oStyles.HasByName(sStyleName) Then
	'PrintColor(oStyles.getByName(sStyleName).CharColor)
	Exit Sub
End If
oStyle = ThisComponent.createInstance("com.sun.star.style.CharacterStyle")
For i=LBound(oProps) To UBound(oProps)
	If oProps(i).Name = "ParentStyle" Then
		If oStyles.HasByName(oProps(i).Value) Then
			oStyle.ParentStyle = oProps(i).Value
		Else
			Print "Parent character style (" & oProps(i).Value & _
") does not exist, ignoring parent."
		End If
		oStyle.ParentStyle = oProps(i).Value
	Else
		oStyle.setPropertyValue(oProps(i).Name, oProps(i).Value)
	End If
Next
oStyles.insertByName(sStyleName, oStyle)
End Sub

五、删除style

Sub delstyles
odoc = thiscomponent
ostyles = odoc.stylefamilies.getbyname("CharacterStyles")
i = 0
While i < ostyles.getcount
	stylename = ostyles.getbyindex(i).getname
	'Print stylename
	if instr(stylename, "char style") > 0 Then
		ostyles.removebyname(stylename)
	Else
		i = i + 1
	End if
wend
End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值