1. //背景色、フォント色、枠線より各種XSSFCellStyleの作成して、cellStyleMapに保存する
  2. private HashMap<String, XSSFCellStyle> createXssfCellStyle() {
  3. HashMap<String, XSSFCellStyle> cellStyleMap = new HashMap<>();
  4.  
  5. XSSFCellStyle xssfCellStyle;
  6. String mapKey = "";
  7. XSSFColor[] xssfColorArr = new XSSFColor[bgColorArr.length];
  8. XSSFFont[] xssfFontArr = new XSSFFont[fontColorArr.length];
  9. for(int bgColorIndex=0; bgColorIndex<bgColorArr.length; bgColorIndex++) {
  10. xssfColorArr[bgColorIndex] = createXssfColor(bgColorArr[bgColorIndex]);
  11. }
  12. for(int fontColorIndex=0; fontColorIndex<fontColorArr.length; fontColorIndex++) {
  13. xssfFontArr[fontColorIndex] = createXssfFont(fontColorArr[fontColorIndex]);
  14. }
  15.  
  16. for (int bgColorIndex=0; bgColorIndex<bgColorArr.length; bgColorIndex++) {
  17. for(int fontColorIndex=0; fontColorIndex<fontColorArr.length; fontColorIndex++) {
  18. for(int rightBorderNameIndex=0; rightBorderNameIndex<borderNameArr.length; rightBorderNameIndex++ ) {
  19. for (int bottomBorderNameIndex=0; bottomBorderNameIndex<borderNameArr.length; bottomBorderNameIndex++ ) {
  20. for (int dataFormatIndex=0; dataFormatIndex<dataFormatArr.length; dataFormatIndex++) {
  21. for (int wrapTextIndex=0; wrapTextIndex < wrapTextArr.length; wrapTextIndex++) {
  22. xssfCellStyle = wb.createCellStyle();
  23. xssfCellStyle.setFillForegroundColor(xssfColorArr[bgColorIndex]);
  24. xssfCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  25. xssfCellStyle.setFont(xssfFontArr[fontColorIndex]);
  26. xssfCellStyle.setBorderTop(BorderStyle.HAIR);
  27. xssfCellStyle.setBorderLeft(BorderStyle.HAIR);
  28. xssfCellStyle.setBorderRight(BorderStyle.valueOf(borderNameArr[rightBorderNameIndex]));
  29. xssfCellStyle.setBorderBottom(BorderStyle.valueOf(borderNameArr[bottomBorderNameIndex]));
  30. xssfCellStyle.setDataFormat(dataFormatArr[dataFormatIndex]);
  31. xssfCellStyle.setWrapText(wrapTextArr[wrapTextIndex]);
  32.  
  33. //right border name(MEDIUMやHAIR) + bottom border name(MEDIUMやHAIR) + font color(000000など) + background color (ffffffなど)
  34. mapKey = borderNameArr[rightBorderNameIndex]
  35. + borderNameArr[bottomBorderNameIndex]
  36. + fontColorArr[fontColorIndex]
  37. + bgColorArr[bgColorIndex]
  38. + dataFormatArr[dataFormatIndex]
  39. + wrapTextKeyArr[wrapTextIndex];
  40. cellStyleMap.put(mapKey, xssfCellStyle);
  41. }
  42.  
  43. }
  44.  
  45. }
  46. }
  47. }
  48. }
  49. return cellStyleMap;
  50. }
  51.  
  52. //右枠線のNAME、下枠線のNAME、フォント色、背景色より、合っているXSSFCellStyleを取得
  53. private XSSFCellStyle getXssfCellStyle(String rightBorderName, String bottomBorderName, String fontColor, String bgColor, int dataFormat, boolean isWrapped ) {
  54. String wrapTextKey = WRAP_TEXT_KEY_FALSE;
  55. if (isWrapped) {
  56. wrapTextKey = WRAP_TEXT_KEY_TRUE;
  57. }
  58. String mapKey = rightBorderName + bottomBorderName + fontColor + bgColor + dataFormat + wrapTextKey;
  59. if (!xssfCellStyleMap.containsKey(mapKey)) {
  60. }
  61. return xssfCellStyleMap.get(mapKey);
  62. }

  

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. nginx ngx_http_image_filter_module 简单试用

    nginx包含了一个ngx_http_image_filter_module 模块,我们可以方便的进行图片的缩略图,平时一些简单的功能 已经够用了 环境准备 为了简单使用docker-compose ...

  2. java8_api_字符串处理

    字符串处理1 字符串处理2    string的常用方法 package java_20180209_api_string; public class StringDemo2 { public sta ...

  3. mysql入门学习笔记

    MySQL的登陆和退出 mysql -u 用户名 -p 密码 #登陆 quit #退出(exit or \q) 具体参数: 参数 描述 -D,--database=name 打开指定数据库 -deli ...

  4. 注解@Resource和@Autowired区别对比

    @Resource和@Autowired都是做bean的注入时使用,其实@Resource并不是Spring的注解,它的包是javax.annotation.Resource,需要导入,但是Sprin ...

  5. 利用工具将数据库中的表导出到word中

    1.动软代码生成器 效果图: 数据库设计说明书中的一项,刚好我负责写这个文档, 18张表,前两张表是自己画表格自己填充内容,写到第三张表的时候就已经崩溃了(我觉得我耐力还是够的,怎么说也画完了两张表呢 ...

  6. Eclipse中Java build path的使用

    1.Eclipse中,工程属性的Java Build Path的Library标签页下,有如下几个按钮:Add Jars...添加JAR包,是指本Eclipse当前包含的工程中的,在工程列表下选取即可 ...

  7. Oracle数据csv导入

    打开工具,在tool下面有个Text Importer 先选择Data from textfile选项卡 然后选择 Open data file ,打开要导入的文件 1\ 2\ 再先选择Data to ...

  8. 时间规划在Optaplanner上的实现

    在与诸位交流中,使用较多的生产计划和路线规划场景中,大家最为关注的焦点是关于时间的处理问题.确实,时间这一维度具有一定的特殊性.因为时间是一维的,体现为通过图形表示时,它仅可以通过一条有向直线来表达它 ...

  9. 工控随笔_19_西门子_WinCC的VBS脚本_08_常量和流程控制_01

    在编程的过程中,有时候我们会使用一些固定的值,例如圆周率,或者某个人的生日,或者家庭住址等等, 这些信息对于一个对象来说一旦确定就不会改变,因此我们在编程的时候也不希望这些信息会改变,在VBS里面 也 ...

  10. RDLC报表系列--------报表分页显示标题

    RDLC表格标题分页后,标题不显示网上的办法也不少.怎奈我试过很多,只有这个可以解决.留下代码以后使用 将报表以 XML的方式打开,搜索找到“详细信息” 在这个位置 报表分页标题设置<Tabli ...