そう。ここに難しい質問があります:
Word 2007 用の Word プラグインを開発し、Word 2010 にアップグレードしました。2007 年には安定していましたが、アップグレード後に重要な機能が 1 つ機能しなくなったため、変更を元に戻す必要がありました。
停止した特定の機能は、ドキュメントで選択された画像を取得し、その横に特定の書式設定でテキストボックスを追加します。(質問の最後にコードを提供します)
最終バージョンは、2007 年版と 2010 年版の両方にインストールできますが、2007 年にしか機能しません。今日まで!... [サスペンス]
偶然にも、あるクライアントがこのプラグインを使用して Word 2010 のドキュメントで作業しましたが、驚くべきことに、なんとか機能しました!!
そこで私は問題を調査しに行きました。作業中のドキュメントのコピーと、同じドキュメントの非作業バージョンのコピーを取り、両方の OpenXML を比較しました。
これが私が見つけたものです:
ワーキングドキュメント
これは、作業ドキュメントの画像マークアップです。
<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="3251200" cy="2285390"/>
<wp:effectExtent l="19050" t="19050" r="25400" b="19685"/>
<wp:docPr id="193" name="Imagem 48" descr="Elev. 4"/>
<wp:cNvGraphicFramePr>
<a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
</wp:cNvGraphicFramePr>
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:nvPicPr>
<pic:cNvPr id="0" name=""/>
<pic:cNvPicPr/>
</pic:nvPicPr>
<pic:blipFill>
<a:blip r:embed="rId33">
<a:lum/>
</a:blip>
<a:stretch>
<a:fillRect/>
</a:stretch>
</pic:blipFill>
<pic:spPr>
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="3251200" cy="2285390"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
<a:noFill/>
<a:ln w="19044" cmpd="sng">
<a:solidFill>
<a:srgbClr val="333333"/>
</a:solidFill>
<a:prstDash val="solid"/>
</a:ln>
</pic:spPr>
</pic:pic>
</a:graphicData>
</a:graphic>
</wp:inline>
</w:drawing>
作業文書ではありません
これは、非作業ドキュメントの同じ画像マークアップです。
<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0" wp14:anchorId="0FC2E46A" wp14:editId="42C17A65">
<wp:extent cx="3251200" cy="2285390"/>
<wp:effectExtent l="19050" t="19050" r="25400" b="19685"/>
<wp:docPr id="50" name="Imagem 50" descr="Elev. 1"/>
<wp:cNvGraphicFramePr>
<a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
</wp:cNvGraphicFramePr>
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:nvPicPr>
<pic:cNvPr id="0" name=""/>
<pic:cNvPicPr/>
</pic:nvPicPr>
<pic:blipFill>
<a:blip r:embed="rId24">
<a:lum/>
</a:blip>
<a:stretch>
<a:fillRect/>
</a:stretch>
</pic:blipFill>
<pic:spPr>
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="3251200" cy="2285390"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
<a:noFill/>
<a:ln w="19044" cmpd="sng">
<a:solidFill>
<a:srgbClr val="333333"/>
</a:solidFill>
<a:prstDash val="solid"/>
</a:ln>
</pic:spPr>
</pic:pic>
</a:graphicData>
</a:graphic>
</wp:inline>
</w:drawing>
唯一の違いは、作業ドキュメントの 2 行目です。
<wp:inline distT="0" distB="0" distL="0" distR="0">
もう1つは次のとおりです。
<wp:inline distT="0" distB="0" distL="0" distR="0" wp14:anchorId="0FC2E46A" wp14:editId="42C17A65">
そう!機能していないドキュメントの画像には、2 つの追加の属性wp14:anchorId
とwp14:editId
.
関数:
これは、テキストボックスを画像に追加してフォーマットするメソッドです。
Sub AddTextBox(ByVal picture As Word.InlineShape)
Dim textBox As Word.Shape =
ActiveDocument.Shapes.AddTextbox(
Orientation:=Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal,
Left:=picture.Width + 10,
Top:=0,
Width:=MarginWidth - picture.Width - 10,
Height:=picture.Height,
Anchor:=picture.Range.Paragraphs(1).Range)
With textBox
.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin
.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionParagraph
.Line.DashStyle = Microsoft.Office.Core.MsoLineDashStyle.msoLineSolid
.Line.BackColor.RGB = RGB(255, 255, 255)
.Line.Style = Microsoft.Office.Core.MsoLineStyle.msoLineSingle
.Line.Weight = 0.25
.LockAnchor = True
End With
EndSub
問題:
上記の方法は、ご覧のとおり、テキストボックスを画像がある段落の上部に揃えます。画像はインラインであるため、テキスト ボックスの上部は画像の上部に揃えられます。これは、Word 2007 および参照されている作業ドキュメントで発生することです。
問題は次のとおりです。作業していないドキュメントでこのメソッドを実行すると、テキストボックスがページの上部に配置されてしまいます。マージンなし。
この作業文書は例外的です。他のすべては、Word 2010 で機能しないものと同じように動作します。
MSDN のドキュメントを調べましたが、これらの属性に関する情報はありません。
だからお願い:
- 属性
wp14:anchorId
とは何wp14:editId
ですか? - また、Word でそれらの生成を停止するにはどうすればよいでしょうか。
- または、これらの属性が存在する場合にテキストボックスがページの上部に移動するのを止める方法。
よろしくお願いします。