[Info-vax] WEENDOZE question
Arne Vajhøj
arne at vajhoej.dk
Wed Feb 7 20:24:58 EST 2018
On 2/6/2018 11:11 AM, VAXman- at SendSpamHere.ORG wrote:
> As for the problem, Excel will NOT maintain a header border when cells are
> merged in the header. This looks fine on OSX with Numbers or on Linux with
> LibreOffice Calc. Anyway, to fix it, I had to output empty cells with the
> specified header format re-specified to the cells cannibalized in the merge.
> Customer is happy!
The output from the Java program below shows border on merged cells fine
in both MSO Excel and LO Calc.
Arne
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellUtil;
import org.apache.poi.ss.util.RegionUtil;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class MergedHeaderBorder {
public static void main(String[] args) throws IOException {
Workbook workbook = null;
try {
workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet();
Row headerrow = sheet.createRow(0);
Cell headercell = headerrow.createCell(0);
CellUtil.setAlignment(headercell, HorizontalAlignment.CENTER);
headercell.setCellValue("Big header");
CellRangeAddress headerregion =
CellRangeAddress.valueOf("A1:D1");
sheet.addMergedRegion(headerregion);
RegionUtil.setBorderTop(BorderStyle.THICK, headerregion,
sheet);
RegionUtil.setBorderBottom(BorderStyle.THICK, headerregion,
sheet);
RegionUtil.setBorderLeft(BorderStyle.THICK, headerregion,
sheet);
RegionUtil.setBorderRight(BorderStyle.THICK, headerregion,
sheet);
Row datarow = sheet.createRow(1);
datarow.createCell(0).setCellValue("ABC");
datarow.createCell(1).setCellValue(17);
datarow.createCell(2).setCellValue(2.50);
datarow.createCell(3).setCellFormula("B2*C2");
try(OutputStream os = new FileOutputStream("/work/hdr.xlsx")) {
workbook.write(os);
}
} finally {
workbook.close();
}
}
}
More information about the Info-vax
mailing list