What your screenshot shows is a gridline and not a border line. That's a difference in spreadsheets. The gridlines are shown in application window only to see the cells better. They will not be printed.
If you dont want to see the gridlines you either could switching to not showing gridlines for the whole sheet, what i do not recommend, or you could set white border lines which will overpaint some of the gridlines then.
Since you have tagged apache-poi-4
I will show a complete example which uses the advanced methods of CellUtil
and PropertyTemplate
to produce what you seems to want.
Code:
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
class CreateExcelLeftRight {
public static void main(String[] args) throws Exception {
try (Workbook workbook = new XSSFWorkbook();
FileOutputStream fileout = new FileOutputStream("Excel.xlsx") ) {
//create font with bigger size
Font font = workbook.createFont();
font.setFontHeightInPoints((short)24);
Sheet sheet = workbook.createSheet();
//merge A1:E2
sheet.addMergedRegion(new CellRangeAddress(
0, //first row (0-based)
1, //last row (0-based)
0, //first column (0-based)
4 //last column (0-based)
));
//merge F1:H2
sheet.addMergedRegion(new CellRangeAddress(
0, //first row (0-based)
1, //last row (0-based)
5, //first column (0-based)
7 //last column (0-based)
));
//create row 1
Row row = sheet.createRow(0);
//create cell A1
Cell cell = row.createCell(0);
cell.setCellValue("LEFT");
CellUtil.setFont(cell, font);
CellUtil.setVerticalAlignment(cell, VerticalAlignment.CENTER);
//create cell F1
cell = row.createCell(5);
cell.setCellValue("RIGHT");
CellUtil.setFont(cell, font);
CellUtil.setVerticalAlignment(cell, VerticalAlignment.CENTER);
CellUtil.setAlignment(cell, HorizontalAlignment.RIGHT);
PropertyTemplate propertyTemplate = new PropertyTemplate();
//paint all inside borders white on A1:H2
propertyTemplate.drawBorders(new CellRangeAddress(0, 1, 0, 7),
BorderStyle.THIN, IndexedColors.WHITE.getIndex(), BorderExtent.INSIDE);
//paint all bottom borders thick gray on A2:H2
propertyTemplate.drawBorders(new CellRangeAddress(1, 1, 0, 7),
BorderStyle.THICK, IndexedColors.GREY_40_PERCENT.getIndex(), BorderExtent.BOTTOM);
propertyTemplate.applyBorders(sheet);
sheet.setActiveCell(new CellAddress(3, 0));
workbook.write(fileout);
}
}
}
Result:
