简体   繁体   English

如何将样式应用于行直到Apache POI中的指定单元格

[英]How to apply style to a row uptill a specified cell in Apache POI

I want to apply border style to a row but not the entire row. 我想将边框样式应用于一行而不是整个行。 I want to apply it till 33rd cell. 我想将其应用到第33单元。 How can I do it?? 我该怎么做??

Any idea?? 任何想法??

  1. Create a style you want: 创建所需的样式:

      HSSFCellStyle my_style = my_workbook.createCellStyle(); /* Draw a thin left border */ my_style.setBorderLeft(HSSFCellStyle.BORDER_THIN);/* Add medium right border */ my_style.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);/* Add dashed top border */ my_style.setBorderTop(HSSFCellStyle.BORDER_DASHED); /* Add dotted bottom border */ my_style.setBorderBottom(HSSFCellStyle.BORDER_DOTTED); 
  2. Create a row: 创建一行:

      /*Create a row */ Row row = my_sheet.createRow(0); 
  3. Add cells to the row with your desired border style: 将具有所需边框样式的单元格添加到行中:

      /*Now add cells to the row*/ Cell cell = row.createCell(0); cell.setCellValue("Add Border Example - 1 "); /*Now add style to your cell cell.setCellStyle(my_style); 
  4. Repeat the process of creating cells for the row created earlier 对先前创建的行重复创建单元格的过程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM