poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Princess <hepzib...@googlemail.com>
Subject Re: merging rows
Date Tue, 02 Jun 2009 10:03:12 GMT
Thanks for the inputs ..i did try both teh methods suggested by you ...still
the problem exists
Hepzibah
**Hope can be ignited by a spark of encouragement *****



On Thu, May 28, 2009 at 9:51 PM, MSB <markbrdsly@tiscali.co.uk> wrote:

>
> Ah, now I understand the source of the confusion I think. Forgive me please
> if I am telling you what you already know but IMO, the key to working with
> merged regions is to remember that the data should be written into the tol
> peft hand most cell of the region. The location of the data within the
> region is then determined by setting the alignment options of the style -
> the setAlignment() and setVerticalAlignment() methods.
>
> So, this line
>
> cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
>
> will cause whatever you write into the first cell in the region to appear
> in
> the centre of the region - horizontally. Without checking the javadoc, I
> think that you need to change it to something like;
>
> cellStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
>
> Failing that, have a look at the setVerticalAlignment(int) method of the
> HSSFCellStyle class as that is used to set the vertical alignment of the
> cells/regions contents. You may need to add something like;
>
> cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_BOTTOM);
>
> Further, the fact that the cells contents have been rotated 90 degrees will
> also cause some confusion. My advise, therefore, is to add the
> setverticalAlignment() method call and experiment with the values passed to
> each method to see what the effects are.
>
> Sadly, I do not have the time tonight to check that out but I reckon it
> should work for you so I am sorry that I cannot be of any more help just
> now. If you continue to have problems, let me know as soon as possible so
> that I can play woth some code before I leave for work in the morning.
>
>
>
>
> Princess-4 wrote:
> >
> > 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 <hepzibahr@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 <markbrdsly@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-unsubscribe@poi.apache.org
> >>> For additional commands, e-mail: user-help@poi.apache.org
> >>>
> >>>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/merging-rows-tp23728143p23768834.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message