栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Apache POI-条件格式-需要为规则和格式设置不同的单元格范围

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Apache POI-条件格式-需要为规则和格式设置不同的单元格范围

Excel
提供基于公式的条件格式设置规则。

如果in的值是数字且大于5 , 则该公式

=AND(ISNUMBER($C1),$C1>5)
返回。如果将此公式应用于范围,则如果相应行的列中的值满足该条件,则此范围内的每个单元格都为true
。那是因为列在公式中使用固定。但是行号不是固定的,因此是固定的。
True``$C1``G1:L1000``C``C``$C

使用示例

apache poi

import org.apache.poi.ss.usermodel.*;import org.apache.poi.xssf.usermodel.XSSFWorkbook;import org.apache.poi.ss.util.CellRangeAddress;import java.io.FileOutputStream;public class ConditionalFormatting { public static void main(String[] args) throws Exception {  Workbook workbook = new XSSFWorkbook();  Sheet sheet = workbook.createSheet("new sheet");  SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();  ConditionalFormattingRule rule = sheetCF.createConditionalFormattingRule("AND(ISNUMBER($C1), $C1>5)");  PatternFormatting fill = rule.createPatternFormatting();  fill.setFillBackgroundColor(IndexedColors.YELLOW.index);  fill.setFillPattern(PatternFormatting.SOLID_FOREGROUND);  ConditionalFormattingRule[] cfRules = new ConditionalFormattingRule[]{rule};  CellRangeAddress[] regions = new CellRangeAddress[]{CellRangeAddress.valueOf("G1:L1000")};  sheetCF.addConditionalFormatting(regions, cfRules);  workbook.write(new FileOutputStream("ConditionalFormatting.xlsx"));  workbook.close(); }}

现在,如果您在

C
数字列中放置数值大于5的内容,则列中的单元格
G:L
将填充为黄色。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/506496.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号