I think that I might be on to a technique to solve this specific sort of
problem.
Firstly, I have found out that it is possible to 'place' an image into a
specific cell by setting all of the co-ordinates for that cell - the last
four parameters of the HSSFClientAnchor class - to the same value. So, to
place an image in cell A1, the last four parameters would be 0, 0, 0, 0.
Secondly, those first four parameters of the HSSFClientAnchor class - dx1,
dx2, dy1 and dy2 - determine the locations of the top left and bottom right
ahnd corners of the image within the cell; and this is to my mind the
crucial point. By limiting the location to just one cell using the latter
four parameters and then playing with the values of the first four, it is
possible to place an image within a cell and to determine the size of that
image.
Thirdly, it seems that the co-ordinate system within the cell is fixed with
regard to the range of values. Apparantly, moving from the top of the cell
downwards, the range of co-ordinate values runs from 0 to 255. Moving from
the right hand edge of the cell leftwards, the co-ordinate values move from
0 to 1023. The challenge I now have to crack is determining how these
co-ordinate values can be manipulated to ensure that an image is inserted at
the correct location within the cell and is sized appropriately.
Again, I think that I am onto apossible solution but it involves converting
between Excel's system of expressing the columns width to pixels,
determining the 'actual' width of the column, caculating now many pixels -
how far and how large - to set the image and then converting this back into
the co-ordinate systems values. Could be a bit tricky and I will not have
the time to work on it during the day today as we are catching up on the
work we missed yesterday owing to the rain. As always though, I will post if
I make any progress.
Yours
Mark B
deep4u wrote:
>
> Hi mark,
> when u free send me the code.
>
> Thanks,
>
> MSB wrote:
>>
>> The image ought to be fine. Using Excel, it is possible to set the same
>> sort of properties that you can with POI, i.e. that the image should not
>> move or resize itself with the cells. To do this using 'my' version of
>> Excel, you select the image on the worksheet and click on the right hand
>> mouse button; this pops open a menu from which you can select the 'Size
>> and Properties' option. The options screen that appears in response to
>> this has a number of tabs on it. One of them is labelled 'Properties' and
>> selecting this allows you to say how the image should respond to resizing
>> of the cells. I would select the 'Don't move or size with cells' option.
>> Then the image ought to remain tha same size irrespective of what you do
>> with the columns or rows.
>>
>> If you are in no hurry, I can put together some code later today to test
>> this hypothesis and then post the results to you. Sadly, I have to leave
>> in about an hour to help a group of volunteers construct a flight of
>> steps linking two footpaths together - which should be fun given the
>> weather forecast today - but should be able to get some code together
>> this evening.
>>
>> Yours
>>
>> Mark B
>>
>>
>> deep4u wrote:
>>>
>>> Hi mark,
>>> I need to create a excel dynamically means based On weekly,
>>> Monthly, suppose this is current week so 07/24/09-07/31/09,...next based
>>> on months july month the name excelsheet will be "july.xls" , and next
>>> nonth "August.xls"... If i taking a template ok but in my program i will
>>> set autosize on that no streched the image?
>>>
>>> Thanks,
>>>
>>>
>>> MSB wrote:
>>>>
>>>> You need to do the following;
>>>>
>>>> Start Excel
>>>> If necessary, open a new workbook - Excel usually opens up with a new,
>>>> empty workbook so this may not be necessary.
>>>> Select Insert->Picture and navigate your way to where the logo image is
>>>> stored. Select (highlight) the image and then click on the Insert
>>>> button.
>>>> Now, you should see that the logo has been inserted into the worksheet
>>>> and you can use the mouse to drag it into the correct location and
>>>> re-size it as necessary.
>>>> Save the file away and remember where you stored it and the name you
>>>> used.
>>>>
>>>> That has created the template that you will pick up using POI and
>>>> populate with data. All you need to do is something like this;
>>>>
>>>> File file = new File("..Path to and name of the file you created
>>>> above..");
>>>> FileInputStream fis = new FileInputStream(file);
>>>> HSSFWorkbook workbook = new HSSFWorkbook(fis);
>>>> HSSFSheet sheet = workbook.getSheetAt(0);
>>>>
>>>> and when you have your sheet, populate it in the usual manner and then
>>>> save the completed workbook away again, most likely using a different
>>>> name so that the template can be used again and again as the basis for
>>>> further documents. It is common to see users do this sort of thing as
>>>> POI's image manipulation facilities are not quite as feature rich as
>>>> are Excel's.
>>>>
>>>> Hope that helps. If it is not clear, I will create a template and some
>>>> code that picks it up and populates it and PM both to you; just let me
>>>> know.
>>>>
>>>> Yours
>>>>
>>>> Mark B
>>>>
>>>>
>>>> deep4u wrote:
>>>>>
>>>>> Hi mark,
>>>>> I need to create Excel sheet dynamically with logo. But
>>>>> using Template how it is possible.
>>>>>
>>>>> Thanks,
>>>>>
>>>>>
>>>>> MSB wrote:
>>>>>>
>>>>>> So, setting the anchor type does not solve the problem?
>>>>>>
>>>>>> In that case, I think that your only recourse is to create a document
>>>>>> template using Excel and to place the logo onto the document with it.
>>>>>> Then you should be able to safely use HSSF/XSSF to populate the
>>>>>> worksheet.
>>>>>>
>>>>>> Yours
>>>>>>
>>>>>> Mark B
>>>>>>
>>>>>>
>>>>>> deep4u wrote:
>>>>>>>
>>>>>>> Hi,
>>>>>>> i use the poi 3.5 also image will be expanding. I write like
>>>>>>> this
>>>>>>> anchor.setAnchorType(HSSFClientAnchor.DONT_MOVE_AND_RESIZE);
>>>>>>> or anchor.setAnchorType(3); how to reslove this.
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>>
>>>>>>> deep4u wrote:
>>>>>>>>
>>>>>>>> Hello,
>>>>>>>> I am new to this Library. Its working great, i used logo
>>>>>>>> (image) in the excel sheet. with the auto sizing the image also
>>>>>>>> expanding and contracting according to that column data.
>>>>>>>>
>>>>>>>> Can i keep the image irrespective of the column size?
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/autosize-in-Excel-irrespetive-of-image-tp24604961p24732755.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]