Click here to Skip to main content
16,013,918 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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,...........
Posted
Updated 8-Jul-10 18:29pm
v2

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.
 
Share this answer
 
Comments
krishna_goluguri 9-Jul-10 0:32am    
hi LNoguuira
thanks for ur answer but i already achived that one but how to display the numbers from excel sheet on text box.
please see my question again now i added my code also
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900