Discussion:
WORD: How to insert a picture into a table cell?
(too old to reply)
Dave M.
2003-07-25 15:53:08 UTC
Permalink
How do you insert a picture into a particular cell in a table?

I have the following code:

InsertPictureIntoRange(PictureFileName, Table.Cell((Loop * 2) + 2, 1).Range);

which calls

procedure TWordAPI.InsertPictureIntoRange(fileName: String; Rnge: OleVariant);
var
picfilename: WideString;
varFalse, varTrue: OleVariant;
begin;
try
varTrue := True;
varFalse := False;
picfilename := filename;

FWordDoc.Application.Selection.InlineShapes.AddPicture(picfilename, varFalse, varTrue, Rnge);
end;

which insert it *behind* the tables.

Is there a way to put it *into* a cell? I'm using W2K and Word 2000.

Best,
Dave
(replace NOSPAM with eims to reply)
Deborah Pate (TeamB)
2003-07-26 13:43:04 UTC
Permalink
<<Dave M.:
Is there a way to put it *into* a cell?
var
Tbl: Table;
OleRange: OleVariant;

OleRange := Tbl.Cell(2, 2).Range;
OleRange.Collapse(Direction);
Tbl.Cell(2, 2).Range.InlineShapes.AddPicture(
'H:\Pictures\Test.jpg', EmptyParam, EmptyParam,
OleRange);
--
Deborah Pate (TeamB) http://delphi-jedi.org

TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html
Dave M.
2003-07-29 08:11:12 UTC
Permalink
Post by Dave M.
Is there a way to put it *into* a cell?
var
Tbl: Table;
OleRange: OleVariant;
OleRange := Tbl.Cell(2, 2).Range;
OleRange.Collapse(Direction);
Tbl.Cell(2, 2).Range.InlineShapes.AddPicture(
'H:\Pictures\Test.jpg', EmptyParam, EmptyParam,
OleRange);
Hi Deborah, thank you for that, but I get the EOleSys Error "Unspecified Error" (no more information is presented than that) on the last line of your code!
Deborah, ignore my last message - I got it working, but I had to remove the OleRange.Collapse(Direction) line, as according to MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/off2000/html/ppmthaddpicture.asp),

"Range Optional Variant. The range where the picture will be placed in the text. The picture replaces the range, if the range isn't collapsed. If this argument is omitted, the picture is placed automatically."

Best,
Dave

(replace NOSPAM with eims to reply)

Loading...