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など)
何か案は?