View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default pictures in single cells - conflict with wrapping text

I hadn't digested in your first post that in effect the xls is being created
with BIFF8. The makers of Apache POI have done well because until recently,
when MS published the BIFF8 in full under the open source agreement, the
documentation about drawing objects was very thin.

I probably can't answer your question other than to describe how objects on
sheets are positioned and resized, subject their move/resize properties.

Initially Left/Top (distance from top left of sheet) and Width/Height are
the main properties. When the object is created it references two other
cells, TopLeft and BottomRight.

If the object is set to "move" with cells, if the TopLeft cell moves (eg
row/col repositioned or deleted) the object's Top/Left properties will
change accordingly.

Moving the BottomRight cell similarly affects size but it depends -
If the object's bottom or right edge touches the cell's bottom or right
edge, if the bottom-right corner of the BottomRight cell moves the object
will resize.
Otherwise, the object will resize according to any change in the position of
the top-left corner of the BottomRight cell. Hope that all makes sense.


I don't know at what point the object first creates a reference to its
TopLeft and BottomRight cells, particularly when created with BIFF8, maybe
only after the file is first used in Excel and perhaps that's what's giving
you a problem. Not sure if for your purposes it might be worth finding out
if those cells can be returned in BIFF8, as they can via Excel's object
model.

I suppose the obvious question is why not automate Excel, even if only to
tidy things up in the file that was originally created elsewhere.

Regards,
Peter T










"Rob Y." wrote in message
...
ActiveSheet.Pictures.Placement = xlMove

This is like selecting all pictures on the sheet, rt-click, format,
properties, Move but don't size with cells.

I'm not sure what you mean about anchors inExcel


I already have my pictures set to 'move but don't size with cells'.
That much works.

The problem is that the *original* size of the pictures is based on
the original size of the cells, and I don't know how tall the rows are
going to be once Excel performs its auto-wrapping magic on the rest of
the data on the row.

The 'anchor' terminology comes from the Apache POI toolkit I'm using
to create the XLS's - though I think the terminology just reflects the
internal data structures of an XLS. Excel sizes pictures through a
combination of a range of cells and starting and ending offsets within
the cells on the edges of the range. In my case there's just a single
cell.

The problem is that the 'offsets' are defined as a percentage of the
size of the cell (it's even more complicated than that, but
effectively that's how it works). Because I don't know the height of
my cell at the time I'm creating the XLS (because I don't know how
much wrapping will be required by text in other cells on the same
row), I can't compute the ending vertical offset correctly. I just
assume that the row is one line high and had hoped that Excel would
interpret my ending vertical offset based on the initial cell height
before wrapping text on that line. After all, what's the point of
asking Excel to auto-wrap my text if Excel assumes I know how much
wrapping will be required? But the picture sizing mechanism seems to
assume just that.

Note that I'm creating a complete XLS file before Excel ever gets its
hands on it. I'm not using OLE automation to fill a spreadsheet one
operation at a time (in which case, perhaps, Excel would go through
all the internal stuff it has to do to hide the anchor mechanism from
you). If that were the case, then this might not be a problem. But
surely, there are other ways to create XLS's than to automate Excel
itself (like, for example, Apache POI). I'm just hoping that there's
some way to represent what I'm trying to do in the XLS file so that
Excel will size my pictures to a 1-line row height and *then* proceed
to auto-wrap any text on the row. If not, then I just have to choose
between pictures and auto-wrapping and accept that it's not possible
to have both.