(本文档仅供参考,仅适用于本文档中的示例报表/场景,若实际报表/场景与示例代码无法完全适配(如使用功能不一致,或多个宏代码冲突等),需根据实际需求开发代码。)
问题
想要修改电子表格轮播控件样式,但是在【界面设置】中自定义样式没有生效,那要怎么修改对应样式呢?
说明
由于电子表格是以iframe格式存在,在自定义样式中编写的css样式规则无法应用到iframe内部,对于iframe来说,如需设置样式须在iframe内部进行设置。
解决方案
可以考虑通过编写报表宏来对电子表格中轮播控件自定义样式,如下所示。
宏类型 | 对象 | 事件 |
---|---|---|
客户端宏 | spreadsheetReport | onRender |
function main(spreadsheetReport, isAjaxRefreshCallback) { var doc = spreadsheetReport.elemSheetFrame.contentDocument; var styleSheet = doc.styleSheets[0]; //获取到样式表 var ruleLength = styleSheet.cssRules.length; //获取到里面样式的数量 var newRule1 = ".swiper-pagination-bullet-active {opacity: 1 !important;background: #ff0000 !important;}"; var newRule2 = ".swiper-pagination-bullet {width: 48px !important; height: 8px !important; border-radius: 0% !important; background: #00ff00 !important; opacity: 0.5 !important;}"; // 插入新的样式 styleSheet.insertRule(newRule1, ruleLength); styleSheet.insertRule(newRule2, ruleLength); }