Sorry to say this but I cannot re-produce the problem.
Yesterday evening, I put toghether and ran this very simple piece of code;
public static void mergeTest(String filename) {
File file = null;
FileOutputStream fos = null;
XSSFWorkbook workbook = null;
XSSFSheet sheet = null;
XSSFRow row = null;
XSSFCell cell = null;
try {
workbook = new XSSFWorkbook();
sheet = workbook.createSheet("Merge Test");
row = sheet.createRow(0);
cell = row.createCell(0);
cell.setCellValue("Region One.");
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));
row = sheet.createRow(1);
cell = row.createCell(1);
cell.setCellValue("Region Two.");
sheet.addMergedRegion(new CellRangeAddress(1, 2, 1, 6));
file = new File(filename);
fos = new FileOutputStream(file);
workbook.write(fos);
}
catch(Exception ex) {
System.out.println("Caught an: " + ex.getClass().getName());
System.out.println("Message: " + ex.getMessage());
System.out.println("Stacktrace follows............");
ex.printStackTrace(System.out);
}
finally {
if(fos != null) {
try {
fos.close();
fos = null;
}
catch(IOException ioEx) {
// I G N O R E
}
}
}
}
which creates two merged regions on one sheet. One region consists of a
single line of cells, the other of two ines of cells. Compiled and run
against an early beta of version 3.8 - poi-3.8-beta1-20101213.jar and
associated libraries - the xlsx file it produced opened in Excel without any
complaint.
May I ask, which version of POI you are using, which version of Excel and
whether you have tried to create a merged region in an xlsx file rather than
an xlsm. I am wondering if there is some aspect of your template that is
'clashing' somhow either with the xml POI creates or the markup that Excel
expects to read. As a test, try using your xlsm template and creating only
the merged regions to see if that works; it may be the case that we will
have to work through the file you are creating until it is possible to
identify just what is causing the problem. As NIck suggested, if the attempt
to create just the merged regions does fail, then repaet a similar operation
using Excel, rename both files with the .zip extension and then unzip then
into separate folders. Then it will be possible to look at the xml markup to
see just how the two files differ and that should point the way to a
solution.
Yours
Mark B
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/XSSFSheet-addMergedRegion-giving-excel-error-tp3389764p3390926.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]