Merged region does work for me. int firstRow = 0; int lastRow = 3; int firstCol =5; int lastCol = 5;
row= sheet1.createRow(lastRow ); HSSFCell cellMgHead = rowMs.createCell((short) lastCol ); cellMgHead.setCellValue("XXXX" ); cellMgHead.setCellStyle(styleMgHead); but when i try to write.the text does not appear on the row3 and col5 in excel... Hepzibah **Hope can be ignited by a spark of encouragement ***** On Thu, May 28, 2009 at 7:56 PM, Princess <hepzib...@googlemail.com> wrote: > Thanks a lot for the effort .would try and let you know > Hepzibah > **Hope can be ignited by a spark of encouragement ***** > > > > > On Thu, May 28, 2009 at 11:05 AM, MSB <markbrd...@tiscali.co.uk> wrote: > >> >> Sorry I could not reply before today - internet was down yesterday at home >> and I did not have access to the javadocs at work, anyway have been able >> to >> play with some code this morning. >> >> Firstly, I am sorry to say that I was unable to test this code using >> version >> 3.0.2 as I only have later versions on my PC, but I do hold out hopes that >> it works correctly. Secondly, it may be worthwhile - assuming that you can >> do so - upgrading to a more recent version of POI as the Region class has >> now been deprecated; superseded by the CellRageAddress class. Thirdly, I >> have changed the code somewhat, I was not absolutly clear on the meaning >> of >> your variables 'row', 'mg' and 'rowms' so I created four int variables >> called firstRow, lastRow, firstCol and lastCol in my example confident >> that >> you could translate between the two. >> >> Anyway, here is the code; >> >> int firstRow = 0; >> int lastRow = 3; >> int firstCol = 0; >> int lastCol = 5; >> >> workbook = new HSSFWorkbook(); >> sheet = workbook.createSheet("Merged Region"); >> row = sheet.createRow(firstRow); >> cell = row.createCell(firstCol); >> >> cell.setCellValue(new >> org.apache.poi.hssf.usermodel.HSSFRichTextString("Merged Cell")); >> >> cellStyle = workbook.createCellStyle(); >> cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); >> cellStyle.setFillForegroundColor( >> org.apache.poi.hssf.util.HSSFColor.LIGHT_CORNFLOWER_BLUE.index); >> cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); >> cellStyle.setRotation((short)90); >> >> cell.setCellStyle(cellStyle); >> >> region = new org.apache.poi.hssf.util.Region(); >> region.setColumnFrom((short)firstCol); >> region.setColumnTo((short)lastCol); >> region.setRowFrom(firstRow); >> region.setRowTo(lastRow); >> sheet.addMergedRegion(region); >> >> The first obvious difference is sequenceing, I created the cell and >> applied >> the style before merging the region on the sheet; I do not know if thsi is >> important or not though. What may be is the way I am creating the region >> using the serRow... and setColumn... method class. I found that the >> behaviour of these methods and that of the overloaded constructor where >> quite different. Only by using the individual class could I crfeate the >> merged region successfully and that may also be the cause of your problems >> but I cannot be certain as I have not tested the code against verion >> 3.0.2. >> >> If you have any problems. let me know so that I can try again please. >> >> >> Princess-4 wrote: >> > >> > int row = 5 ,mg =1 ,rowms=7; >> > HSSFCellStyle styleMgHead = wb.createCellStyle(); >> > styleMgHead.setAlignment(HSSFCellStyle.ALIGN_CENTER); >> > >> > >> styleMgHead.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index); >> > styleMgHead.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); >> > styleMgHead.setRotation((short)90); >> > >> > Region regionMg = new Region(row - 1, (short) mg, rowms - 1, (short)mg >> ); >> > sheet1.addMergedRegion(regionMg); >> > rowMs= sheet1.createRow(rowms - 1); >> > HSSFCell cellMgHead = rowMs.createCell((short) mg); >> > cellMgHead.setCellValue("XXXX"); >> > cellMgHead.setCellStyle(styleMgHead); >> > >> > >> > With this the row is getting merged but the text is not written in the >> > cell >> > >> > Any specific reason .Using POI 3.0.2 >> > >> > >> >> -- >> View this message in context: >> http://www.nabble.com/merging-rows-tp23728143p23758010.html >> Sent from the POI - User mailing list archive at Nabble.com. >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscr...@poi.apache.org >> For additional commands, e-mail: user-h...@poi.apache.org >> >> >