libreoffice API 开发(五):处理段落

     其实UNO的编程都是一个套路,通过文档工厂获得实例,然后看看该实例的类成员函数有哪些功能,设置可用的属性。当然,如果其中涉及到和其他组件或者实例交互的时候就需要自己仔细研究了。

    处理段落的代码很简单,直接贴下来。

    

void manipulateParagraph(Reference <XTextDocument> xTextDocument)
{
    Reference <XText> xText = xTextDocument->getText();
    Reference<XTextCursor> xTextCursor(xText->createTextCursorByRange(xText->getEnd()),UNO_QUERY);
    Reference <XPropertySet> xProps(xTextCursor,UNO_QUERY);


    /// 设置左右间距

    sal_Int32 margin;
    margin = 3000;
    Any any_margin;
    any_margin <<= margin;
    xProps->setPropertyValue("ParaLeftMargin",any_margin);


    /// 设置字体
    Any fontname;
    fontname <<= OUString::createFromAscii("Arial");
    xProps->setPropertyValue("CharFontName",fontname);

    ///设置字体颜色
    sal_Int32 charcolor = 0x000099;
    Any any_charcolor;
    any_charcolor <<= charcolor;
    xProps->setPropertyValue("CharColor",any_charcolor);

    ///设置粗体
    Any fontweight;
    fontweight <<=::com::sun::star::awt::FontWeight::BOLD;
    xProps->setPropertyValue("CharWeight",fontweight);

    ///设置字体大小
    sal_Int32 height;
    height = 20;
    Any any_height;
    any_height <<= height;
    xProps->setPropertyValue("CharHeight",any_height);
    xText->insertString(xText->getEnd(),"This is a paragraph.We write words here and set paragraph style later.The effect is easy to see.Some atrributes are setted!",false);

    ///居中显示
    sal_Int16 adjust = ::com::sun::star::style::ParagraphAdjust::ParagraphAdjust_CENTER;
    Any any_adjust;
    any_adjust <<= adjust;

    xProps->setPropertyValue("ParaAdjust",any_adjust);
    
    xText->insertControlCharacter(xText->getEnd(),::com::sun::star::text::ControlCharacter::PARAGRAPH_BREAK,false);
   
  
}

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值