LibreOffice BASIC修改幻灯片标题:无法找到Title属性求解决方案
LibreOffice Impress BASIC代码获取幻灯片标题的解决方法
旧版代码中的oSlide.Title属性在LibreOffice 7.5.4.2版本中已不再支持,可通过以下两种方式获取并设置幻灯片标题:
方法一:通过形状服务类型查找标题
遍历幻灯片的所有形状,筛选出标题类型的形状进行设置,该方法适配自定义模板场景:
oDoc = StarDesktop.LoadComponentFromURL("private:factory/simpress", "_blank", 0, Array()) oSlideList = oDoc.getDrawPages() oSlide = oSlideList.insertNewByIndex(oSlideList.Count) ' 遍历幻灯片形状,定位标题占位符 Dim oShape As Object For Each oShape In oSlide If oShape.supportsService("com.sun.star.drawing.TitleShape") Then oShape.Text.String = "Recent History of Artificial Intelligence" Exit For End If Next
方法二:通过占位符索引获取(默认模板场景)
默认模板的标题幻灯片中,第一个占位符通常为标题,可直接通过索引获取:
oDoc = StarDesktop.LoadComponentFromURL("private:factory/simpress", "_blank", 0, Array()) oSlideList = oDoc.getDrawPages() oSlide = oSlideList.insertNewByIndex(oSlideList.Count) ' 读取第一个占位符并设置标题文本 If oSlide.Count > 0 Then oTitle = oSlide.getByIndex(0) oTitle.Text.String = "Recent History of Artificial Intelligence" End If
内容的提问来源于stack exchange,提问作者tony gil
相关产品推荐
相关产品推荐

