//背景色、フォント色、枠線より各種XSSFCellStyleの作成して、cellStyleMapに保存する
private HashMap<String, XSSFCellStyle> createXssfCellStyle() {
HashMap<String, XSSFCellStyle> cellStyleMap = new HashMap<>(); XSSFCellStyle xssfCellStyle;
String mapKey = "";
XSSFColor[] xssfColorArr = new XSSFColor[bgColorArr.length];
XSSFFont[] xssfFontArr = new XSSFFont[fontColorArr.length];
for(int bgColorIndex=0; bgColorIndex<bgColorArr.length; bgColorIndex++) {
xssfColorArr[bgColorIndex] = createXssfColor(bgColorArr[bgColorIndex]);
}
for(int fontColorIndex=0; fontColorIndex<fontColorArr.length; fontColorIndex++) {
xssfFontArr[fontColorIndex] = createXssfFont(fontColorArr[fontColorIndex]);
} for (int bgColorIndex=0; bgColorIndex<bgColorArr.length; bgColorIndex++) {
for(int fontColorIndex=0; fontColorIndex<fontColorArr.length; fontColorIndex++) {
for(int rightBorderNameIndex=0; rightBorderNameIndex<borderNameArr.length; rightBorderNameIndex++ ) {
for (int bottomBorderNameIndex=0; bottomBorderNameIndex<borderNameArr.length; bottomBorderNameIndex++ ) {
for (int dataFormatIndex=0; dataFormatIndex<dataFormatArr.length; dataFormatIndex++) {
for (int wrapTextIndex=0; wrapTextIndex < wrapTextArr.length; wrapTextIndex++) {
xssfCellStyle = wb.createCellStyle();
xssfCellStyle.setFillForegroundColor(xssfColorArr[bgColorIndex]);
xssfCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
xssfCellStyle.setFont(xssfFontArr[fontColorIndex]);
xssfCellStyle.setBorderTop(BorderStyle.HAIR);
xssfCellStyle.setBorderLeft(BorderStyle.HAIR);
xssfCellStyle.setBorderRight(BorderStyle.valueOf(borderNameArr[rightBorderNameIndex]));
xssfCellStyle.setBorderBottom(BorderStyle.valueOf(borderNameArr[bottomBorderNameIndex]));
xssfCellStyle.setDataFormat(dataFormatArr[dataFormatIndex]);
xssfCellStyle.setWrapText(wrapTextArr[wrapTextIndex]); //right border name(MEDIUMやHAIR) + bottom border name(MEDIUMやHAIR) + font color(000000など) + background color (ffffffなど)
mapKey = borderNameArr[rightBorderNameIndex]
+ borderNameArr[bottomBorderNameIndex]
+ fontColorArr[fontColorIndex]
+ bgColorArr[bgColorIndex]
+ dataFormatArr[dataFormatIndex]
+ wrapTextKeyArr[wrapTextIndex];
cellStyleMap.put(mapKey, xssfCellStyle);
} } }
}
}
}
return cellStyleMap;
} //右枠線のNAME、下枠線のNAME、フォント色、背景色より、合っているXSSFCellStyleを取得
private XSSFCellStyle getXssfCellStyle(String rightBorderName, String bottomBorderName, String fontColor, String bgColor, int dataFormat, boolean isWrapped ) {
String wrapTextKey = WRAP_TEXT_KEY_FALSE;
if (isWrapped) {
wrapTextKey = WRAP_TEXT_KEY_TRUE;
}
String mapKey = rightBorderName + bottomBorderName + fontColor + bgColor + dataFormat + wrapTextKey;
if (!xssfCellStyleMap.containsKey(mapKey)) {
}
return xssfCellStyleMap.get(mapKey);
}

  

POI--各种样式的XSSFCellStyle的生成的更多相关文章

  1. ExcelHelper----根据指定样式的数据,生成excel(一个sheet1页)文件流

    /// <summary> /// Excel导出类 /// </summary> public class ExcelHelper { /// <summary> ...

  2. JAVA POI 应用系列(1)--生成Excel

    POI简介(官网:http://poi.apache.org/)     Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office ...

  3. poi操作excel2007(读取、生成、编辑)

    因为现在再写excel2003版的比较low,所以我在这就不介绍了,直接介绍2007,我所用的编程软件是IDEA poi操作office总共有6个jar包,在pom.xml文件中配置如下,也可下载后直 ...

  4. 漂亮的CSS按钮样式集以及在线生成工具

    以前我们制作一样带带阴影.圆角或3D感的按钮都需要用图片来制作,但CSS3出来后就可以不用图片了,由于是代码写的按钮样式,在Retina上浏览依然清晰美观.虽然不错,但我们写一个阴影+质感的按钮还是挺 ...

  5. iText、poi操作word2007(读取,生成)

    关于生成word文件以及插入文字.表格.图片等功能,我使用了poi和itext,因为poi插入图片的jar包我在网上查并不是太完全,也可能我没找到如何使用,所以插入图片我用的是itext iText所 ...

  6. POI格式化Cell样式

    通过一个实例演示怎样通过POI设置Excel单元格的边框.字体.颜色.大小.下划线.合并.对齐方式. Excel文件如下: Java代码   package my.excel;       impor ...

  7. POI简易帮助文档系列--给Excel设置样式

    正如Html需要CSS一样,我们的POI生成的Excel同样需要样式才能更完美的表现我们的数据.下面还是从简单的例子出发,学习和了解POI的样式设计. 一.我的位置. package com.myja ...

  8. Servlet 中使用POI生成Excel

    使用的是poi3.13 http://mvnrepository.com/artifact/org.apache.poi/poi/3.13 import java.io.IOException; im ...

  9. Java利用POI生成Excel强制换行

    前一段时间在做一个学校排课系统时,有一个地方需要利用把课程表生成excel汇出给客户,由于之前用excel都只是简单的应用,在单元格里都是用自动换行,而这次可能需要用到手动强制换行. 于是我在网上找了 ...

随机推荐

  1. 关于Rabbitmq的routingkey的作用

    对于消息发布者而言它只负责把消息发布出去,甚至它也不知道消息是发到哪个queue,消息通过exchange到达queue,exchange的职责非常简单,就是一边接收发布者的消息一边把这些消息推到qu ...

  2. Nginx的编译安装及选项

    编译安装Nginx1.安装常见的工具和库(GCC.PCRE.zlib.OpenSSL) Nginx是一个由C语言编写的,所以需要一个编译工具如GNU的GCC[root@www ~]# yum inst ...

  3. RTP协议

    RTP协议格式: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+ ...

  4. 再见VB6!再见程序生涯!

    今天写一篇博文告别使用了15年的VB6,从此终结程序生涯.记得读大学的时候第一学习编程,用VB6嵌入MediaPlayer控件写了一个简易视频播放器,看着视频的画面激动人心,从此就爱上了编程,从此也和 ...

  5. Spring Cloud Turbine微服务集群实时监控

    本文代码下载地址: https://gitlab.com/mySpringCloud/turbine SpringBoot版本:1.5.9.RELEASE (稳定版) SpringCloud版本:Ed ...

  6. Ubuntu 16.04安装Docker-CE

    系统环境 * Ubuntu: 16.04 * Docker: 17.09.0-ce 安装步骤 1.安装Docker-CE,具体参考:https://docs.docker.com/engine/ins ...

  7. 初次使用BAT,请检查Chrome浏览器和ChromeDriver兼容性

    ChromeDriver可以理解为Chrome驱动,它是架在BAT程序和Chrome之间的桥梁.但是ChromeDriver的问题是,每个版本的兼容范围很窄,通常只能兼容3个Chrome版本. 因此, ...

  8. 高性能 TCP/UDP/HTTP 通信框架 HP-Socket v4.1.3

    HP-Socket 是一套通用的高性能 TCP/UDP/HTTP 通信框架,包含服务端组件.客户端组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP/HTTP 通信系统,提供 C/ ...

  9. JPA相关知识

    这篇文章是摘自Patrick Linskey的一篇文章,主要是关于JPA相关内容的问答,相信JPA面试会碰到很多这里面的问题 问题:EJB专家团队是如何摆脱事务描述符的? 回答:在会话bean和消息驱 ...

  10. linux/centos elasticsearch 环境搭建 安装 运行 使用

    环境搭建也是有些坑的存在,所以整理了一下搭建流程,安全无痛. ElasticSearch是一个开源的分布式搜索引擎,具备高可靠性,支持非常多的企业级搜索用例. 一.java 环境 直接apt安装火箭一 ...