|
Hi,
How can I read data from an excel file in C#?
Best wishes
|
|
|
|
|
There is a Microsoft Toolkit for Office, you can control Excel from C# with that.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Gembox[^] do a cool .net dll. Very simple to use and you don't need Excel installed. The free version has some rows/sheets limits but is otherwise fully functional.
Dave
|
|
|
|
|
for excel 2003+,It is xml file in fact.and low versoin,i remeber CP had some article about it,you can search try.
|
|
|
|
|
No, the XML format started in 2008.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Hello everyone,
I have an question about forms in C#.
This is a problem which I have had since the start of programming in C#.
This is the problem:
In the (main) Form there is a button to open another (child) Form.
But when I use that Form I would like to have the main Form to be enabled. This is no problem. But when I close the child Form I would like to disable the main Form.
But I want the main form to do this.
So not something like this:
public void createForm(){
Child child = new Child(this);
child.show();
this.Enabled = true;
}
public void show(){
this.Enabled = false;
}
public Child(Main m){
this.main = m;
}
public void Dispose(){
main.show();
}
I would rather like to have something like this:
public void createForm(){
Child child = new Child();
child.show();
this.Enabled = true;
}
public void child_Disposed(object sender, EventArgs e){
this.Enabled = false;
}
If I'm not wrong, I'll have to work with delegates. But I don't know how, can somebody help me?
|
|
|
|
|
you might be able to catch the childs onFormClosing event on the parent and the disable the parent in the handler...
read my article on Delegates And Events[^]
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
Your second code looks OK, only thing is you haven't hooked the Disposed event.
public void createForm(){
Child child = new Child();
child.Disposed += this.child_Disposed;
child.show();
this.Enabled = true;
}
private void child_Disposed(object sender, EventArgs e){
this.Enabled = false;
}
|
|
|
|
|
Dear all,
I have a little problem converting a string that contains a ',' into a double.
Double needs a value devided by a dot ( or so I've read )
So , in my code , the following occurs :
string lat = p[u].X.ToString().Replace(',', '.');
MessageBox.Show(lat);
The output will be for example : 55.38978 ( which shows up perfect in the messagebox )
However, if i do the following :
MessageBox.Show(Convert.ToDouble(lat).ToString());
The output will be : 5538978
That doesn't make a whole lot of sense to me. So that dot is somehow bothering Double or am I not converting properly ?
Cheers
|
|
|
|
|
Well the problem is that double works with a komma in stead of a dot.
See it like this:
string ss = "55,5493";
string lat = ss.ToString().Replace(',', '.');
double d = Convert.ToDouble(ss);
double dd = Convert.ToDouble(lat);
MessageBox.Show("" + d);
MessageBox.Show("" + dd);
So you should change this one:
string lat = ss.ToString().Replace(',', '.');
into this one:
string lat = ss.ToString().Replace('.', ',');
Good luck
|
|
|
|
|
Hi Rick,
ToString() when applied to numbers will by default use the regional settings of your system,
which define a "decimal point" (not necessarily a period) and a "thousands separator" (not
necessarily a comma).
Parse() and TryParse() will observe the "decimal point" and ignore the "thousands separator".
If you have a number formatted one way (say West-European way, with decimal comma, and thousands
period) and parsed another way (say US way), you will get wrong results, and even an Exception
when more than one thousands separator is present.
The solution is NOT to replace periods by comma and vice versa, the solution is to apply
the appropriate settings, by using a FormatProvider or CultureInfo.
The above applies not only to doubles, but also to floats and decimals.
|
|
|
|
|
How do I write the contents of a webpage without a webbrowser? I am aware of
webBrowser.Navigate("http://www.google.com");
using (StreamWriter sw = File.CreateText(path))
{
sw.Write(webBrowser.DocumentText);
}
However, I was trying to use another way to do it without using a webBrowser.
Thanks in advance.
|
|
|
|
|
Hi,
have a look at WebRequest and HttpWebRequest classes and the GetResponse method.
|
|
|
|
|
In my application, when I showing a new form I do,
Form2 frm2=new Form2();
This.hide();
frm2.TopMost = true;
frm2.Show();
I do like that..again when I come to first form. I do the same being in second form.(imagine I am in Form2 now.)
this.Close();
frm1.Show(); // this is my first form.
Problem is some times I cant see my first form.it is still hiden. So it is happens sometimes.
Are there any way to know (some status) to know my form is already hiden or shown.
What is the best practice of this kind of situation?
|
|
|
|
|
Hi,
Show/Hide methods and Visible property always correspond.
|
|
|
|
|
Dear All,
To know the IEnumerable Interface I have done one demo Aplication please let me know whether there is anything wrong in my approach.
class MyFile : FileSystemInfo
{
private FileInfo _strFile;
public MyFile(FileInfo strFile)
{
_strFile = strFile;
}
public override void Delete()
{
_strFile.Delete();
}
public override bool Exists
{
get
{
if (_strFile.Exists)
{
return true;
}
else
{
return false;
}
}
}
public override string Name
{
get { return _strFile.Name;}
}
}
class MyFiles : IEnumerable<MyFile>
{
private string _directoryPath;
private string _fileExtension = "xml";
public MyFiles(string directoryPath)
{
_directoryPath = directoryPath;
}
public string FileExtension
{
get { return _fileExtension; }
set { _fileExtension = value; }
}
#region IEnumerable<MyFile> Members
public IEnumerator<MyFile> GetEnumerator()
{
DirectoryInfo di = new DirectoryInfo(_directoryPath);
FileInfo[] rgFiles = di.GetFiles("*." + _fileExtension);
foreach (FileInfo fi in rgFiles)
{
MyFile ss = new MyFile(fi);
yield return ss;
}
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
DirectoryInfo di = new DirectoryInfo(_directoryPath);
FileInfo[] rgFiles = di.GetFiles("*." + _fileExtension);
foreach (FileInfo fi in rgFiles)
{
MyFile ss = new MyFile(fi);
yield return ss;
}
}
#endregion
}
Here is it's implementation :
static void Main()
{
MyFiles myFS = new MyFiles(@"D:\TestInterface");
foreach(MyFile FS in MyFiles)
{
Console.WriteLine(FS.Name);
Console.ReadLine();
}
}
Here I am trying to Iterate the Files in Certain directory, and it's further implementation would be to Add New Methods to MyFile Class so as to get Certain required Data from the Files.So far it looks good .
I only wanted to know whether my Interface Implementation is Wrong anywhere or require any changes.
Thanks in Advance.
Develop2Program & Program2Develop
|
|
|
|
|
Navneet Hegde wrote: IEnumerator IEnumerable.GetEnumerator()
You dont really need to provide an implementation for that too. Simply return the generic IEnumerable, ie: return GetEnumerator();
Everything else looks fine
|
|
|
|
|
Please provide an example.
Thank You
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
delegate types are sealed, so no.
|
|
|
|
|
You can 'modify' a delegate though. As an example, see how I make Action delegates parallel in my latest article[^].
|
|
|
|
|
I still like that article. I still cannot think of a single instance where I'd use it, but who cares because it's cool.
|
|
|
|
|
Pete O'Hanlon wrote: I still cannot think of a single instance where I'd use it, but who cares because it's cool.
I want to make it even cooler, by taking any delegate type, then generating a DynamicMethod to do the same as I do with the Action delegates.
|
|
|
|
|
Ooohh... Nice. Still coming up blank as to when I would use it. The race is now on to find day to day practical uses.
|
|
|
|
|
Pete O'Hanlon wrote: Still coming up blank as to when I would use it.
With all the news about multicore CPU's, it could be handy anywhere
|
|
|
|
|
All delegates are derived from System.Delegate . But compiler won't allow you to derive from this class, it is done internally. You can always cast any user defined delegates to "System.Delegate" type.
|
|
|
|