cexcel文件读取|EXCEL 在线读取TXT文件

cexcel文件读取|EXCEL 在线读取TXT文件的第1张示图

A. 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]总结:感觉还是这种方式比较好~

B. 如何从excel中读取数据

VLOOKUP是一个查找函数,给定一个查找的目标,它就能从指定的查找区域中查找返回想要查找到的值。它的基本语法为: VLOOKUP(查找目标,查找范围,返回值的列数,精确OR模糊查找)下面以一个实例来介绍一下这四个参数的使用 例1:如下图所示,要求根据表二中的姓名,查找姓名所对应的年龄。 公式:B13 =VLOOKUP(A13,$B$2:$D$8,3,0) 参数说明:1 查找目标:就是你指定的查找的内容或单元格引用。本例中表二A列的姓名就是查找目标。我们要根据表二的“姓名”在表一中A列进行查找。 公式:B13 =VLOOKUP(A13,$B$2:$D$8,3,0) 2 查找范围(VLOOKUP(A13,$B$2:$D$8,3,0) ):指定了查找目标,如果没有说从哪里查找,EXCEL肯定会很为难。所以下一步我们就要指定从哪个范围中进行查找。VLOOKUP的这第二个参数可以从一个单元格区域中查找,也可以从一个常量数组或内存数组中查找。本例中要从表一中进行查找,那么范围我们要怎么指定呢?这里也是极易出错的地方。大家一定要注意,给定的第二个参数查找范围要符合以下条件才不会出错: A 查找目标一定要在该区域的第一列。本例中查找表二的姓名,那么姓名所对应的表一的姓名列,那么表一的姓名列(列)一定要是查找区域的第一列。象本例中,给定的区域要从第二列开始,即$B$2:$D$8,而不能是$A$2:$D$8。因为查找的“姓名”不在$A$2:$D$8区域的第一列。 B 该区域中一定要包含要返回值所在的列,本例中要返回的值是年龄。年龄列(表一的D列)一定要包括在这个范围内,即:$B$2:$D$8,如果写成$B$2:$C$8就是错的。3 返回值的列数(B13 =VLOOKUP(A13,$B$2:$D$8,3,0))。这是VLOOKUP第3个参数。它是一个整数值。它怎么得来的呢。它是“返回值”在第二个参数给定的区域中的列数。本例中我们要返回的是“年龄”,它是第二个参数查找范围$B$2:$D$8的第3列。这里一定要注意,列数不是在工作表中的列数(不是第4列),而是在查找范围区域的第几列。如果本例中要是查找姓名所对应的性别,第3个参数的值应该设置为多少呢。答案是2。因为性别在$B$2:$D$8的第2列中。4 精确OR模糊查找(VLOOKUP(A13,$B$2:$D$8,3,0) ),最后一个参数是决定函数精确和模糊查找的关键。精确即完全一样,模糊即包含的意思。第4个参数如果指定值是0或FALSE就表示精确查找,而值为1 或TRUE时则表示模糊。这里兰色提醒大家切记切记,在使用VLOOKUP时千万不要把这个参数给漏掉了,如果缺少这个参数默为值为模糊查找,我们就无法精确查找到结果了。 1、接下来,我们的任务是通过利用VLOOKUP函数来实现查找同学C的成绩。为此在单元格中输入“=VLOOKUP”,此时就会发现VLOOKUP包括三个参数和一个可选参数。其中“lookup_value”是指要查找的值。参数“table_array”是指搜索的区域,在此在除标题之后的整个数据区域。第三个参数“col_index_num”是指整个函数返回单元格所在的列号。2、最后以右括号结尾,并按回车键,就出现想要的结果啦。

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中读取另一excel中的文件信息

在B4单元格输入以下公式,然后向下填充公式=VLOOKUP(A4,INDIRECT("'["&B$1&"*.xls]Sheet1!'A:B"),2,0)公式表示:通过INDIRECT函数,引用"'["&B$1&"*.xls]Sheet1!'A:B"字符串构成的查找引用区域,并通过VLOOKUP函数在其A列精确匹配与A4单元格相同的单元格,并返回对应B列的数据。

E. 如何打开一个excel文件读取多个文件

准备一下工具和原料:

1.一台Windows7系统笔记本电脑。

2.软件Excel 2007。

excel表格批量加载方法:

1.选择要加载的excel表格,点击鼠标右键,选择打开。

F. 如何用excel按条件来读取txt文件中的数据

既然是交通数据,涉及国民安全。那么,我来试着帮你扣我一五九六三九七零

G. 如何获取Excel文件里的内容

显然,这份Excel是由其他的商业软件生成的,该商业软件的评估期已过,不能再用了,所以实际上该Excel根本就没有数据。你叫该单位再重新提交数据。

H. 如何读取excel文件

1.新建一个excel文件,在里面写入两行数据,如下所示:2.打开visual studio新建一个web窗体应用程序,如下所示:3.在default.aspx中,添加一个按钮控件,添加一个gridview控件,按钮用于点击的时候连接excel获取数据,gridview用于展示数据。

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

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

J. EXCEL 在线读取TXT文件

将代码改成这个:

PrivateSubCommandButton1_Click()Range("A3:Q8000").ClearDimXmlHttpAsObject,tmpAsStringSetXmlHttp=CreateObject("MSXML2.XMLHTTP")WithXmlHttp.Open"GET","http://www.17500.cn/getData/3d.TXT",False.sendtmp=.responsetextEndWithDimarr,s,brr(),tAsStringarr=Split(tmp,Chr(10))ReDimbrr(0ToUBound(arr))Fori=0ToUBound(arr)IfLen(arr(i))>0Thens=Split(arr(i),"")Forj=0To4t=t&s(j)&","Nextt=Left(t,Len(t)-1)brr(i)=tt=""EndIfNextCells(2,1)="开奖期号"Cells(2,2)="开奖日期"Cells(2,3)="开"Cells(2,4)="奖"Cells(2,5)="号"Fori=0ToUBound(brr)Cells(i+3,1).Resize(1,5)=Split(brr(i),",")NextEndSub

未经允许不得转载:山九号 » cexcel文件读取|EXCEL 在线读取TXT文件

赞 (0)