|
Console.Read Method[^]
Reads the next character from the standard input stream.
Console.ReadLine Method [^]
Reads the next line of characters from the standard input stream.
Difference:
"line of ... ers"
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Im trying to write a utility that opens an excel file using C#.net Visual Studio 2005. One of the first things I have to do is add a reference to the Microsoft Excel 11 Object Library. After I add this I have to add the "using" statement to use Microsoft.Office.Interop.Excel. However, I cant seem to be able to find the Interop class. Intellisense only picks up Microsoft.Office.Core ...has anyone else experienced this? How did you add this class?
Thanks
|
|
|
|
|
Your using statement will be
using Microsoft.Office.Core;
Just because I've been through this pain before and the documentation for automatation is awful, I thought I'd paste an old demo I had lying around...
private void ReadExcelValue()
{
object o = System.Reflection.Missing.Value;
Excel.Application objE = new Excel.Application();
Excel.Workbooks objBooks = null;
Excel.Workbook objB = null;
Excel.Worksheet objS = null;
objE.Workbooks.Open(Server.MapPath("spreadsheet.xls"), o, o, o, o, o, o, o, o, o, o, o, o, o, o);
objBooks = objE.Workbooks;
objB = objBooks[(object)1];
objS = (Excel.Worksheet)objB.Worksheets[(object)1];
Response.Write(((Excel.Range)objS.Cells[1, 1]).Text);
Release(objS);
if (objB != null)
objB.Close(false, o, o);
Release(objB);
if (objBooks != null)
objBooks.Close();
Release(objBooks);
if (objE != null)
objE.Quit();
Release(objE);
GC.Collect();
System.Diagnostics.Process[] objPr = System.Diagnostics.Process.GetProcessesByName("Excel");
foreach (System.Diagnostics.Process pr in objPr)
pr.Kill();
}
private void Release(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
}
catch { }
finally
{
obj = null;
}
}
Note: It's rather ugly stuff and there's a cheesy hack to make sure that the excel process doesn't persist on the server after execution (yes it's pretty easy to end up with thousands of Excel.exe processes if you don't kill them).
HTH
|
|
|
|
|
am i still missing any namespaces apart from the Microsoft.Office.Core library? cause I dont have the Application or Workbook classes in the Excel library (maybe im not stating that correctly). When I type Excel. intellisense does not pick up Application or Workbook...do I need any thing else?
Thanks
|
|
|
|
|
I only had two references I added to get that code working were:
Microsoft Office 11.0 Object Library
Microsoft Excel 11.0 Object Library
Obviously those will vary dependant on which version of office you are developing against.
Intellisense partially works in web developer express, and vs 2005. I do seem to remember that it pretty much didn't work at all in older versions of visual studio (but not 100% sure on that). It's all part of the pain of doing office automation I'm afraid
HTH
|
|
|
|
|
i cant even compile the project let alone get intellisense to work. i think im missing some namespace...the pain with VS 2005.
im waiving the white flag..help.
|
|
|
|
|
Have you included the Microsoft Interop Assemblies as references in your project?
|
|
|
|
|
I did do an add reference, and the on the COM tab chose Microsoft Excel 10 Object Library.
Does this suffice? Do you have to manually install any other interop libraries?
|
|
|
|
|
I believe that should be sufficient. You might, however, need the Excel 11 libraries, which are included on the install disk for excel if you have 2003 or 2003 Pro (But NOT 2003 basic).
Once you have the right one included, you should be able to access the correct namespaces/methods.
|
|
|
|
|
I have a user control with a ListView on the top and two buttons on the lower left. As the control is resized, I want the list to "grow" and the buttons to stay at the lower right. The ListView is anchored to top, bottom, left, right and the buttons are anchored to bottom and right. I can change the size at design time and everything works as planned. When I drop this on a form and drag the size to the size I want, it works fine. But when I close the designer and reopen it, it appears the ListView has expanded to the full size of the control like it is docked to each edge. Any idea what may be wrong?
I also tried setting the size in code but same issue at runtime.
Thanks. -- Bud
|
|
|
|
|
|
I have written app, borrowing some code from this article ( http://www.codeproject.com/cs/miscctrl/MyExtRichTextBox.asp?df=100&forumid=229962&select=1556581&msg=1556581[^] ). I have controls being inserted at various locations throughout a document and everything looks great. I'm able to query the interface and iterate through each control in the document. Great.
Now, however, I have to be able to save the document to be reloaded at a later time in the same application. When I do this normally, I lose the control information.
So, how can I save the document so that when I reload it, my controls are still showing up in the richtextbox?
Any help is greatly appreciated.
Thanks,
Tony
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.
|
|
|
|
|
When I look at the rtf, each place a control should be I have this:
\objattph\'20
So, something is being saved. However, there are properties on each control that are unique for each control inserted. I need to persist this data.
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.
|
|
|
|
|
Hi!
What are you using to save/load the contents of the RTB?
I just tried pasting an OLE object into the RTB, then saving it via RichTextBox.SaveFile() . Re-loading it afterwards with RichTextBox.LoadFile() showed the object...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Well, I'm not using an OLE object (which is the most likely reason why this doesn't work), I'm using a control I created in VS 2003. I'm fairly certain that if I implement the correct interfaces in the control that it will save correctly. But, I wouldn't swear to it.
I've tried the save file, I've even tried streaming it straight to disk. The objects are there because I can (using IRichEditOle.GetObjectCount) get a correct count of objects, and actually get the objects back, cast them to the appropriate control and access their properties. This is all before saving though. Once saved, it seems that only a placeholder is saved, and not the object or it's data.
Any ideas on what ole interfaces need to be implemented? Any Examples would be appreciated as well. I can't seem to find a lot of information about this.
Thanks,
Tony
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.
|
|
|
|
|
Any help is appreciated.
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.
|
|
|
|
|
I have a listbox with a contextmenu. The contextmenu has items such as "add" and "move up" and "move down" and "delete".
But how do I get the listboxitem that were clicked and hence the 'object' for the actions? It's not the selected item on the listbox since I right clicked to get the contextmenu.
I have a feeling that this should be easy, but I just dont know how to do it.
|
|
|
|
|
iakob wrote: But how do I get the listboxitem that were clicked
They hide that information in the documentation[^]
led mike
|
|
|
|
|
Basically, you need to handle the MouseDown event on the listbox and select the item you clicked.
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
ListBox listBox = sender as ListBox;
if (e.Button == MouseButtons.Right)
{
int index = listBox.IndexFromPoint(e.X, e.Y);
if (index >= 0 && index < listBox.Items.Count)
{
listBox.SelectedIndex = index;
}
listBox.Refresh();
}
}
In your event handler for the the context menu item, you will need to test if there are any selected items and do the appropriate action. Something like this:
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItems.Count > 0)
{
MessageBox.Show(listBox1.SelectedItems[0].ToString());
}
else
{
MessageBox.Show("You didn't select an item!");
}
}
If you really want to, you would actually enable/disable context menu options in your MouseDown event handler based on an item being selected or the user right clicking in "white space".
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
Thank you both (though one was more impudent than the other .
I've browsed the documentation and googled the question without finding an answer. Guess I simply failed to spot that particular member. RTFM is simple enough, one should think.
But thanks again.
|
|
|
|
|
Hey, this is my problem: i select the last line after i added the new text, i change the color of the line, but then all the lines before becomes the first color inserted and not the color i added them before.
what's the problem and how can i fix it?
this is the code where i add the text in:
private void rtbAddText(String NewText, Color NewColor)
{
NewText += Environment.NewLine;
if (NewColor == null)
this.rtbConsole.Text = NewText;
else
{
int OldLength = rtbConsole.Text.Length;
this.rtbConsole.Text += NewText;
this.rtbConsole.Select(OldLength, NewText.Length);
this.rtbConsole.SelectionColor = NewColor;
}
}
Thanks... NaNg.
|
|
|
|
|
rather than using
this.rtbConsole.Text += NewText; you should use
this.rtbConsole.AppendText(NewText);
HTH
|
|
|
|
|
Thanks.... was looking for Add() function... (at start) :P
|
|
|
|
|
Hi,
Is it possible to load up a GridView where all rows are in edit mode?
Thanks
|
|
|
|
|
Is this an ASP.NET question?
led mike
|
|
|
|