请教大家下面这段话转成VB。net为什么 gettype报错

loujiale 2010-10-03 04:35:27
以下是原来C#的代码

private void WordConvert()
{
Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();
Type wordType = word.GetType();

Microsoft.Office.Interop.Word.Documents docs = word.Documents;
Type docsType = docs.GetType ();
object objDocName = @"c:\tmp\test.doc";
Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { objDocName, true, true });

//打印输出到指定文件
Type docType = doc.GetType();
object printFileName = @"c:\tmp\test.ps";
docType.InvokeMember("PrintOut", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { false, false, Microsoft.Office.Interop.Word.WdPrintOutRange.wdPrintAllDocument, printFileName });
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);

string o1 = "c:\\tmp\\test.ps";
string o2 = "c:\\tmp\\test.pdf";
string o3 = "";

//引用将PS转换成PDF的对象
try
{
ACRODISTXLib.PdfDistillerClass pdf = new ACRODISTXLib.PdfDistillerClass();
pdf.FileToPDF(o1, o2, o3);
}
catch { }

//为防止本方法调用多次时发生错误,必须停止acrodist.exe进程
foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcesses())
{
int begpos;
int endpos;

string sProcName = proc.ToString();
begpos = sProcName.IndexOf("(") + 1;
endpos = sProcName.IndexOf(")");

sProcName = sProcName.Substring(begpos, endpos - begpos);

if (sProcName.ToLower().CompareTo("acrodist") == 0)
{
try
{
proc.Kill();
}
catch { }
break;
}
}
}
转成VB。NET
Private Sub WordConvert()
Dim word As Microsoft.Office.Interop.Word.ApplicationClass = New Microsoft.Office.Interop.Word.ApplicationClass()
Dim wordType As Type = word.GetType

Dim docs As Microsoft.Office.Interop.Word.Documents = word.Documents
Dim docsType As System.Type = docs.GetType() Dim objDocName As Object = "c:\tmp\test.doc"
Dim doc As Microsoft.Office.Interop.Word.Documents = DirectCast(docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, Nothing, docs, New [Object]() {objDocName, True, True}), Microsoft.Office.Interop.Word.Documents)

'打印输出到指定文件
Dim docType As Type = doc.GetType Dim printFileName As Object = "c:\tmp\test.ps"
docType.InvokeMember("PrintOut", System.Reflection.BindingFlags.InvokeMethod, Nothing, doc, New Object() {False, False, Microsoft.Office.Interop.Word.WdPrintOutRange.wdPrintAllDocument, printFileName})
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, Nothing, word, Nothing)

Dim o1 As String = "c:\tmp\test.ps"
Dim o2 As String = "c:\tmp\test.pdf"
Dim o3 As String = ""

'引用将PS转换成PDF的对象
Try
Dim pdf As New ACRODISTXLib.PdfDistillerClass()
pdf.FileToPDF(o1, o2, o3)
Catch
End Try

'为防止本方法调用多次时发生错误,必须停止acrodist.exe进程
For Each proc As Process In System.Diagnostics.Process.GetProcesses()
Dim begpos As Integer
Dim endpos As Integer

Dim sProcName As String = proc.ToString()
begpos = sProcName.IndexOf("(") + 1
endpos = sProcName.IndexOf(")")

sProcName = sProcName.Substring(begpos, endpos - begpos)

If sProcName.ToLower().CompareTo("acrodist") = 0 Then
Try
proc.Kill()
Catch
End Try
Exit For
End If
Next
End Sub

标成红色的2句话报错 ,请问如何解决
...全文
206 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
loujiale 2010-10-04
  • 打赏
  • 举报
回复
难道没有人知道吗 继续顶
Ants2002 2010-10-04
  • 打赏
  • 举报
回复
学习了
loujiale 2010-10-04
  • 打赏
  • 举报
回复
继续顶
wuyq11 2010-10-03
  • 打赏
  • 举报
回复
引用什么WORD 组件
loujiale 2010-10-03
  • 打赏
  • 举报
回复
自己顶
loujiale 2010-10-03
  • 打赏
  • 举报
回复
自己顶
loujiale 2010-10-03
  • 打赏
  • 举报
回复
我就是这样写的 可是报错
错误 3 “GetType”不是“Microsoft.Office.Interop.Word.Documents”的成员。 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\WebApplication1\WebApplication1\WebForm4.aspx.vb 28 39 WebApplication1
wuyq11 2010-10-03
  • 打赏
  • 举报
回复
Dim word As New Microsoft.Office.Interop.Word.ApplicationClass()
Dim wordType As System.Type= word.GetType()
Dim docs As Microsoft.Office.Interop.Word.Documents = word.Documents
Dim docsType As System.Type= docs.GetType()

62,271

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧