1

Word 文書の一時テキストをリストの新しいテキストに置き換えようとしています。テキストが形になっていない場合は機能しますが、テキストボックス内のテキストを見つけようとするとエラーがスローされます。これが私がこれまでに持っているものです:

public void FindReplace(List<repvals> replaceVals, string docLocation, int listLen)
        {

            //Opens a new Word application
            var app = new Microsoft.Office.Interop.Word.Application();
            //Opens the .docx
            var doc = app.Documents.Open(docLocation, true, false);

            //Selects the document
            var range = doc.Range();

            for (int i = 0; i < listLen; i++)
            {

                //Finds the parameter, then replaces
                range.Find.Execute(FindText: Convert.ToString(replaceVals[i].tempVal), Replace: WdReplace.wdReplaceAll, ReplaceWith: Convert.ToString(replaceVals[i].Boxes));

                var shapes = doc.Shapes;
                //Finds text within textboxes, then changes them
                foreach (Microsoft.Office.Interop.Word.Shape shape in shapes)
                {
                    var initialText = shape.TextFrame.TextRange.Text;
                    var resultingText = initialText.Replace(Convert.ToString(replaceVals[i].tempVal), Convert.ToString(replaceVals[i].Boxes));
                    shape.TextFrame.TextRange.Text = resultingText;
                }

            }
            //prints document
            doc.Save();
            doc.Close();

            //fully closes Word
            Marshal.ReleaseComObject(app);
        }

当たると問題発生

var initialText = shape.TextFrame.TextRange.Text;

そして、「このオブジェクトは添付テキストをサポートしていません」というエラーをスローします。

図形内のテキストは特別なものではありません。(例: tDATE、tNAMEなど)

何か案は?

4

2 に答える 2

0

*「2003年には、標準テキストボックスのAltTextのデフォルトは含まれているテキストでしたが、Alt Textを一致しないように変更できるため、このように読むことは決して良い考えではありませんでした.2010年には、Alt Textのデフォルトは空白です.

テキスト ボックスの名前が "Text Box 2" の場合 (そうでない場合は正しい名前に置き換えてください)、MsgBox ActiveDocument.Shapes("Text Box 2").TextFrame.TextRange が機能するはずです。"*

-- ジョン・SR・ウィルソン

http://answers.microsoft.com/en-us/office/forum/office_2010-customize/shapesalternativetext-is-blank-for-the-docx/7671c746-2c2b-41d9-b7de-389a766587a7?page=2&msgId=31041d67- e62b-4ce0-b283-57fd6a4ff6b2

于 2013-11-05T17:02:35.703 に答える