Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

private void menuItem2_Click(object sender, System.EventArgs e)
	{
		this.openFileDialog1.FileName = "*.xls";
		if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
		{
			Excel.Workbook theWorkbook = 
				ExcelObj.Workbooks.Open(
				openFileDialog1.FileName, 0, true, 5,
				"", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 
				0, true);

			// get the collection of sheets in the workbook
			Excel.Sheets sheets = theWorkbook.Worksheets;

			// get the first and only worksheet from the collection 
			// of worksheets
			Excel.Worksheet worksheet =  (Excel.Worksheet)sheets.get_Item(1);
			
			for (int i = 1; i <= 10; i++)
			{
Excel.Range range = worksheet.get_Range("A"+i.ToString (), "J"+i.ToString () );
				System.Array myvalues = (System.Array)range.Cells.Value;
				
				string[] strArray = ConvertToStringArray(myvalues);
				
				listView1.Items.Add(new ListViewItem(strArray));
//		
		
			}
			
			ExcelObj.Quit ();

			   
		}
	}

 

the above is the code for opening an excel file and put all the elements to list box which has 10 categories...........see snapshot

 

 

now when I retrieve the list items as

MessageBox.Show(listView1.items[0].Text);

it works fine

my question is

it would NOT let me retrieve the value which is in the second or third category of listbox

 

like 2, 3 or 4 through items[index] thingy...........

 

please help

 

also suggest the best method for retreiving excel data into c# arrays

tahnksssssssssss

  • Leaders
Posted

Perhaps what you need is the ListViewItem.SubItems property. Looking at the first item in your listview (LastNAme=1, Company=2, etc.) that ListViewItem's sub items would be "1", "2", "3", "4", etc.

 

Is this what you need?

[sIGPIC]e[/sIGPIC]
Posted

Yes, I tried it but I dont know its full syntax.........also will it show the ALL items under the company/city/state etc ????.

Suppose I want to have the values "1,2,3,4,5,6,7,8,9" the first items of last name, company......etc into an string array ??? how can i do that ???

and like the second item of each category in second string array and so on ?

 

 

with Fonds regars,

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...