gpt4 book ai didi

c# - 错误 : Word 2013 VSTO Cannot Handle Image in Header Formatted Behind or In Front of Text

转载 作者:太空狗 更新时间:2023-10-29 20:38:29 25 4
gpt4 key购买 nike

I am cross-posting this question from Microsoft Community因为我在那里没有得到任何回应,也许这里有人可以对此有所启发。

我注意到使用 VSTO 处理文档时 Word 2013 特有的问题。

文档在页眉或页脚中包含一个图像,其布局选项设置为“使用文本环绕”和“文本后面”或“文本前面”:

Image with Layout Options set to "With Text Wrapping" with "Behind Text"

使用 VSTO,如果我打开文档然后尝试处理形状,我会收到以下异常:

The remote procedure call failed. (Exception from HRESULT: 0x800706BE)

我在这里上传了一个复制品:Word2013VstoImageFormattedInHeaderBug.zip

相关代码在WordFieldEnumerator.cs中:

private static bool ShapesWithinGroup(Shape shape)
{
var result = false;
try
{
// shape.GroupItems throws the exception
if (shape.GroupItems != null && shape.GroupItems.Count > 0)
{
result = true;
}
}
catch (UnauthorizedAccessException)
{
// This shape is not in a group - ignore
}
catch (Exception exception)
{
var exceptionString = exception.BuildExceptionString();
Console.WriteLine(exceptionString);
Console.WriteLine(exception.StackTrace);
//throw;
}

return result;
}

这是完整的异常和堆栈跟踪:

The remote procedure call failed. (Exception from HRESULT: 0x800706BE)

at Microsoft.Office.Interop.Word.Shape.get_GroupItems()
at Word2013VstoImageFormattedInHeaderBug.WordFieldEnumerator.ShapesWithinGroup(Shape shape) in C:\Users\QA\Desktop\Word2013VstoImageFormattedInHeaderBug\Word2013VstoImageFormattedInHeaderBug\WordFieldEnumerator.cs:line 170
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

at Microsoft.Office.Interop.Word.Shape.get_TextFrame()
at Word2013VstoImageFormattedInHeaderBug.WordFieldEnumerator.ProcessShapes(IEnumerable`1 shapes) in C:\Users\QA\Desktop\Word2013VstoImageFormattedInHeaderBug\Word2013VstoImageFormattedInHeaderBug\WordFieldEnumerator.cs:line 124
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.CustomMarshalers.EnumeratorViewOfEnumVariant.MoveNext()
at System.Linq.Enumerable.<CastIterator>d__aa`1.MoveNext()
at Word2013VstoImageFormattedInHeaderBug.WordFieldEnumerator.ProcessShapes(IEnumerable`1 shapes) in C:\Users\QA\Desktop\Word2013VstoImageFormattedInHeaderBug\Word2013VstoImageFormattedInHeaderBug\WordFieldEnumerator.cs:line 90
at Word2013VstoImageFormattedInHeaderBug.WordFieldEnumerator.GetAllFields() in C:\Users\QA\Desktop\Word2013VstoImageFormattedInHeaderBug\Word2013VstoImageFormattedInHeaderBug\WordFieldEnumerator.cs:line 64
at Word2013VstoImageFormattedInHeaderBug.Program.LockDialogFields(Document document) in C:\Users\QA\Desktop\Word2013VstoImageFormattedInHeaderBug\Word2013VstoImageFormattedInHeaderBug\Program.cs:line 116
at Word2013VstoImageFormattedInHeaderBug.Program.PdfDocument(String documentFilePath) in C:\Users\QA\Desktop\Word2013VstoImageFormattedInHeaderBug\Word2013VstoImageFormattedInHeaderBug\Program.cs:line 60

无论我是否 try catch 异常都会引发异常,并且它会导致 Word 2013 崩溃:

Event Viewer entry

这个bug在Word 2016上没有出现,我可以成功处理形状。但是,升级到 Office 2016 不是一种选择。我认为这需要 Office 2013 的修补程序才能修复错误。

我可以做些什么来让它在 Word 2013 上运行?我尝试了很多假定的修复,包括多次修复和重新安装 Office 2013,但都无济于事。

最佳答案

形状可以放置在页面上的任何位置,但它们始终附加到文本的锚定范围内。在遍历锚定到它的形状之前选择当前范围可能会解决 HRESULT 0x80010105 RPC_E_SERVERFAULT 异常。

在您的 GetAllFields() 方法中,在调用 ProcessShapes() 之前分别选择页眉和页脚的范围

foreach (HeaderFooter header in section.Headers)
{
if (header.LinkToPrevious) // || header.Index != WdHeaderFooterIndex.wdHeaderFooterFirstPage
{
continue;
}

header.Range.Select();

// Add the fields in the header
fields.AddRange(header.Range.Fields.Cast<Field>());

// Add the fields in the shapes in the header
var fieldsInShapes = ProcessShapes(header.Shapes.Cast<Shape>());
fields.AddRange(fieldsInShapes);
}

foreach (HeaderFooter footer in section.Footers)
{
if (footer.LinkToPrevious) // || footer.Index != WdHeaderFooterIndex.wdHeaderFooterFirstPage
{
continue;
}

footer.Range.Select();

// Add the fields in the footer
fields.AddRange(footer.Range.Fields.Cast<Field>());

// Add the fields in the shapes in the footer
var fieldsInShapes = ProcessShapes(footer.Shapes.Cast<Shape>());
fields.AddRange(fieldsInShapes);
}

不知道对你有没有帮助? (我不是 Word 互操作专家..)

关于c# - 错误 : Word 2013 VSTO Cannot Handle Image in Header Formatted Behind or In Front of Text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43727740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com