Click here to Skip to main content
15,892,480 members
Home / Discussions / C#
   

C#

 
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
GeneralRe: New to Excel Programming in C# Pin
mcljava13-Mar-06 4:05
mcljava13-Mar-06 4:05 
GeneralRe: New to Excel Programming in C# Pin
jklucker13-Mar-06 5:31
jklucker13-Mar-06 5:31 
GeneralRe: New to Excel Programming in C# Pin
mcljava13-Mar-06 5:56
mcljava13-Mar-06 5:56 
GeneralRe: New to Excel Programming in C# Pin
jklucker13-Mar-06 6:04
jklucker13-Mar-06 6:04 
GeneralRe: New to Excel Programming in C# Pin
Drew McGhie13-Mar-06 11:46
Drew McGhie13-Mar-06 11:46 
QuestionHow to catch event right mouse button in Pocket PC Pin
pmasknguyen12-Mar-06 12:04
pmasknguyen12-Mar-06 12:04 
AnswerRe: How to catch event right mouse button in Pocket PC Pin
Colin Angus Mackay12-Mar-06 20:08
Colin Angus Mackay12-Mar-06 20:08 
QuestionBitmap Creation Pin
allenmpcx12-Mar-06 11:40
allenmpcx12-Mar-06 11:40 
AnswerRe: Bitmap Creation Pin
Guffa12-Mar-06 12:47
Guffa12-Mar-06 12:47 
GeneralRe: Bitmap Creation Pin
allenmpcx12-Mar-06 14:02
allenmpcx12-Mar-06 14:02 
AnswerRe: Bitmap Creation Pin
Guffa13-Mar-06 0:04
Guffa13-Mar-06 0:04 
QuestionConnection String Pin
Sean8912-Mar-06 9:50
Sean8912-Mar-06 9:50 
AnswerRe: Connection String Pin
Jon Sagara12-Mar-06 11:29
Jon Sagara12-Mar-06 11:29 
GeneralRe: Connection String Pin
Sean8912-Mar-06 11:44
Sean8912-Mar-06 11:44 
QuestionDirectX viewer Pin
Sabry190512-Mar-06 7:58
Sabry190512-Mar-06 7:58 
AnswerRe: DirectX viewer Pin
Judah Gabriel Himango12-Mar-06 11:42
sponsorJudah Gabriel Himango12-Mar-06 11:42 
QuestionRichTextBox printing??? Pin
nogola12-Mar-06 7:06
nogola12-Mar-06 7:06 

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.