You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Yegor Kozlov <ye...@dinom.ru> on 2007/09/24 14:12:44 UTC

Re[2]: How to get sheet name in HSSFSheet class?

> On Sat, 22 Sep 2007, Yegor Kozlov wrote:
>> When we access a sheet from HSSFWorkbook we should remember its index. 
>> There are lots of places where the sheet index is involved including 
>> HSSFWorkbook.cloneSheet() and HSSFWorkbook.setSheetOrder(String 
>> sheetname, int pos). All of these should be covered.

> It might be less work to tell the sheet its name? You can then get the
> sheet index if you need it (via a workbook.getSheetIndex(name) call), and
> we only need to update things in workbook.setSheetName. My hunch is that
> reorganising it so that a sheet knows its index might be good, but it 
> would take a lot more work

I think a better idea is to lookup the sheet in the
HSSFWorkbook.sheets collection. Given a HSSFSheet finding its
index looks as follows:

    public int getSheetIndex(HSSFSheet sheet)
    {
        for (int k = 0; k < sheets.size(); k++)
        {
            if(sheets.get(k) == sheet) {
                return k;
            }
        }
        return -1;
    }

The point that HSSFSheet doesn't have a reference to the owning
HSSFWorkbook. If we add it, the fix is trivial.
    
Yegor

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re[5]: How to get sheet name in HSSFSheet class?

Posted by Yegor Kozlov <ye...@dinom.ru>.
Checkout from svn or download a daily build from
http://encore.torchbox.com/poi-svn-build/.


 Yegor
 
> Hello!

> Nick Burch <nick <at> torchbox.com> writes:

>> I'll put it in in a sec
>> 
>> Nick

> How I could get a patch? 





> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Re[3]: How to get sheet name in HSSFSheet class?

Posted by Alexey Kuznetsov <ku...@mail.ru>.
Hello!

Nick Burch <nick <at> torchbox.com> writes:

> I'll put it in in a sec
> 
> Nick

How I could get a patch? 





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Re[3]: How to get sheet name in HSSFSheet class?

Posted by Christophe Charles <ch...@gmail.com>.
Hello,

In Feb 2007 Yegor wrote about scaling image in Excel :


There isn't an easier way do scale images.
>
> There was a discussion recently about scaling.
> Excel measures images in units of 1/256th of a character width of the
> default font. Conversion from these "weird" units to pixels is not
> trivial. It's the main problem.
>
> I have ideas how to add such support. Check POI in a month or two.
> There is a chance I will commit it.
>
> Yegor






 Hi all,
>
>  I'm using Jakarta POI 3.0-alpha3 to write an Excel spreadsheet with
>  images and I'm having some trouble computing the HSSFClientAnchor
>  size.
>
>  At the moment I try to manage it by adding column widths and row
>  heights until I reach approximately the size of the image in cells,
>  and then set up dx and dy, but I can almost never get it to work
>  perfectly and images are never exactly at 100%.
>
>  Is there an easier way to do this? I have searched around in google,
>  groups and google code search but couldn't find anything useful. How
>  do you people do this?
>
>  Thanks a lot!
>
>  Below is a snippet of my code. Basically, you give the starting row/
>  col position of the image you want to insert and it goes around adding
>  row/column sizes into imgHeight and imgWidth until their values are
>  equal to or greater than the size of the image. If they're greater, it
>  substracts one row or one column, depending on what was greater, and
>  puts the remaining pixels on dx or dy.
>
>          protected int addImage(HSSFWorkbook wb, HSSFSheet sheet,
> InputStream
>  img, int numRow, short numCol) {
>                  int x1 = 0;
>                  int y1 = 0;
>                  short x2 = 0;
>                  int y2 = 0;
>                  int row1 = numRow;
>                  short col1 = numCol;
>                  int row2 = numRow;
>                  short col2 = numCol;
>                  ImageData d = new ImageData();
>                  int idx = loadAndConvertPicture(img,wb,d);
>                  int imgHeight = 0;
>                  int imgWidth = 0;
>
>                  while(imgWidth <d.getWidth() || imgHeight <d.getHeight())
> {
>                          if(imgWidth <d.getWidth()) col2++;
>                          if(imgHeight <d.getHeight()) row2++;
>                          if(imgWidth != d.getWidth()) {
>                                  int colWidth = (int)
>  (sheet.getColumnWidth((short)col2)/48);
>                                  if(imgWidth+colWidth<=d.getAmplada()) {
>                                          imgWidth +=colWidth;
>                                  } else {
>                                          col2--;
>                                          x2=(short)(d.getWidth
> ()-imgWidth);
>                                          imgWidth=d.getWidth();
>                                  }
>                          }
>                          if(imgHeight != d.getHeight()) {
>                                  int rowHeight;
>                                  HSSFRow row = sheet.getRow(row2);
>                                  if(row != null) rowHeight = (int)
>  row.getHeight()/20;
>                                  else rowHeight = (int)
>  sheet.getDefaultRowHeight()/20;
>                                  if(row == null) row = sheet.createRow
> (row2);
>                                  if(imgHeight +rowHeight<=d.getHeight()) {
>                                          imgHeight +=rowHeight;
>                                  } else {
>                                          row2--;
>                                          y2=d.getHeight()-imgHeight ;
>                                          imgHeight =d.getHeight();
>                                  }
>                          }
>                  }



I want to now what about new commit in POI to scaling image ?

Thank a lot .

Chris

Re: Formula cell is showing zero using new Jar 3.0.1

Posted by Nick Burch <ni...@torchbox.com>.
On Mon, 24 Sep 2007, Sajedul Munir wrote:
> Hi there. I recently downloaded new release POI jar v 3.0.1. I was able 
> to write value in my excel report (based on template) but in all formula 
> fields it is showing zero. Let's say in cell B3 value is 3000 and cell 
> B4 value is 4000. I have a formula set for cell B5 (SUM(B3:B4)) which 
> was showing 7000 using old 2.5.1 jar but using new jar, it is showing 0.

You'll need to use the Forumla Evaluator to re-calculate the results of 
your formulas:
 	http://poi.apache.org/hssf/eval.html

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Formula cell is showing zero using new Jar 3.0.1

Posted by Sajedul Munir <Sa...@frameworks.ca>.
Hi there. I recently downloaded new release POI jar v 3.0.1. I was able
to write value in my excel report (based on template) but in all formula
fields it is showing zero. Let's say in cell B3 value is 3000 and cell
B4 value is 4000. I have a formula set for cell B5 (SUM(B3:B4)) which
was showing 7000 using old 2.5.1 jar but using new jar, it is showing 0.
Can anyone tell me what am I missing here? 

 

I would appreciate any help in this matter. Thanks advance for the help.

 

Sajedul Munir

Frameworks Inc

Toronto, Canada

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re[3]: How to get sheet name in HSSFSheet class?

Posted by Nick Burch <ni...@torchbox.com>.
On Mon, 24 Sep 2007, Yegor Kozlov wrote:
>> Shall we go for that?
>
> Yes. You or me?

I'll put it in in a sec

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re[3]: How to get sheet name in HSSFSheet class?

Posted by Yegor Kozlov <ye...@dinom.ru>.

> Shall we go for that?

Yes. You or me?

Yegor

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re[2]: How to get sheet name in HSSFSheet class?

Posted by Nick Burch <ni...@torchbox.com>.
On Mon, 24 Sep 2007, Yegor Kozlov wrote:
> I think a better idea is to lookup the sheet in the HSSFWorkbook.sheets 
> collection. Given a HSSFSheet finding its index looks as follows:

Yup, that'd work to

> The point that HSSFSheet doesn't have a reference to the owning 
> HSSFWorkbook. If we add it, the fix is trivial.

It already has a reference to model.Workbook, which is almost but not 
quite good enough :/

We could easily change HSSFSheet so you pass in a HSSFWorkbook rather than 
a Workbook, then grab out the Workbook in the constructor, and save both.


Shall we go for that?

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org