|
Dear all,
Is there a way to create excel files and write data into excel files using C#, without the installation of MS Excel on the computer?
Thanks in advance.
|
|
|
|
|
There are some components out there (for example XLSReadWriteII.NET) but which versions of excel file format they support (and they are all different) is another matter.
If you are talking about creating the file and writing into it, why not use a CSV file, which is simple to create, simple to amend, and any flavour of excel can read them.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
I can't use csv, it most be xls.
What about using the oledb? with oledb u can also easly read and write excel, bud do you need then MS Excel for this?
|
|
|
|
|
Haven't tried it myself, but this says YES YOU DO[^] which makes sense to me.
Have you considered farming the excel stuff to a server which does have excel loaded (I assume it is the cost that stops you installing on all machines)?
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Use OleDb. it does not require excel to bee installed on the client computer.
However the file must be created first. Then fill it with data.
Also note that there is no UPDATE in using OLEDB/Jet with Excel files. A way around is: delete and add.
|
|
|
|
|
NPOI[^] will do this, open source too
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Private Void SendMail()
{
MailMessage mMsg = new MailMessage();
SmtpClient sClient = new SmtpClient();
string sHtmlBody = "Test mail ";
AlternateView avHtml = AlternateView.CreateAlternateViewFromString(sHtmlBody);
NetworkCredential crMail = new NetworkCredential();
mMsg.AlternateViews.Add(avHtml);
mMsg.From = new MailAddress("rishi@wi.com","Rishi");
mMsg.To.Add("test@wi.com","Test");
mMsg.Subject = "Test Mail");
//This is my actual local mail server ip, port and username password
//which I've already configured in my outlook and it is working fine.
//-------------------------------
sClient.Host = "192.168.1.7";
sClient.Port = 26;
crMail.UserName = "rishi@wi.com";
crMail.Password = "12345";
//-------------------------------
sClient.UseDefaultCredentials = False;
sClient.Credentials = crMail;
sClient.Send(mMsg);
}
When call this function this shows the error:
"Mail box unavailable. The server response was: No Such User"
There is no issue with this smtp details the same already I've configured in my MS outlook. And also it working fine in VB6 program using CDO.
My requirement is I want to send mails through SMTP which may available in locally or globally.
If anybody have an idea with this pls reply here..
Thanks & Regards,
Rishi
WinCrs
|
|
|
|
|
Try the code snippets given below:
void sendEmail(string strFrom
, string strTo
, string strSubject
, string strBody)
{
MailMessage objMailMessage = new MailMessage();
System.Net.NetworkCredential objSMTPUserInfo =
new System.Net.NetworkCredential();
SmtpClient objSmtpClient = new SmtpClient();
try
{
objMailMessage.From = new MailAddress(strFrom);
objMailMessage.To.Add(new MailAddress(strTo));
objMailMessage.Subject = strSubject;
objMailMessage.Body = strBody;
objSmtpClient = new SmtpClient("172.0.0.1"); objSMTPUserInfo = new System.Net.NetworkCredential
("User name", "Password","Domain");
objSmtpClient.Credentials = objSMTPUserInfo;
objSmtpClient.UseDefaultCredentials = false;
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSmtpClient.Send(objMailMessage);
}
catch (Exception ex)
{ MessageBox.Show (ex.Message.Tostring()); }
finally
{
objMailMessage = null;
objSMTPUserInfo = null;
objSmtpClient = null;
}
}
Thanks
Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Alright for some reason I can't seem to get this to work. I have tried the following
In form1.cs button click event
I added
Form2 f2 = new form2();
this.AddOwnedForm(f2);
f2.show();
then in form2 I added this in the button event
this.Owner.Controls["bnFindPrice"].enabled = true;
I keep getting object reference not set to instance of object but bnFindPrice is the valid name on form1 of the button I wish to enable.
Thanks for your help.
|
|
|
|
|
The reason is simple: the default access specifiers for controls is not public, so that stuff like this won;t work.
Why not? Because it is very bad practice. It ties the design of the two forms together, so that both must change if one does.
A better idea is to create an event in form two which form one subscribes to. Form two then "throws" the event so say "Changed", and form one handles the implementation.
I.e. Form one knows it has a button, so it handles all thing to do with it, including enable / disable. Form two just knows that the user has done something which form on knows how to handle.
Events aren't difficult to implement:
In form two:
public event EventHandler Changed;
protected virtual void OnChanged(EventArgs e)
{
EventHandler eh = Changed;
if (eh != null)
{
eh(this, e);
}
}
private void DoSomethingToChangeData()
{
OnChanged(null);
}
In form one:
frmChild.Change += new frmChange.ChangeHandler(Changed);
private void Changed(object sender, EventArgs e)
{
}
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Have you checked if owner property is null?
You can have a public property in the form1 for the enabled property of the button. In the second form, you can try this:
this.Parent.BtnEnabled = true;
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Use GetControl function to find control by name, e.g.
this.Owner.GetControl("bnFindPrice").enabled = true;
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:52am.
|
|
|
|
|
|
I want to write some method that will return an array that contain all open / active windows.
How can i do it ?
|
|
|
|
|
You can do that using methods in User32.dll. Here[^] is an example.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Use windows api function EnumWindows, http://msdn.microsoft.com/en-us/library/ms633497(VS.85).aspx
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:52am.
|
|
|
|
|
string text = "A";
string newText = "Some text that wont appear, " + text == "A" ? "its A" : "its something else";
MessageBox.Show(newText);
Output : its something else
it wont show the first segment of newText plus the condition got reverse
string text = "A";
string newText = "Some text that wont appear, " + text != "A" ? "its A" : "its something else";
MessageBox.Show(newText);
Output : its A
All good for following
string text = "A";
string newText = "Some text that wont appear, " + (text == "A" ? "its A" : "its something else");
MessageBox.Show(newText);
Output : Some text that wont appear, its A
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
AFAIK, it is not a bug. '+' takes precedence over '==' hence you are getting those results. Actually, first statement will do this:
"Some text that wont appear, A" == "A" ? "its A" : "its something else"
Hence the result.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Brilliant !!!
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
It's also bad form to not properly scope your statement. It makes the code much easier to read:
string text = "A";
string newText = "Some text that wont appear, " + ((text == "A") ? "its A" : "its something else");
Next, you should use string.Format or a StringBuilder object when your doing something like this. It's more efficient in terms of memory use.
string text = "A";
string newText = string.Format("Some text that wont appear, {0}", (text == "A") ? "its A" : "its something else");
StringBuilder newText2 = new StringBuilder("");
newText2.AppendFormat("Some text that wont appear, {0}", (text == "A") ? "its A" : "its something else");
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
To add to what danish said, it is always a good idea to enclose complex statements in parentheses, as it both enforces the precedence you want, and is easier to read.
I always use them for the "?" operator: (cond ? true : false). If nothing else, VS will highlight the beginning and end when the cursor is over the other, and CTRL+} will move from one to the other.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
I'm learning WPF (finally). Just bought a book and started.
Things are going quite well and all the test application seem to work. I have only 1 problem I can't seem to find.
Everytime I want to change the name of the file and class from eg. Window1 to something more comprehensive I get an error in App.g.cs where he says that namespace "mynamespace" doesn't find the App object. For my tests I just deleted it, but since it is created by Visual Studio it will often overwrite it again.
I played around a little with XML namespaces in both the changed Window1.xaml and cs files as with the App.xaml and cs files. no avail (the book also uses standard Window1 naming so no help there).
I'm playing around on my home desktop with VS 2008 express (the free version) edition. I haven't tried yet on my work laptop.
thanks !
PS: just curious, my first impression is that WPF is a little 'forced' and is not really easy programming (xaml), am I alone in this?
|
|
|
|
|
Clean your solution and then try again.
V. wrote: PS: just curious, my first impression is that WPF is a little 'forced' and is not really easy programming (xaml), am I alone in this?
Using Expression Blend generally reduces some of this xaml work.
There are only 10 types of people in this world — those who understand binary, and those who don't. |
|
|
|
|
|
What do you mean exactly with "clean your solution" ?
thanks.
|
|
|
|
|
Hi All,
say i have these inputs strings:
string input_1 = " ABCD ";
string input_2 = " A BC D ";
string input_3 " A B C D ";
I want to convert these strings to the follows:
input_1 = " ABCD";
input_2 = " A BC D";
input_3 " A B C D";
basically remove all the blanks after the last letter, i know the string.TrimEnd() function in .Net can be used to achieve my requirement. Is there another way (without using string.TrimEnd() function) to achieve the same as String.TrimEnd() does?
Many thanks
|
|
|
|