在我的应用程序中,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
路径?