更新时间:2022-11-07 23:37:37
if(cmbhlevels.Value ==1)
{
ActiveDocument .AttachedTemplate.AutoTextEntries(z_TOC1)。Insert(Where:Selection.Range,RichText:true);
}
看起来原始代码是VBA,因此它不太可能在独立的c#项目中按原样运行因为没有ActiveDocument等概念。
你可以使用在线代码转换器
如 https://www.carlosag.net/tools/codetranslator/
选项A
第0步;学习C#
MSDN _ Visual C#和Visual Basic入门 [ ^ ]
步骤1;查看文档
Document.AttachedTemplate属性(Microsoft.Office.Tools.Word) [ ^ ]
选项B
步骤0;雇用开发人员
How do I convert this VB code to C# ? Here is VBA Code.
What I have tried:
If cmbhlevels.Value = "1" Then
ActiveDocument.AttachedTemplate.AutoTextEntries("z_TOC1").Insert Where _
:=Selection.Range, RichText:=True
End If
How can I rewrite this code to c# ? Please help me...
if (cmbhlevels.Value == "1") { ActiveDocument.AttachedTemplate.AutoTextEntries("z_TOC1").Insert (Where: Selection.Range, RichText: true); }
It looks like the original code is VBA though so it's unlikely to work as-is in an independent c# project as there is no concept of "ActiveDocument" etc.
You can use online code converter
like https://www.carlosag.net/tools/codetranslator/
Option A
Step 0; Learn C#
MSDN _ Getting Started with Visual C# and Visual Basic[^]
Step 1; Review the documentation
Document.AttachedTemplate Property (Microsoft.Office.Tools.Word)[^]
Option B
Step 0; Hire a developer