Hi Michael, This is like a private coversation.
Next week, I will not be available. It seems maybe I was confused with this HSFFCell null. Thanks for your details. I plan to wait 1-2 weeks and to see if my templates problems are solved. If there is still a problem, I will create a simple example to show you in details. Have a good day, Benjamin > > Benjamin - > > Ok I think I see where you are confused. > > Case 1) Cell does not exist and you get a null when you request it. > Create and format the cell. > > Case 2) Cell exists. In this case the Cell can have a number of > different > Cell Types such as BOOLEAN, DOUBLE, DATE, NUMERIC, BLANK, etc. Before you > try and get a value from a cell you need to check the Cell Type so you > know > which method to call. If your Cell Type is HSSFCell.CELL_TYPE_BLANK, then > to add a value, you set the Cell Type to the appropriate Cell Type and > then > set the value. I don't think you need to set the Cell Style after doing > this, but if the formatting is lost for some reason you can do the > setCellStyle(cellStyleId) and you'll be fine. Otherwise, if the cell is > already of the Cell Type want, just update the value. > > - MJD > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Thursday, February 09, 2006 3:13 AM > To: POI Users List > Cc: 'POI Users List' > Subject: RE: [Question]HSSFRow.getCell(cellNb), loosing border if no data > i > n the cell > > Hi Michael, > > I thought when the HSSFCell has no value but a style, POI with this method > (Row.getCell((short) cellNb)), should return an object HSSFCell not null > instead of a null object. > And after a getValue() should return null, but a getCellStyle() should > return the HSSFCellStyle not null ! > What do you think about this? > > I understand what you said before... if the HSSFCell is null, I should > create one with the same style as the cell before for example. > > benjamin, >> Benjamin - >> >> Ok, the problem is a little different than I had first thought. In your >> case, I think you will need to either figure out which style you are >> using >> in other cells that exist with the desired formatting or you can create >> a >> new HSSFCellStyle that mimics the settings you need and then after you >> create the new cells with HSSFCell cell = HSSFRow.createCell(column) you >> will need to do a cell.setCellStyle(cellStyleId) to set the proper >> formatting. >> >> So, first check to see if the cell exists, if so use it, else if it >> returns >> null then create a new cell and set the value & style. >> >> - MJD >> >> -----Original Message----- >> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] >> Sent: Wednesday, February 08, 2006 3:11 AM >> To: POI Users List >> Cc: 'POI Users List' >> Subject: RE: [Question]HSSFRow.getCell(cellNb), loosing border if no >> data >> i >> n the cell >> >> Thanks for your message Michael, >> >> My problem happens when I read a file (HSSFWorkbook), like using a >> template to create my own dynamic Excel file. >> >> For a HSSFWorkbook, and for a HSSFSheet I use a loop to parse each row >> (HSSFRow). >> To have the HSSFCell, I use this method : oneRow.getCell((short) cellNb) >> -If ((the cell has a value inside) && (a style(a border for example))) >> { >> I get the correct object HSSFCell with the method >> oneRow.getCell( >> (short) cellNb) >> } >> >> -If((the cell has NO value)&& (a style(a border for example))) >> { >> I get the null Object with the method oneRow.getCell((short) cellNb) >> To catch the style of this cell, I need to use this method: >> HSSFCell.getCellStyle >> But it is not possible to apply a method to a null object! >> } >> >> I Hope this text makes it more clear. >> >> Benjamin CHALLAMEL >> >> >>> Benjamin - >>> >>> If I under stand your question correctly.... HSSFCells have both a >>> Cell >>> Style and Cell Type associated with them. If you intend to have an >>> empty >>> cell you should set the Cell Type to HSSFCell.CELL_TYPE_BLANK and >>> create >>> a >>> Cell Style with the appropriate borders and Data Format, etc. The >>> HSSFCell >>> class has get/set methods for the Cell Style, Cell Type, and of course >>> the >>> Cell Value. To create a new Cell Style see the >>> HSSFWorkbook.createCellStyle() method. >>> >>> I haven't seen this happen before but if you are loosing the formatting >>> after you update the value of a cell, you could save the Cell Style >>> before >>> you set the Type and Value and then set it back after you set the Type >>> and >>> Value to make sure the Cell Style (borders, etc) are set the way you >>> want. >>> >>> I hope this helps, >>> >>> - MJD >>> >>> One somewhat related caveat that is not well documented: You need to >>> try >>> to >>> share Cell Styles between all cells with identical formatting. Do not >>> create a new Cell Style for each cell you create unless they are truly >>> formatted uniquely. This creates a management nightmare if you have >>> very >>> many Cell Styles, but it's a necessary aspect of the beasties. >>> >>> >>> -----Original Message----- >>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] >>> Sent: Tuesday, February 07, 2006 10:56 AM >>> To: [email protected] >>> Subject: [Question]HSSFRow.getCell(cellNb),loosing border if no data in >>> the >>> cell >>> >>> Hello, >>> >>> I'm working with this JAR : poi-2.5.1-final-20040804.jar >>> >>> My problem is about reading a HSSFCell and loosing the border. >>> >>> We have a HSSFRow. >>> I'm getting the value for a HSSFCell from a HSSFRow, with this method: >>> oneCell = oneRow.getCell((short) cellNb); >>> For both cases (describe after), there is a border on the specified >>> cell: >>> >>> 1)Case "there is a value in the cell" and a border: >>> >>> -> "oneRow.getCell((short) cellNb)" return a HSSFCell object, after I >>> can >>> set an other value >>> -> the value has a border >>> >>> 2)Case "there is no value in the cell" and a border: >>> >>> -> "oneRow.getCell((short) cellNb)" return null, >>> -> I have to create a HSSFCell (oneCell = oneRow.createCell((short) >>> cellNb)) to set the value >>> -> I have lost the border. >>> >>> Do you know if I'm using the API in a wrong way, or maybe the I can get >>> the Style of a HSSFCell somewhere? >>> >>> Thanx in advanced. >>> >>> Benjamin CHALLAMEL >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>> Mailing List: http://jakarta.apache.org/site/mail2.html#poi >>> The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/ >>> >>> >> > **************************************************************************** >>> This email may contain confidential material. >>> If you were not an intended recipient, >>> Please notify the sender and delete all copies. >>> We may monitor email to and from our network. >>> >> > **************************************************************************** >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>> Mailing List: http://jakarta.apache.org/site/mail2.html#poi >>> The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/ >>> >>> >>> >>> >>> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> Mailing List: http://jakarta.apache.org/site/mail2.html#poi >> The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/ >> >> > **************************************************************************** >> This email may contain confidential material. >> If you were not an intended recipient, >> Please notify the sender and delete all copies. >> We may monitor email to and from our network. >> > **************************************************************************** >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> Mailing List: http://jakarta.apache.org/site/mail2.html#poi >> The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/ >> >> >> >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > Mailing List: http://jakarta.apache.org/site/mail2.html#poi > The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/ > > **************************************************************************** > This email may contain confidential material. > If you were not an intended recipient, > Please notify the sender and delete all copies. > We may monitor email to and from our network. > **************************************************************************** > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > Mailing List: http://jakarta.apache.org/site/mail2.html#poi > The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/ > > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] Mailing List: http://jakarta.apache.org/site/mail2.html#poi The Apache Jakarta Poi Project: http://jakarta.apache.org/poi/
