在Word中有關圖片隨著文字一起移動的問題 |
尚未結案
|
adrain
一般會員 發表:39 回覆:28 積分:13 註冊:2004-07-27 發送簡訊給我 |
wapTXT.Selection.TypeText('1.');
dSerilTop := PointsToCentimeters(wapTXT.Selection.Information[wdVerticalPositionRelativeToPage]); //流水號垂直座標
dSerilLeft:= PointsToCentimeters(wapTXT.Selection.Information[wdHorizontalPositionRelativeToPage]); //流水號水平座標
wapTXT.Selection.InlineShapes.AddPicture(ovVar[1], ovVar[2], ovVar[3], ovVar[4]).Select;
wapTXT.Selection.InlineShapes.Item(1).ConvertToShape;
wapTXT.Selection.ShapeRange.WrapFormat.Side:= wdWrapLeft;
wapTXT.Selection.ShapeRange.ScaleWidth(0.3, msoFalse, msoScaleFromTopLeft);
wapTXT.Selection.ShapeRange.ScaleHeight(0.3, msoFalse, msoScaleFromTopLeft);
dShapeHeight:= PointsToCentimeters(wapTXT.Selection.ShapeRange.Height);
dShapeWidth := PointsToCentimeters(wapTXT.Selection.ShapeRange.Width);
dShapeLeft := PointsToCentimeters(wapTXT.Selection.ShapeRange.Left);
dShapeTop := PointsToCentimeters(wapTXT.Selection.ShapeRange.Top);
dPageWidth := PointsToCentimeters(wapTXT.ActiveDocument.PageSetup.PageWidth);
dPageHeight := PointsToCentimeters(wapTXT.ActiveDocument.PageSetup.PageHeight);
dLeftMargin := PointsToCentimeters(wapTXT.ActiveDocument.PageSetup.LeftMargin);
dRightMargin:= PointsToCentimeters(wapTXT.ActiveDocument.PageSetup.RightMargin);
wapTXT.Selection.ShapeRange.RelativeVerticalPosition:= wdRelativeVerticalPositionPage;
wapTXT.Selection.ShapeRange.Top:= CentimetersToPoints(dSerilTop); //dSerilTop:目前游標的所在位置
wapTXT.Selection.ShapeRange.RelativeHorizontalPosition:= wdRelativeHorizontalPositionPage;
wapTXT.Selection.ShapeRange.RelativeVerticalPosition:= wdRelativeVerticalPositionParagraph; //圖片隨者文字一起移動
if iNumCols= 2 then begin //雙欄位設定
if dSerilLeft< (dPageWidth- dTextSpaceing/ 2) then begin //左欄位出題
wapTXT.Selection.ShapeRange.Left:= CentimetersToPoints(dTextColWidth dLeftMargin- dShapeWidth);
end else begin //右欄位出題
wapTXT.Selection.ShapeRange.Left:= CentimetersToPoints(dPageWidth- dRightMargin- dShapeWidth);
end;
end else begin //單欄位設定
wapTXT.Selection.ShapeRange.Left:= CentimetersToPoints(dTextColWidth dLeftMargin- dShapeWidth);
end;
Selection.Collapse(EmptyParam);
Selection.TypeText('測試123');
Selection.TypeParagraph; //換行 <---主要的癥結點,執行此換行動作,圖片就會跟著移動 對不起,我又有問題來發問了!!
以上是我目前的程式碼,我的問題在於將圖片與文字一起移動,也就是wapTXT.Selection.ShapeRange.RelativeVerticalPosition:= wdRelativeVerticalPositionParagraph;
但是設入此行後就發生問題,基本上如果游標在某段的最前端執行Selection.TypeParagraph(換行)後才會圖片隨著文字一起移動,那如過游標在其他地方應該就不會造成這樣結果,但是我以上所執行的程式卻會造成無論我游標垂直位置移到哪邊,圖片的垂直位置也一樣移到那邊,不知道是程式哪邊有問題才會這樣,能再請大大在指導我小第一下下嘛??麻煩麻煩囉
|
chris_shieh
高階會員 發表:46 回覆:308 積分:240 註冊:2004-04-26 發送簡訊給我 |
不知道這是不是你要的
Selection.ShapeRange.ConvertToInlineShape; _Unit:=wdCharacter; //OleVariant _Count:=1; //OleVariant Selection.MoveRight(_unit, _Count, EmptyParam); Selection.Collapse(EmptyParam); Selection.TypeText('測試123'); Selection.TypeParagraph; //換行 <---主要的癥結點,執行此換行動作,圖片就會跟著移動@瞭解越多.懂得越少@ |
adrain
一般會員 發表:39 回覆:28 積分:13 註冊:2004-07-27 發送簡訊給我 |
以下這張(圖一)是我想要的結果
以下這張(圖二)目前是我程式執行後的結果,是錯誤的
//Selection.ShapeRange.ConvertToInlineShape; <-這一段在我這邊執行時會有問題
Selection.InlineShapes.Item(1).ConvertToShape; <-所以目前暫且以這行替代
_Unit:=wdCharacter; //OleVariant
_Count:=1; //OleVariant
Selection.MoveRight(_unit, _Count, EmptyParam);
Selection.Collapse(EmptyParam);
Selection.TypeText('測試');
Selection.TypeParagraph;
目前改成上面的程式執行後還是造成不是我所要的結果,還是一樣一執行Selection.TypeParagraph後圖片就會跟著游標垂直向下移動(如圖二),我希望能達到上圖(圖一)的結果,就是Selection.TypeParagraph執行後圖片不會移動到第二個段落,除非游標在第一個段落的最前面才可以移動圖片
,不好意思再麻煩大大!! 發表人 -
|
chris_shieh
高階會員 發表:46 回覆:308 積分:240 註冊:2004-04-26 發送簡訊給我 |
Selection.ShapeRange.RelativeHorizontalPosition := wdRelativeHorizontalPositionMargin; Selection.ShapeRange.RelativeVerticalPosition := wdRelativeVerticalPositionMargin;//圖片隨者文字一起移動 //Selection.ShapeRange.Left:=wdShapeRight; //這行不會過 蠻奇怪的 跟MSDN 說明不一樣 //Delphi包成了TOleNum=LongWord 超過.Left(Single)值域 不知道要如何轉換 Selection.ShapeRange.IncrementLeft(360); //折衷改用這行手動計算邊界間點數 Selection.ShapeRange.WrapFormat.DistanceTop := CentimetersToPoints(0); Selection.ShapeRange.WrapFormat.DistanceBottom := CentimetersToPoints(0); Selection.ShapeRange.WrapFormat.DistanceLeft := CentimetersToPoints(0); Selection.ShapeRange.WrapFormat.DistanceRight := CentimetersToPoints(0); Selection.ShapeRange.WrapFormat.type_ := wdWrapTight; _Unit:=wdCharacter; //OleVariant _Count:=1; //OleVariant Selection.MoveRight(_unit, _Count, EmptyParam); Selection.Collapse(EmptyParam); for i :=0 to 50 do begin Selection.TypeText('測試'); end; Selection.TypeParagraph; //換行 <---主要的癥結點,執行此換行動作,圖片就會跟著移動@瞭解越多.懂得越少@ |
adrain
一般會員 發表:39 回覆:28 積分:13 註冊:2004-07-27 發送簡訊給我 |
Selection.TypeText('1.');
Selection.TypeText(Char(9));
dSerilTop := PointsToCentimeters(Selection.Information[wdVerticalPositionRelativeToPage]); //垂直座標
dSerilLeft:= PointsToCentimeters(Selection.Information[wdHorizontalPositionRelativeToPage]); //水平座標
Selection.InlineShapes.AddPicture(ovVar[1], ovVar[2], ovVar[3], ovVar[4]).Select;
Selection.InlineShapes.Item(1).ConvertToShape;
//Selection.ShapeRange.RelativeHorizontalPosition := wdRelativeHorizontalPositionMargin; Selection.ShapeRange.RelativeHorizontalPosition:= wdRelativeHorizontalPositionColumn; //目前是以這個常數做設定,因為可能會有多欄位的設定
Selection.ShapeRange.RelativeVerticalPosition:= wdRelativeVerticalPositionParagraph;
Selection.ShapeRange.WrapFormat.Side:= wdWrapBoth;
Selection.ShapeRange.Left:= CentimetersToPoints(0);
Selection.ShapeRange.Top:= CentimetersToPoints(0.1);
Selection.ShapeRange.ScaleWidth(0.3, msoFalse, msoScaleFromTopLeft);
Selection.ShapeRange.ScaleHeight(0.3, msoFalse, msoScaleFromTopLeft);
dShapeHeight:= PointsToCentimeters(Selection.ShapeRange.Height);
dShapeWidth := PointsToCentimeters(Selection.ShapeRange.Width);
ggdRightMargin:= PointsToCentimeters(ActiveDocument.PageSetup.RightMargin);
Selection.ShapeRange.IncrementLeft(CentimetersToPoints(ggdTextColWidth- dShapeWidth));
Selection.ShapeRange.WrapFormat.DistanceTop:= CentimetersToPoints(0);
Selection.ShapeRange.WrapFormat.DistanceBottom:= CentimetersToPoints(0);
Selection.ShapeRange.WrapFormat.DistanceLeft:= CentimetersToPoints(0);
Selection.ShapeRange.WrapFormat.DistanceRight:= CentimetersToPoints(0);
Selection.ShapeRange.WrapFormat.Type_:= wdWrapTight; // 將圖片的文繞圖方式改為'緊密'
ovVar[1]:= wdCharacter;
ovVar[2]:= 1;
Selection.MoveRight(ovVar[1], ovVar[2], EmptyParam);
Selection.Collapse(EmptyParam);
for i :=0 to 50 do
begin
Selection.TypeText('測試');
end;
Selection.TypeParagraph; //換行<--執行到此行後還是會造成(圖片二)的狀況
以上是我目前改過的程式,但是還是一直存在著Selection.TypeParagraph執行圖片就會跟著下移,還是無法達到(圖片一)的境界
目前的執行結果好像圖片永遠都會跟著最後一個段落在做變化,我在想是不是有可能得先設定圖片要以哪個段落做基礎,才能夠執行selection.TypeParagraph後圖片不會跟著下移??這也只是我的猜想....還是您有其他的方式呢?
|
chris_shieh
高階會員 發表:46 回覆:308 積分:240 註冊:2004-04-26 發送簡訊給我 |
Selection.TypeText('1.'); Selection.TypeText(Char(9)); dSerilTop := PointsToCentimeters(wapTXT.Selection.Information[wdVerticalPositionRelativeToPage]); //流水號垂直座標 dSerilLeft := PointsToCentimeters(wapTXT.Selection.Information[wdHorizontalPositionRelativeToPage]); //流水號水平座標 Selection.InlineShapes.AddPicture(ovVar[1], ovVar[2], ovVar[3], ovVar[4]).Select; Selection.InlineShapes.Item(1).ConvertToShape; Selection.ShapeRange.RelativeHorizontalPosition := wdRelativeHorizontalPositionMargin; //要用這個設定才行 Selection.ShapeRange.RelativeVerticalPosition := wdRelativeVerticalPositionMargin;//要用這個設定才行 Selection.ShapeRange.WrapFormat.Side := wdWrapBoth; Selection.ShapeRange.Left := CentimetersToPoints(0); Selection.ShapeRange.Top := CentimetersToPoints(0.1); Selection.ShapeRange.ScaleWidth(0.3, msoFalse, msoScaleFromTopLeft); Selection.ShapeRange.ScaleHeight(0.3, msoFalse, msoScaleFromTopLeft); dShapeHeight := PointsToCentimeters(Selection.ShapeRange.Height); dShapeWidth := PointsToCentimeters(Selection.ShapeRange.Width); ggdRightMargin := PointsToCentimeters(ActiveDocument.PageSetup.PageWidth); //Selection.ShapeRange.IncrementLeft(CentimetersToPoints(ggdTextColWidth - dShapeWidth)); //sorry 懶得算了, ggdTextColWidth 計算方式我想你有 反正就是對齊右邊 Selection.ShapeRange.IncrementLeft(360); Selection.ShapeRange.WrapFormat.DistanceTop := CentimetersToPoints(0); Selection.ShapeRange.WrapFormat.DistanceBottom := CentimetersToPoints(0); Selection.ShapeRange.WrapFormat.DistanceLeft := CentimetersToPoints(0); Selection.ShapeRange.WrapFormat.DistanceRight := CentimetersToPoints(0); Selection.ShapeRange.WrapFormat.Type_ := wdWrapTight; // 將圖片的文繞圖方式改為'緊密' _Unit := wdCharacter; _Count:= 1; Selection.MoveRight(_Unit, _Count, EmptyParam); Selection.Collapse(EmptyParam); for i := 0 to 50 do begin Selection.TypeText('測試'); end; Selection.TypeParagraph; //換行<--執行到此行後還是會造成(圖片二)的狀況以下是我的執行結果 @瞭解越多.懂得越少@ |
adrain
一般會員 發表:39 回覆:28 積分:13 註冊:2004-07-27 發送簡訊給我 |
(圖1-1)游標在1的最左側,且尚未執行Selection.TypeParagraph(起始狀態)
(圖1-2)執行Selection.TypeParagraph後圖片會隨著段落垂直下降一行
(圖1-3)執行Selection.TypeParagraph後圖片並不會隨著段落垂直下降一行(圖片保持原位置)
以上三張圖代表著尚未執行Selection.TypeParagraph(圖1-1),
及執行後狀態(圖1-2),(圖1-3) 而(圖1-2)是下面這兩行所完成
Selection.ShapeRange.RelativeHorizontalPosition:= wdRelativeHorizontalPositionPage;
Selection.ShapeRange.RelativeVerticalPosition:= wdRelativeVerticalPositionParagraph;
也是我目前所要的執行結果,而且游標在'1'的右邊再次執行Selection.TypeParagraph後圖片就不可再隨著游標下降,簡單的說就是游標在'1'的左邊圖片可以垂直移動,游標在'1'左邊圖片就不可隨著游標垂直移動
但是在目前我的程式裡:游標在'1'左邊圖片就不可隨著游標垂直移動的功能卻無法達成,一直困擾我,不知大大有否更好的解決方式呢? 而(圖1-3)是下面這兩行所完成,也就是大大您敎我的
Selection.ShapeRange.RelativeHorizontalPosition := wdRelativeHorizontalPositionMargin; Selection.ShapeRange.RelativeVerticalPosition := wdRelativeVerticalPositionMargin;
然而卻無法達成圖片隨段落垂直移動,也就是(圖1-2)的結果,可能是我要的功能沒跟您說詳細,所以讓您不清楚我所要的結果!!所以真是不好意思還得再麻煩您
|
chris_shieh
高階會員 發表:46 回覆:308 積分:240 註冊:2004-04-26 發送簡訊給我 |
Selection.TypeText('1.'); Selection.TypeText(Char(9)); dSerilTop := PointsToCentimeters(wapTXT.Selection.Information[wdVerticalPositionRelativeToPage]); //流水號垂直座標 dSerilLeft := PointsToCentimeters(wapTXT.Selection.Information[wdHorizontalPositionRelativeToPage]); //流水號水平座標 Selection.InlineShapes.AddPicture(ovVar[1], ovVar[2], ovVar[3], ovVar[4]).Select; Selection.InlineShapes.Item(1).ConvertToShape; Selection.ShapeRange.RelativeHorizontalPosition := wdRelativeHorizontalPositionMargin; //要用這個設定才行 Selection.ShapeRange.RelativeVerticalPosition := wdRelativeVerticalPositionParagraph;//隨物件移動改成這個設定 Selection.ShapeRange.WrapFormat.Side := wdWrapBoth; Selection.ShapeRange.Left := CentimetersToPoints(0); Selection.ShapeRange.Top := CentimetersToPoints(0); Selection.ShapeRange.ScaleWidth(0.3, msoFalse, msoScaleFromTopLeft); Selection.ShapeRange.ScaleHeight(0.3, msoFalse, msoScaleFromTopLeft); dShapeHeight := PointsToCentimeters(Selection.ShapeRange.Height); dShapeWidth := PointsToCentimeters(Selection.ShapeRange.Width); ggdRightMargin := PointsToCentimeters(ActiveDocument.PageSetup.PageWidth); //Selection.ShapeRange.IncrementLeft(CentimetersToPoints(ggdTextColWidth - dShapeWidth)); //sorry 懶得算了, ggdTextColWidth 計算方式我想你有 反正就是對齊右邊 Selection.ShapeRange.IncrementLeft(360); Selection.ShapeRange.WrapFormat.DistanceTop := CentimetersToPoints(0); Selection.ShapeRange.WrapFormat.DistanceBottom := CentimetersToPoints(0); Selection.ShapeRange.WrapFormat.DistanceLeft := CentimetersToPoints(0); Selection.ShapeRange.WrapFormat.DistanceRight := CentimetersToPoints(0); Selection.ShapeRange.WrapFormat.Type_ := wdWrapTight; // 將圖片的文繞圖方式改為'緊密' _Unit := wdCharacter; _Count:= 1; Selection.MoveRight(_Unit, _Count, EmptyParam); Selection.Collapse(EmptyParam); for i := 0 to 50 do begin Selection.TypeText('測試'); end; _Unit:=wdParagraph; _Count:=1; Selection.MoveUp(_Unit, _Count, EmptyParam); //移到段落開頭 Selection.TypeParagraph; //換行<--執行到此行後圖片跟著往下移執行結果如下 @瞭解越多.懂得越少@ |
adrain
一般會員 發表:39 回覆:28 積分:13 註冊:2004-07-27 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |