0

VB.NET コードから Excel でタブ区切りの .txt ファイルを開くにはどうすればよいですか?

この質問は多くのフォーラムで尋ねられましたが、実際にこの問題を解決する答えはどこにも見つかりません。

Dim fileName As String = "file.txt"
Dim filePath As String = System.Reflection.Assembly.GetExecutingAssembly().Location
Dim fullFilePath As String = filePath.Substring(0, filePath.LastIndexOf("\"c)) & "\" & fileName

Public Sub OpenFileInExcel()

    Process.Start("excel.exe", fullFilePath)

End Sub
4

2 に答える 2

1

Process.Start() を使用して、最初のパラメーターとして "excel.exe" を渡し、2 番目のパラメーターとしてファイル名を渡します。

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim TabDelimitedFileName As String = "C:\Users\Mike\Documents\somefile.txt"
    If System.IO.File.Exists(TabDelimitedFileName) Then
        Process.Start("excel.exe", Chr(34) & TabDelimitedFileName & Chr(34))
    Else
        MessageBox.Show(TabDelimitedFileName, "File Not Found")
    End If
End Sub
于 2013-10-10T22:24:19.313 に答える
0

Excel COM オブジェクトを使用してファイルを開き、列を自動調整できます。

   Dim X As New Microsoft.Office.Interop.Excel.Application()
            X.Workbooks.Open(FileNm)
            Dim W As Microsoft.Office.Interop.Excel.Worksheet = X.ActiveSheet
            Dim R As Microsoft.Office.Interop.Excel.Range = W.Range(W.Cells(1, 1), W.Cells(65000, 250))
            R.Columns.AutoFit()
            X.Visible = True
于 2019-07-14T02:04:58.747 に答える