Hi,
I'm having issues trying to use the HSSFSheet class + addMergedRegion
method. I need to tell Excel to merge some cells so the text in a cell (a
title at the top of the sheet) doesn't affect the width of that cell in
subsequent rows.
I've tried using either Region or CellRangeAddress as arguments to that
method, but in both cases the compiler (I'm using MyEclipse 8.6.1)
complains that "The method addMergedRegion(Region) in the type HSSFSheet is
not applicable for the arguments (...)".
I get exactly the same results with either poi 3.7 (poi-3.7-20101029.jar)
or the latest 3.8 beta (poi-3.8-beta5-20111217.jar) loaded as external jars
in my Project > Properties > Java Build Path.
Here's an example of code that reproduces the error:
package mypackage;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.Region; // MyEclipse warns: "The type Region
is deprecated"
public class TestPOI {
public static void main(String[] args) {
// setting up the use of the method:
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFRow row = sheet.createRow((short)1);
HSSFCell cell1 = row.createCell((short)1);
// Here's the two ways I've tried to use this method, and the compiler flag
for each:
CellRangeAddress cellRange1 = new CellRangeAddress(1, 1, 1, 5);
sheet.addMergedRegion(cellRange1);
--> "The method addMergedRegion(Region) in the type HSSFSheet is not
applicable for the arguments (CellRangeAddress)".
Region cellRegion1 = new Region(1, (short)1, 1, (short)5); // MyEclipse
warns: "The type Region is deprecated"
sheet.addMergedRegion(cellRegion1);
--> "The method addMergedRegion(Region) in the type HSSFSheet is not
applicable for the arguments (Region)".
}
}
I'm stumped. Is this a bug in POI? Or am I overlooking something / doing
something wrong?
Thanks,
Michael Tucker