利用excel读取文件|通过excel可以直接获取txt文本文件的数据

利用excel读取文件|通过excel可以直接获取txt文本文件的数据的第1张示图

A. 如何在excel表格中读取txt文件

点击最上方一行的“数据”——导入外部数据——导入数据,,,然后选择你要导入的txt文件,根据提示设置你要显示的格式与行列,都可以选择设置

B. excel表格怎样自动读取外文件的数据

如果需要自动读取已经更新的外部文件数据,请将文件保存为*.xlsm格式,这样启动时就自动读取了。

C. EXEL 如何从另外一个EXCEL文档读取数据

方法:

1、常用读取数据多用VlookUP函数。

2、打开两个EXCEL表格,在第二个表格中输入:=VLOOKUP(A:A,[Book1]Sheet1!$A$1:$B$7,2,FALSE)

4、如果直接引用,可以在第二个表格输入=[Book1]Sheet1!$A$2即可。

D. EXCEL 自动读取指定文件内容

文件中的C1格中数值?还是文件中Sheet1中的C1单元格数值?在B2单元格输入以下公式,然后版向下填充公权式=INDIRECT("E:\ABC2014["&LEFT(A$1,3)&–RIGHT(A1)-3+ROW(A1)&"]Sheet1!C1")

E. 如何读取excel中的数据

情形一:读取Excel文件1如果数据文件为excel文件(xls或者xlsx格式的文件)2我们只需要使用MATLAB中提供的系统函数xlsread函数即可,其主要的调用形式为:a=xlsread('filename.xls');其中a表示读入文件所保存的变量名称,filename.xls(或者filename.xlsx)表示excel数据文件,help帮助文档中对xlsread函数的介绍3数据文件,我们只需要使用下面的命令进行读取即可:A = xlsread('data.xlsx');4如果数据文件保存在excel的某个sheet中,我们的使用方式为: A = xlsread('data.xlsx','Sheet1');情形二:写入Excel文件如果需要把某个变量的存储的数据写入到excel文件(xls或者xlsx格式的文件)我们只需要使用MATLAB中提供的系统函数xlswrite()函数即可,其主要的调用形式为:xlswrite('filename.xls',variable);其中variable表示需要写入Excel文件的变量名称,filename.xls(或者filename.xlsx)表示excel数据文件,help帮助文档中对xlswrite()函数的介绍数据文件,我们只需要使用下面的命令进行读取即可:xlswrite('output.xlsx',A);

F. 如何读取excel中的文本文件

使用以下代码即可实现:Sub test() Dim reg As Object Dim wjm As String Set reg = CreateObject("vbscript.regexp") With reg .Global = True .Pattern = "{""id"".*?}" End With wjm = Dir(ThisWorkbook.Path & "\*.txt") m = 2 Do While wjm <> "" txtm = ThisWorkbook.Path & "\" & wjm Open txtm For Input As #1 Do While Not EOF(1) Line Input #1, ss If Left(Trim(ss), 4) = "list" Then ss = Replace(ss, Chr(13), Chr(10) & Chr(13)) Set mathcs = reg.Execute(ss) For i = 0 To mathcs.Count – 1 s = Replace(mathcs(i), """", "") s = Replace(s, ":", ",") xm = Split(s, ",") For j = 1 To 3 Cells(m, j + 1) = xm(j * 2 – 1) Next For j = 4 To 5 Cells(m, j + 1) = xm(j * 2 + 1) Next Cells(m, 1) = wjm m = m + 1 Next Exit Do End If Loop Close #1 wjm = Dir LoopEnd Sub

G. excel怎么自动读取另一个excel表内的文件

方法一:在cc表里面a1输入“=[aa.xls]sheet1!$a$1”a2输入“=[bb.xls]sheet1!$a$1”方法二:你可以打开aa.xls在a1单元格右键复制,打开cc.xls在a1单元格右键点“选择性粘贴”,打开后点“粘贴链接”效果是一样的。

H. excel中怎样读取另一个文件

第一种方法:打开另一个文件,,paste:触发按钮单机事件,VBA如下:[code=vb] Private Sub CommandButton1_Click()Dim towb As WorkbookDim tows As WorksheetDim torow As IntegerDim fromwb As WorkbookDim fromws As WorksheetDim fromrow As IntegerDim projectnameDim iDim openfiles 'input the filepath of your selectionSet towk = Application.ActiveWorkbookSet tows = ActiveSheettorow = [a65536].End(3).Row + 1 'get the last row of data by column A 'get the active worksheet 'call openfile functionopenfiles = openfile()If openfiles <> "" ThenSet fromwb = Application.Workbooks.Open(openfiles)Set fromws = fromwb.Sheets("IPIS") 'set ID tows.Activate tows.Cells(torow, 1) = tows.Cells(torow – 1, 1) + 1 'set "Go/No Go" tows.Activate tows.Cells(torow, 2) = "Go" 'set "Project Name" fromwb.Activate fromws.Activate fromws.Cells(5, 1).Select Selection.Copy tows.Activate tows.Cells(torow, 7).Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False projectname = tows.Cells(torow, 7) 'set "Customer" by projectname tows.Activate tows.Cells(torow, 4) = Split(projectname, " ", 2)(0) ' range("A1") Like "*1234*" End Iftowk.ActivateEnd SubFunction openfile() As Variant 'Declare a variable as a FileDialog object. Dim fd As FileDialog 'Create a FileDialog object as a File Picker dialog box. Set fd = Application.FileDialog(msoFileDialogFilePicker) 'Declare a variable to contain the path 'of each selected item. Even though the path is aString, 'the variable must be a Variant because For Each…Next 'routines only work with Variants and Objects. Dim vrtSelectedItem As Variant 'Use a With…End With block to reference the FileDialog object. With fd 'Allow the selection of multiple files. .AllowMultiSelect = True 'Use the Show method to display the file picker dialog and return the user's action. 'If the user presses the button… If .Show = -1 Then 'Step through each string in the FileDialogSelectedItems collection. For Each vrtSelectedItem In .SelectedItems 'vrtSelectedItem is aString that contains the path of each selected item. 'You can use any file I/O functions that you want to work with this path. 'This example displays the path in a message box. MsgBox "Selected item's path: " & vrtSelectedItem openfile = vrtSelectedItem Next 'If the user presses Cancel… Else End If End With 'Set the object variable to Nothing. Set fd = NothingEnd Function[/code]总结:这种方法可以实现,但是需要打开对应的选择文件才行.第二种方法:利用引用来显示另一个表的内容,不打开文件,VBA代码如下:触发按钮单机事件:[code=vb] Private Sub CommandButton1_Click()Dim towb As WorkbookDim tows As WorksheetDim torow As IntegerDim fromwb As WorkbookDim fromws As WorksheetDim fromrow As IntegerDim projectnameDim iDim openfiles 'input the filepath of your selectionDim filenameSet towk = Application.ActiveWorkbookSet tows = ActiveSheettorow = [a65536].End(3).Row + 1 'get the last row of data by column A 'get the active worksheetApplication.ScreenUpdating = False 'call openfile functionopenfiles = openfile()If openfiles <> "" Then'Set fromwb = Application.Workbooks.Open(openfiles)'Set fromws = fromwb.Sheets("IPIS")'set ID tows.Activate tows.Cells(torow, 1) = tows.Cells(torow – 1, 1) + 1 'set "Go/No Go" tows.Activate tows.Cells(torow, 2) = "Go" 'set "Project Name" filename = dealstr(openfiles) ActiveSheet.Cells(torow, 7).Formula = "='" & filename & "IPIS'!$A$5" projectname = tows.Cells(torow, 7) 'set "Customer" by projectname tows.Activate tows.Cells(torow, 4) = Split(projectname, " ", 2)(0) ' range("A1") Like "*1234*" End Iftowk.ActivateApplication.ScreenUpdating = TrueEnd SubFunction dealstr(f As Variant) As Variant Z = Len(f) For ii = Z To 1 Step -1 If Mid(f, ii, 1) = "\" Then Exit For End If Next ii For i = Len(f) To y Step -1 If Mid(f, i, 1) <= "z" Then Exit For End If Next i a = Mid(f, ii + 1, i – ii) b = Mid(f, 1, ii) dealstr = b & "[" & a & "]"End FunctionFunction openfile() As Variant 'Declare a variable as a FileDialog object. Dim fd As FileDialog 'Create a FileDialog object as a File Picker dialog box. Set fd = Application.FileDialog(msoFileDialogFilePicker) 'Declare a variable to contain the path 'of each selected item. Even though the path is aString, 'the variable must be a Variant because For Each…Next 'routines only work with Variants and Objects. Dim vrtSelectedItem As Variant 'Use a With…End With block to reference the FileDialog object. With fd 'Allow the selection of multiple files. .AllowMultiSelect = True 'Use the Show method to display the file picker dialog and return the user's action. 'If the user presses the button… If .Show = -1 Then 'Step through each string in the FileDialogSelectedItems collection. For Each vrtSelectedItem In .SelectedItems 'vrtSelectedItem is aString that contains the path of each selected item. 'You can use any file I/O functions that you want to work with this path. 'This example displays the path in a message box. openfile = vrtSelectedItem Next 'If the user presses Cancel… Else End If End With 'Set the object variable to Nothing. Set fd = NothingEnd Function[/code]总结:这种方法,不用再打开选择的文件,但是,利用引用的方式显示另一个文件的内容,显得有些藕断丝连,不方便.第三种方法:利用ExecuteExcel4Macro,不打开文件就能读取内容,不再是引用的关系,VBA代码如下:触发按钮单机事件:[code=vb]Private Sub CommandButton1_Click()Dim towb As WorkbookDim tows As WorksheetDim torow As IntegerDim cnn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim i As IntegerDim SQL As String, cnnStr As String, sFileName As StringDim wb As WorkbookDim ws As WorksheetDim projectnameDim openfiles 'input the filepath of your selectionDim filenameSet towk = Application.ActiveWorkbookSet tows = ActiveSheettorow = [a65536].End(3).Row + 1 'get the last row of data by column A 'get the active worksheetApplication.ScreenUpdating = False 'call openfile functionopenfiles = openfile()If openfiles <> "" Then If GetValue(getpathname(openfiles), getfilename(openfiles), "IPIS", "A2") = "error" Then MsgBox "选取文件有误" Else 'set ID tows.Activate tows.Cells(torow, 1) = tows.Cells(torow – 1, 1) + 1 'set "Go/No Go" tows.Activate tows.Cells(torow, 2) = "Go" 'set "Project Name" tows.Cells(torow, 7) = GetValue(getpathname(openfiles), getfilename(openfiles), "IPIS", "A5") projectname = tows.Cells(torow, 7) 'set "Customer" by projectname tows.Activate tows.Cells(torow, 4) = Split(projectname, " ", 2)(0) End IfEnd IfApplication.ScreenUpdating = TrueEnd SubPrivate Function GetValue(path, filename, sheet, ref) ' 从关闭的工作薄返回值 Dim MyPath As String '确定文件是否存在 If Right(path, 1) <> "\" Then path = path & "\" If Dir(path & filename) = "" Then GetValue = "error" Exit Function End If '创建公式 MyPath = "'" & path & "[" & filename & "]" & sheet & "'!" & Range(ref).Range("A1").Address(, , xlR1C1) '执行EXCEL4宏函数 GetValue = Application.ExecuteExcel4Macro(MyPath)End FunctionFunction openfile() As Variant'Declare a variable as a FileDialog object. Dim fd As FileDialog 'Create a FileDialog object as a File Picker dialog box. Set fd = Application.FileDialog(msoFileDialogFilePicker) 'Declare a variable to contain the path 'of each selected item. Even though the path is aString, 'the variable must be a Variant because For Each…Next 'routines only work with Variants and Objects. Dim vrtSelectedItem As Variant 'Use a With…End With block to reference the FileDialog object. With fd 'Allow the selection of multiple files. .AllowMultiSelect = True 'Use the Show method to display the file picker dialog and return the user's action. 'If the user presses the button… If .Show = -1 Then 'Step through each string in the FileDialogSelectedItems collection. For Each vrtSelectedItem In .SelectedItems 'vrtSelectedItem is aString that contains the path of each selected item. 'You can use any file I/O functions that you want to work with this path. 'This example displays the path in a message box. openfile = vrtSelectedItem Next 'If the user presses Cancel… Else End If End With 'Set the object variable to Nothing. Set fd = NothingEnd FunctionFunction getfilename(f As Variant) As Variant Z = Len(f) For ii = Z To 1 Step -1 If Mid(f, ii, 1) = "\" Then Exit For End If Next ii For i = Len(f) To y Step -1 If Mid(f, i, 1) <= "z" Then Exit For End If Next i getfilename = Mid(f, ii + 1, i – ii)End FunctionFunction getpathname(f As Variant) As Variant Z = Len(f) For ii = Z To 1 Step -1 If Mid(f, ii, 1) = "\" Then Exit For End If Next ii For i = Len(f) To y Step -1 If Mid(f, i, 1) <= "z" Then Exit For End If Next i getpathname = Mid(f, 1, ii)End Function[/code]总结:感觉还是这种方式比较好~

I. 如何使用excel提取文件夹中的所有文件路径

使用excel提取文件夹中的所有文件名称的方法主要有以下两个:1、在那个文件夹内新建一个.TXT文件(如wenjian.txt),用记事本单开输入dir> 1.txt保存退出将刚才的.TXT(wenjian.txt)更名为.bat文件(wenjian.bat)双击wenjian.bat文件运行一次,在文件夹内多出一个1.txt文件打开1.txt文件,将其中的内容粘贴到Excel中,数据——分列处理就可以得到你要的文件名列表了!2、VBA(2003版)在那个文件夹下新建Excel文件,打开新建的Excel文件,右击工作表标签(如Sheet1),查看代码——在代码编辑器中输入以下代码Sub Test()Dim i As IntegerDim strPath As StringstrPath = ThisWorkbook.PathWith Application.FileSearch.LookIn = strPath.SearchSubFolders = True.Filename = "*.*"If .Execute > 0 ThenFor i = 1 To .FoundFiles.CountRange("A" & i) = .FoundFiles(i)Next iEnd IfEnd WithEnd Sub回到Excel表格中,工具——宏——宏——选择Sheet1.Test——执行方法一简单的操作就可以,方法二需要对程序有一定的了解,方法二通用性比较强,需要的时候执行一下就可以,更快捷。

J. 通过excel可以直接获取txt文本文件的数据

我们可以通过直接打开文本文件,也就是说我们通过excel可以直接获取txt文本文件的数据,具体的从文本文件获取数据的方法有两种,操作方法分别如下:1、直接打开文本文件用户可以选择“文件”菜单中的“打开”命令,在弹出的打开对话框中的“文件类型”下拉列表中选择“文本文件”,这样就可以从打开得文本文件中获得所需数据了。用这种方法导入数据又一个缺点,就是一旦数据进入Excel后,就无法于该文本文件同步了,也就是说,即使文本文件中的数据进行了更新,Excel也不会同时进行刷新的,必须重新导入才可以。2、利用“导入文本文件”命令执行“数据”菜单中“获取外部数据”子菜单上的“导入文本文件”命令,同样可以获得文本文件中的数据,在导入数据的同时Excel会将其作为外部数据区域,这样用户就可以在需要的时候刷新数据或者定期对数据进行刷新。以上就是我们通过excel直接获取txt文本文件数据的方法,两种方法都可以使用,根据自己的喜欢和需求去操作。

未经允许不得转载:山九号 » 利用excel读取文件|通过excel可以直接获取txt文本文件的数据

赞 (0)