我实现了: 1.只显示txt,excel文件对我来说很好 我必须实现: 1.必须同时显示手机号码 例如,如果我在excel表格中有10个手机号码,则在该excel表格上单击时,它必须在文本框中显示该手机号码,如下所示 8765432567,9876543567,...........
解决方案要打开文件,您需要一个OpenFileDialog. 将OpenFileDialog筛选器属性设置为".xls",.txt"以仅显示所需的文件. 在您的上传按钮上,单击事件使用: openfiledialog.showdialog() 在OpenFileDialog FileOk事件上,您将代码用于读取文件内容并将其显示在文本框中.
这里是一些示例代码,是VB,但可以轻松转换为C#: 您需要添加对Microsoft.Office.Interop.Excel的引用. Dim oXL作为Microsoft.Office.Interop.Excel.Application 作为Microsoft.Office.Interop.Excel.Workbook的Dim oBook 作为Microsoft.Office.Interop.Excel.Worksheet的Dim oSheet 昏暗vValue作为对象 oXL =新的Microsoft.Office.Interop.Excel.Application oBook = oXL.Workbooks.Open(OpenFileDialog1.FileName) oSheet = oBook.Worksheets("Sheet1") ``这里您具有单元格值,只需构建一个循环即可获取所需的数据 ''这将循环遍历第一列中的所有行 对于i As Integer = 0到oSheet.Rows.Count vValue = vValue +;" + oSheet.Cells(1,1).Value 下一个 myTextBox.Text = vValue
hi this is Krishna I have to develop one application which displays excel or text file data in text box see the below screens(how to add pictures)-->i don''t know so i describe below Form: mobile numbers Text box upload button when i click on upload button it has to show only excel and txt files only and when i click on excel or text file if it contains the mobile numbers then those are display in text box with comas my code is like below:
private void lnklUpload_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { OpenFileDialog browseFile = new OpenFileDialog(); browseFile.Filter = "Excel Files (*.xlsx;*.xls;*.txt)|*.xlsx;*.xls;*.txt"; browseFile.Title = "Browse To Excel 2007 File"; if (browseFile.ShowDialog() == DialogResult.Cancel) return; try { txtMobileNumber.Text = browseFile.FileName; string conExcel = txtMobileNumber.Text; //SetExcel(conExcel); } catch (Exception) { MessageBox.Show("Error opening file", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }I achieved: 1.it shows txt,excel files only that is fine for me I have to achieve: 1.it has to display mobile numbers side by side for example if i have 10 mobile numbers in excel sheet when click on that excel sheet it has to show the mobile numbers in textbox like below 8765432567,9876543567,...........
解决方案 For opening the file you need a OpenFileDialog. Set the OpenFileDialog filter property to ".xls",".txt" to show only the files you want. On your upload button click event use: openfiledialog.showdialog() On the OpenFileDialog FileOk Event you put your code for read the file contents and displaying them on textbox.Here''s some sample code, is VB but is easily convertible to C#: You need to add a reference to Microsoft.Office.Interop.Excel. Dim oXL As Microsoft.Office.Interop.Excel.Application Dim oBook As Microsoft.Office.Interop.Excel.Workbook Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet Dim vValue As Object oXL = New Microsoft.Office.Interop.Excel.Application oBook = oXL.Workbooks.Open(OpenFileDialog1.FileName) oSheet = oBook.Worksheets("Sheet1") ''Here you have cell value, just build a loop to get the data you want ''This will loop through all rows in the first column For i As Integer = 0 To oSheet.Rows.Count vValue = vValue + ";" + oSheet.Cells(1, 1).Value Next myTextBox.Text = vValue更多推荐
在TextBox中显示Excel数据和文本文件数据
发布评论