gpt4 book ai didi

vb.net - 如何找到 excel.exe 路径和 notpad.exe 路径

转载 作者:行者123 更新时间:2023-12-04 20:17:40 29 4
gpt4 key购买 nike

在我的申请中 export excel or csv file 之后然后在 excel 或记事本中显示文件。
在这种情况下,我使用

电子表格:

  Dim xExcelFilePath As String = System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\Microsoft Office"
xDir = New DirectoryInfo(xExcelFilePath)
For Each xDirectory As DirectoryInfo In xDir.GetDirectories ' it use for find any version of excel is installed or not
If xDirectory.Name.Count < 6 Then Continue For
If xDirectory.Name.Trim.Substring(0, 6).ToUpper = "OFFICE" Then
If System.IO.File.Exists(xExcelFilePath & "\" & xDirectory.Name & "\EXCEL.EXE") Then
xExcelFilePath = xExcelFilePath & "\" & xDirectory.Name & "\EXCEL.EXE"
Exit For
End If
End If
Next
If System.IO.File.Exists(xExcelFilePath) Then
Dim p As New Process() ' xExcelFilePath means start and stop the local system process
p.StartInfo.UseShellExecute = True
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
p.StartInfo.FileName = xExcelFilePath ' Assaign the file name
p.StartInfo.Arguments = """" + xDestinationPath + """"
Grid1.SaveExcel(xDestinationPath, FarPoint.Win.Spread.Model.IncludeHeaders.ColumnHeadersCustomOnly) ' Export the Excel File
p.Start()

Else
Msg.Err("Could not find Excel installed on this system; file saved to:" + xExcelFilePath + ".")
End If

记事本:
 Dim p As New Process() ' xExcelFilePath means start and stop the local system process
p.StartInfo.UseShellExecute = True
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
p.StartInfo.FileName = "C:\windows\notepad.exe"
p.StartInfo.Arguments = """" + Application.StartupPath & Grid1.ActiveSheet.SheetName & ".csv" + """"
xCSVSheet.SaveTextFile(Application.StartupPath & Grid1.ActiveSheet.SheetName & ".csv", TextFileFlags.None, Model.IncludeHeaders.BothCustomOnly, "", ",", "")
p.Start()

在某些系统的上述代码中 excel file路径不按此顺序,因此抛出异常和 Notepad exe这里是静态添加的。我怎样才能得到 exe file系统中的路径?

最佳答案

不要担心确切的路径,让 Windows 来处理。如果要使用记事本打开文件,只需使用以下代码:

Process.Start("notepad.exe", Application.StartupPath & Grid1.ActiveSheet.SheetName & ".csv")

要启动程序最大化,您必须将其更改为以下内容:
    Dim startInfo As New ProcessStartInfo("notepad.exe")
startInfo.WindowStyle = ProcessWindowStyle.Maximized
startInfo.Arguments = """" & Application.StartupPath & Grid1.ActiveSheet.SheetName & ".csv"""
Process.Start(startInfo)

关于vb.net - 如何找到 excel.exe 路径和 notpad.exe 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18764632/

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