可以采用富文本- signRequiredStar(sheet: GC.Spread.Sheets.Worksheet) {
- const rowCount = sheet.getRowCount() // 获取总行数
- // 遍历第一列,检查行名是否包含 'OTP' 或 'OTC'
- for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
- const cellValue = sheet.getValue(rowIndex, 0) // 获取第一列的值(行名)
- // 如果行名包含 'OTP' 或 'OTC'
- if (cellValue && (cellValue.includes('test') || cellValue.includes('pro'))) {
- // 创建富文本对象并设置星号部分为红色
- const richText = [
- {
- text: cellValue.substring(0, cellValue.indexOf('*')), // 星号之前的文本
- },
- {
- style: { foreColor: 'red' },
- text: '*', // 红色星号
- },
- {
- text: cellValue.substring(cellValue.indexOf('*') + 1), // 星号之后的文本
- },
- ]
- // 设置单元格的富文本
- sheet.setValue(rowIndex, 0, { richText }, GC.Spread.Sheets.SheetArea.viewport)
- }
- }
- }
复制代码
|