Ok, I understand now, you are basically populating a template with data. Must admit I was surprised by your message as I thought you had found a way to get/set the format of a column using HSSF and thought that was not possible yet.
As you read the data, do you know how it should be formatted or is this information bound up in the sheet - the template - alone? Do you know in advance how each column should be formatted - for example column two should contain numeric values and show all negative numbers with a leading minus sign and in red? If so, you can use these cues to set the format for the sheet as you populate each cell, this tends to be the way I do it myself - I build all the HSSFCellStyle class instances I will need, add any formatting and then treat each cell appropriately as I add it to the row. I know that you can get the set of styles and formats applied to the Workbook but do not think that any column or cell information is bound to them and, as your template sheet is effectively empty, I do not know at this stage how you can establish that link - I do not know but think that HSSF will tell you that the sheet is empty but I could be wrong so the first thing I would try is to read a row and recover the HSSFCellStyle object - and it's associated format - for each cell into an associative list that links column number to cell style. Then you can simply read the data from your file, find out which column it should be written into, get that cell style from the list and apply it. If this does not work with empty cells, populate the first row of your spreadsheet with data as you create the template, open the sheet, read that row, etc. --- On Mon, 12/22/08, noobguru <[email protected]> wrote: From: noobguru <[email protected]> Subject: RE: reading excel - can I get column format? To: [email protected] Date: Monday, December 22, 2008, 8:48 AM Also, there may or may not be data in the excel sheet at all. I just format the columns (by excel) and then put data in there accordingly (using hssf or whatever classes). But I need to know the formatting of the columns in order to put data in the excel sheet. noobguru wrote: > > I set the columns in the excel file using Excel. Now I'm trying to read > those formats from the excel file using the libraries given so that I take > a text file (with data in it) and place it in the appropriate columns. > > > Anthony Andrews wrote: >> >> Forgive me asking this as I am a couple of version behind at the moment >> but did you set the format of the column using HSSF or Excel? >> >> --- On Mon, 12/22/08, noobguru <[email protected]> wrote: >> From: noobguru <[email protected]> >> Subject: RE: reading excel - can I get column format? >> To: [email protected] >> Date: Monday, December 22, 2008, 7:50 AM >> >> Thanks Joe, >> >> But I formatted the entire column to one format. So is there anyway >> to >> get that format? >> >> noobguru >> >> HSSFCell cell = ci.next(); >> if (cell.getCellType() == cell.CELL_TYPE_STRING) >> s = s+cell.getRichStringCellValue(); >> >> -----Original Message----- >> From: noobguru [mailto:[email protected]] >> Sent: Friday, December 19, 2008 5:11 PM >> To: [email protected] >> Subject: reading excel - can I get column format? >> >> >> I've tried looking in the apache poi documentation as well as this >> forum, >> however, I couldn't find if it was possible to get the format of a >> column in >> a 2007 excel file. Is this possible at all? (e.g. whether a column is a >> Number, String, Date, etc). >> >> If this is not possible, is there a way to get the format of a cell that >> has >> no data in it? (e.g. whether this cell is formatted as a Number, String, >> Date, etc). >> >> Thanks in advance! >> ~noobguru >> -- >> View this message in context: >> http://www.nabble.com/reading-excel---can-I-get-column-format--tp2109903 >> 1p21099031.html >> Sent from the POI - User mailing list archive at Nabble.com. >> >> >> -- >> View this message in context: >> http://www.nabble.com/reading-excel---can-I-get-column-format--tp21099031p21129971.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] >> >> >> >> >> >> > > -- View this message in context: http://www.nabble.com/reading-excel---can-I-get-column-format--tp21099031p21130946.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]
