Click here to Skip to main content
15,922,894 members
Home / Discussions / C#
   

C#

 
QuestionAnnoying new code folding feature in Sharpdevelop 2.0 Pin
Allah On Acid12-Mar-06 15:42
Allah On Acid12-Mar-06 15:42 
QuestionStatus Bar Pin
Sean8912-Mar-06 14:44
Sean8912-Mar-06 14:44 
AnswerRe: Status Bar Pin
jklucker12-Mar-06 15:16
jklucker12-Mar-06 15:16 
GeneralRe: Status Bar Pin
Sean8912-Mar-06 16:06
Sean8912-Mar-06 16:06 
AnswerRe: Status Bar Pin
mcljava12-Mar-06 15:38
mcljava12-Mar-06 15:38 
QuestionhDC problem Pin
IceWater4212-Mar-06 14:35
IceWater4212-Mar-06 14:35 
AnswerRe: hDC problem Pin
DigitalKing12-Mar-06 15:33
DigitalKing12-Mar-06 15:33 
AnswerRe: need help!! Pin
Steve Pullan12-Mar-06 13:24
Steve Pullan12-Mar-06 13:24 
GeneralRe: need help!! Pin
JulietPlando12-Mar-06 14:39
JulietPlando12-Mar-06 14:39 
GeneralRe: need help!! Pin
Steve Pullan12-Mar-06 15:00
Steve Pullan12-Mar-06 15:00 
Questionhow can i get the ip addres of host on windows application Pin
sa_keles12-Mar-06 12:55
sa_keles12-Mar-06 12:55 
AnswerRe: how can i get the ip addres of host on windows application Pin
Steve Pullan12-Mar-06 13:21
Steve Pullan12-Mar-06 13:21 
GeneralRe: how can i get the ip addres of host on windows application Pin
sa_keles12-Mar-06 13:36
sa_keles12-Mar-06 13:36 
AnswerRe: how can i get the ip addres of host on windows application Pin
mcljava12-Mar-06 14:17
mcljava12-Mar-06 14:17 
GeneralRe: how can i get the ip addres of host on windows application Pin
sa_keles12-Mar-06 15:30
sa_keles12-Mar-06 15:30 
AnswerRe: how can i get the ip addres of host on windows application Pin
jklucker12-Mar-06 15:28
jklucker12-Mar-06 15:28 
GeneralRe: how can i get the ip addres of host on windows application Pin
sa_keles12-Mar-06 15:34
sa_keles12-Mar-06 15:34 
GeneralRe: how can i get the ip addres of host on windows application Pin
sa_keles13-Mar-06 13:03
sa_keles13-Mar-06 13:03 
Questioncannot load image from desktop Pin
deepak112-Mar-06 12:22
deepak112-Mar-06 12:22 
AnswerRe: cannot load image from desktop Pin
Guffa12-Mar-06 12:44
Guffa12-Mar-06 12:44 
GeneralRe: cannot load image from desktop Pin
deepak112-Mar-06 12:59
deepak112-Mar-06 12:59 
GeneralRe: cannot load image from desktop Pin
Steve Pullan12-Mar-06 13:25
Steve Pullan12-Mar-06 13:25 
AnswerRe: cannot load image from desktop Pin
Guffa12-Mar-06 18:39
Guffa12-Mar-06 18:39 
QuestionNew to Excel Programming in C# Pin
mcljava12-Mar-06 12:17
mcljava12-Mar-06 12:17 
AnswerRe: New to Excel Programming in C# Pin
jklucker12-Mar-06 15:47
jklucker12-Mar-06 15:47 
You really don't need to know what the dll name is to reference the Excel object. Just right mouse on references in the Solution Explorer and click on Add Reference. Click on the COM tab and choose the Microsoft Excell 11.0 Object Library and click on select.

Add the following to your form's constructor:
<br />
ExcelObj = new Excel.Application();<br />
<br />
			//  See if the Excel Application Object was successfully constructed<br />
			if (ExcelObj == null)<br />
			{<br />
				MessageBox.Show("ERROR: EXCEL couldn't be started!");<br />
				System.Windows.Forms.Application.Exit();<br />
			}<br />
<br />
			//  Make the Application Visible<br />
			ExcelObj.Visible = false;<br />


Add, ExcelObj.Quit();, to the form's dispose method so Excel will shutdown when you application shut's down. If you don't do this then you flood your system Excel's in your task manager.

Here is the code you need to open an Excel workbook and display it's worksheet.
<br />
private void DispSheets(string FileName)<br />
		{<br />
			// ***********  Here is the call to Open a Workbook in Excel ****************<br />
			// It uses most of the default values (except for the read-only which we set to true)<br />
			theWorkbook = ExcelObj.Workbooks.Open(<br />
				FileName, 0, true, 5,<br />
				"", "", true, Excel.XlPlatform.xlWindows, "\t", false, false,<br />
				0, true, 0, 0);<br />
<br />
			foreach (Excel.Worksheet WrkSht in theWorkbook.Worksheets)<br />
			{<br />
				this.lstWrkSheets.Items.Add(WrkSht.Name);<br />
			}			<br />
		}<br />


You can use the next two methods to read data from an excel spreadsheet iinto a list box.
<br />
private void btnShowData_Click(object sender, System.EventArgs e)<br />
		{<br />
			int iFirst = 0;<br />
			int iLines = 0;<br />
			this.lstXLSData.Items.Clear();<br />
			//this.lstSelectedColumns.Items.Clear();<br />
<br />
			// get the collection of sheets in the workbook<br />
			Excel.Sheets sheets = theWorkbook.Worksheets;<br />
<br />
			// get the first and only worksheet from the collection of worksheets<br />
			Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(this.lstWrkSheets.SelectedIndex+1);<br />
			<br />
			// find starting row<br />
			iFirst = RowStart();<br />
			<br />
			// find row total<br />
			//iLines = RowTotal();<br />
			iLines = 25;<br />
			<br />
			// loop through user specified rows of the spreadsheet and place each row in the list view<br />
			for (int i = iFirst; i <= iLines; i++)<br />
			{				<br />
				//this.sbpInfo.Text = "Importing row " + i + " of " + iLines;<br />
				Excel.Range range = worksheet.get_Range(this.cmbStartCol.Text + i.ToString(),<br />
					this.cmbEndCol.Text + i.ToString());<br />
				System.Array myvalues = (System.Array)range.Cells.Value2;<br />
				string[] strArray = ConvertToStringArray(myvalues);<br />
				this.lstXLSData.Items.Add(new ListViewItem(strArray));<br />
			}<br />
		}<br />
private string[] ConvertToStringArray(System.Array values)<br />
		{ <br />
			// create a new string array<br />
			string[] theArray = new string[values.Length];<br />
<br />
			// loop through the 2-D System.Array and populate the 1-D String Array<br />
			for (int i = 1; i <= values.Length; i++)<br />
			{<br />
				if (values.GetValue(1, i) == null)<br />
					theArray[i-1] = "";<br />
				else<br />
					theArray[i-1] = (string)values.GetValue(1, i).ToString();<br />
			}<br />
<br />
			return theArray;<br />
		}<br />


I hope this information helps you!

I reject your reality and substitute my own!
- Adam Savage, Mythbuster
-George W Bush

life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.

My definition of an expert in any field is a person who knows enough about what's really going on to be scared.
- PJ Plauger

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.