gpt4 book ai didi

excel - 试图在excel电子表格VB.Net上列出文件

转载 作者:行者123 更新时间:2023-12-04 20:51:31 26 4
gpt4 key购买 nike

我正在尝试使用 Openfile Dialog 命令导航到文件夹,然后选择一些文件。使用这些选定的文件,我试图将这些文件的名称写入 Excel 电子表格。我可以导航到该文件夹​​,但无法将文件写入电子表格。

我有以下代码:

    Dim strFileName As String
Dim openFile1 As OpenFileDialog = New OpenFileDialog()


Dim Row As Integer
Row = 14

Const Column_A As Integer = 1
Const Column_B As Integer = 2
Const Column_C As Integer = 3
Const Column_D As Integer = 4
Const Column_E As Integer = 5
Const Column_F As Integer = 6
Const Column_U As Integer = 21

openFile1.Title = "Open File Dialog" 'Title header for dialog box
openFile1.InitialDirectory = "C:\" 'Initial directory for file dialog box
openFile1.Filter = "All files (*.*)|" 'Filter all files
openFile1.Multiselect = True 'Allows the user to select to select multiple files


Dim Folder As IO.FileInfo()
Dim FileName As IO.FileInfo

If openFile1.ShowDialog() = DialogResult.OK Then 'This gives the "ok" to actually open the pop-up window
For Each FileName In Folder.SelectedItems
strFileName = openFile1.FileName 'Stores the Filename inside the variable
Big_Sheet.Cells(Row, Column_B) = FileName
Row = Row + 1
Big_Sheet.Cells(Row, Column_C).Value = strFileName 'Shows the variable FilePath
Next
End If

最佳答案

可能需要更多的研究来写入一个 excel 文件,比如让你的程序知道你在做什么。

Dim xls As Microsoft.Office.Interop.Excel.Application
Dim xlsWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlsWorkSheet As Microsoft.Office.Interop.Excel.Worksheet

xls = New Microsoft.Office.Interop.Excel.Application
xlsWorkBook = xls.Workbooks.Open("Insert file directory here")
xlsWorkSheet = xlsWorkBook.Sheets("sheet1")

xlsWorkSheet.Cells(1, 1) = TextBox1.Text

希望你能用它来让你更好地理解,我的 friend ,研究是关键。

关于excel - 试图在excel电子表格VB.Net上列出文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59043593/

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