Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用windows窗体生成Word文档不需要';不适用于所有电脑:System.Runtime.InteropServices.COMException(0x800A16CA)_C#_Runtime_Production Environment_Word_Winforms Interop - Fatal编程技术网

C# 使用windows窗体生成Word文档不需要';不适用于所有电脑:System.Runtime.InteropServices.COMException(0x800A16CA)

C# 使用windows窗体生成Word文档不需要';不适用于所有电脑:System.Runtime.InteropServices.COMException(0x800A16CA),c#,runtime,production-environment,word,winforms-interop,C#,Runtime,Production Environment,Word,Winforms Interop,我开发了一个windows窗体应用程序来生成Word报告。开始时,它在所有生成良好文档的PC机上运行良好,在我添加了以下代码块后,它在一些PC机上执行时停止生成报告 object end = 0; object start = 0; string title = Regex.Replace(tab.Cell(1, 1).Range.Text, pattern, dati[7]); Range rng = doc.Range(ref start, ref end); rng.Text = titl

我开发了一个windows窗体应用程序来生成Word报告。开始时,它在所有生成良好文档的PC机上运行良好,在我添加了以下代码块后,它在一些PC机上执行时停止生成报告

object end = 0;
object start = 0;
string title = Regex.Replace(tab.Cell(1, 1).Range.Text, pattern, dati[7]);
Range rng = doc.Range(ref start, ref end);
rng.Text = title;
Object styleHeading2 = "Heading 2";
rng.set_Style(ref styleHeading2);
rng.Paragraphs.OutlineLevel = Word.WdOutlineLevel.wdOutlineLevel2;
rng.Paragraphs.SpaceAfter = 10;
我发现,在不起作用的PC上,代码抛出以下异常: System.Runtime.InteropServices.COMException(0x800A16CA):具有指定名称的项不存在。 在Microsoft.office.Interop.Word.Range.set_样式中(对象和属性)

你有什么办法解决这个问题吗


谢谢

问题在于Word的语言。在我的电脑上,Word是英文的,但我的同事有母语Word,因此他们不理解命令:

 Object styleHeading2 = "Heading 2";
解决方案是使用Word.WdBuiltinStyle枚举设置样式,在本例中:

Object styleHeading2 = WdBuiltinStyle.wdStyleHeading2;

你有一个
async
方法吗?@karritos不,我不想,也许这在不久的将来会对我有所帮助