poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robins, Joe" <joe.rob...@teachforamerica.org>
Subject Getting book from sheet, sheet from row, etc.
Date Mon, 08 Dec 2008 20:28:04 GMT
Hi,

I've tried to find this answer in the docs, looking through the archives, etc., but I can't
find it anywhere.  I'm hoping someone here can help me out.

Is there a reason that there are not methods on HSSFSheet, HSSFRow, etc., to get the parent
object?  A quick look through the code reveals that they are storing those references.  If
I have:

  HSSFWorkbook wb = <create my workbook here>
  HSSFSheet sheet = wb.createSheet();
  HSSFRow row = sheet.createRow(0);

It would seem that I should be able to do:
  row.getSheet();
  sheet.getWorkbook();

As I mentioned, they are storing these references in private member variables.  Is there some
reason they are not exposed through getters?

Here is the use case that I am trying to accomplish.  I have a method foo that takes as arguments
an HSSFRow, a column number, and an Object, does some stuff, and writes the object to the
specified cell:

public void foo(HSSFRow row, int col, Object data);

Now the problem is that I need to do some formatting depending on the type of data.  If it's
a number, for example, I set the cell type to NUMERIC.  But if it's a Date, I want to create
a cell style for the date to format it appropriately.  However, I can only create a data format
and a cell style off the workbook, not off the row or the cell, and I can't get a reference
to the workbook at this point.

So is there some reason I can't work my way back up the chain to get the workbook?  And is
there any other way to accomplish this, short of creating the style in the calling method
and passing it in?

Thank you,

Joe Robins
Director, Systems & Software Development
Teach For America
Email: joe.robins@teachforamerica.org
Phone: 212-279-2080, x368
One day, all children in this nation will have the opportunity to attain an excellent education.
http://www.teachforamerica.org/



____________________________________________
This communication and any file transmitted with it may contain information that is confidential,
privileged and exempt from disclosure under applicable law. It is intended solely for the
use of the individual or entity to which it is addressed. If you are not the intended recipient,
you are hereby notified that any use, dissemination or copying of this communication is strictly
prohibited. If you have received this communication in error, please notify the sender. Thank
you for your cooperation.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message