|
Hi,
Here is the program for displaying simple text in excel using late binding.
It checks at run time.This program works on all the version of Excel.
I want to modfify this program.
Can anybody help me to do that.
I want to display All the rows and coulmns of Emp table
This is very easy with early binding. I want to do that with late binding
here is code
Write this code inside button click event pls anybody modify I want to display table conntents Excel using late binding
----------------------------------------
object objApp_Late;
object objBook_Late;
object objBooks_Late;
object objSheets_Late;
object objSheet_Late;
object objRange_Late;
object[] Parameters;
int intExcelPID;
try
{
// Get the class type and instantiate Excel.
Type objClassType;
objClassType = Type.GetTypeFromProgID("Excel.Application");
objApp_Late = Activator.CreateInstance(objClassType);
Process[] aProcesses=Process.GetProcessesByName("Excel");
// please remove the string variable
string strProc="These are the processes running \n";
for (int i = 0; i <= aProcesses.GetUpperBound(0); i++)
{
intExcelPID = aProcesses[i].Id;
strProc+=intExcelPID.ToString()+ " ";
}
//Get the workbooks collection.
objBooks_Late = objApp_Late.GetType().InvokeMember( "Workbooks",
BindingFlags.GetProperty, null, objApp_Late, null );
//Add a new workbook.
objBook_Late = objBooks_Late.GetType().InvokeMember( "Add",
BindingFlags.InvokeMethod, null, objBooks_Late, null );
//Get the worksheets collection.
objSheets_Late = objBook_Late.GetType().InvokeMember( "Worksheets",
BindingFlags.GetProperty, null, objBook_Late, null );
//Get the first worksheet.
Parameters = new Object[1];
Parameters[0] = 1;
objSheet_Late = objSheets_Late.GetType().InvokeMember( "Item",
BindingFlags.GetProperty, null, objSheets_Late, Parameters );
//Get a range object that contains cell A1.
Parameters = new Object[2];
Parameters[0] = "A1";
Parameters[1] = Missing.Value;
objRange_Late = objSheet_Late.GetType().InvokeMember( "Range",
BindingFlags.GetProperty, null, objSheet_Late, Parameters );
//Write "Hello, World!" in cell A1.
Parameters = new Object[1];
Parameters[0] = "Hello, World!";
objRange_Late.GetType().InvokeMember( "Value", BindingFlags.SetProperty,
null, objRange_Late, Parameters );
//Return control of Excel to the user.
Parameters = new Object[1];
Parameters[0] = true;
objApp_Late.GetType().InvokeMember( "Visible", BindingFlags.SetProperty,
null, objApp_Late, Parameters );
objApp_Late.GetType().InvokeMember( "UserControl", BindingFlags.SetProperty,
null, objApp_Late, Parameters );
Parameters = new Object[1];
Parameters[0] = "Test2.xls";
objBook_Late.GetType().InvokeMember( "SaveAs", BindingFlags.InvokeMethod, null, objBook_Late, Parameters );
Parameters = new Object[1];
Parameters[0] = "Test2.xls";
objBook_Late.GetType().InvokeMember( "Close", BindingFlags.InvokeMethod, null, objBook_Late, Parameters );
// Check if the array of "EXCEL" processes exists
if (aProcesses.Length > 0)
{
// The last excel process is the orphaned process which is killed
aProcesses[aProcesses.Length-1].Kill();
}
}
catch( Exception theException )
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat( errorMessage, theException.Message );
errorMessage = String.Concat( errorMessage, " Line: " );
errorMessage = String.Concat( errorMessage, theException.Source );
MessageBox.Show( errorMessage, "Error" );
}
Any clue
regards
sanjeev
|
|
|
|
|
When I xml serialize a file, I want all the empty node should not appear. e.g.
The below mentioned xml serialized file has empty region node.
<Application>
<Name>abc</Name>
<Region/>
<Application>
I want empty node should not appear in xml serialized file.
<Application>
<Name>abc</Name>
<Application>
I appreciate, if anyone has any solutions or suggestions to this, please share their knowledge.
Regards,
Shiby
|
|
|
|
|
|
g'day guys,
i am stuck on a small problem which is starting to frustrate me a little. I have written a small c# application which displays a list of files. When a user selects one or more of the files it gets the selected files sends the file UNC path as hyper links to the email. The program itself invokes outlook to generate the emails.
If I were to simply use the generic outlook email editor (i.e. not ms word), it works fine. I have included a fragment of my code at the bottom.
The problem arises when outlook is configured to use ms word as the default email editor. There is no link being displayed in the body of the email. So I decided to write the content of the HTMLBody to console. What I found was that the link i am inserting using the <a> </a> tags is sitting out side the <html> & </html> tags.
To totally contridict my findings, I reverted the outlook email editor to Outlook's own editor (ie. not using ms word). I examined the contents of oMailItem.HTMLBody via console. My reference file enclosed in the <a> </a> tags was sitting outside the <html></html> tags. But the email itself showed the file as hyperlinks. I dont understand why this is possible!!!!
My question is how do I insert the reference file link within the <html></html> tags of the email body in c#??? At this point I am completely stumped. Is there a solution that can suit either types of email editors in outlook ????
Any suggestions ????
thanks
<code>
private void createEmail(object sender, System.EventArgs e)
{
string PostingNotice ="";
string EmailBody="";
string sHtml="";
oApp = new Outlook.Application();
oNameSpace= oApp.GetNamespace("MAPI");
oNameSpace.Logon(null,null,false,true);
oOutlookFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.Display(false);
foreach (ListViewItem lvitem in listView3.Items)
{
int index = int.Parse(lvitem.Index.ToString());
string filename = selectedFileArrayList[index].ToString();
int lastindex = filename.LastIndexOf('\\');
string displayFilename = filename.Substring(lastindex+1, ((filename.Length) - (lastindex+1)));
//assume fileUNCPath as a string variable containing the UNC path of the file
sHtml = "<a href= "+"\""+fileUNCPath+"\">"+displayFilename+"</a>\n"+"<br>\n";
oMailItem.HTMLBody = sHtml + oMailItem.HTMLBody; //append file link to email body
}
oMailItem.Display(false);
}
</code>
|
|
|
|
|
You are prefixing the sHtml text before the oMailItem.HTMLBody which naturally lands up before the html part which includes ..
Try using
oMailItem.Body = sHtml;
oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
|
|
|
|
|
thanks for replying.. but i dont quite understand your suggestion. I did try it out but it didnt make any different. I dont understand why would you want to do this :
oMailItem.Body = sHtml;
The way I understand is that Body simply indicates the plain text. What if your email contains a signature and the signature has an image as well. then you are loosing this image.
Do you think you could explain it a bit more.
What I was thinking is that instead of sHtml being assigned to HTMLBody when the sHtml string is created. Instead keep appending hyperlinks to the sHtml. Once the FOR loop finishes then do the following:
oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
signature = oMailItem.HTMLBody; //extract signature
Console.WriteLine(signature);
oMailItem.Body="";
oMailItem.Body+=sHtml;
oMailItem.HTMLBody=oMailItem.Body+signature;
With the above i am still loosing the image in the signature.
|
|
|
|
|
//I have an array of panels
public Panel[] a = new Panel[10];
//During the creation of 10 panels i set the tag for each panel as below
int i = 0;
for (i = 0; i < 9; i++)
{
a[i] = new Panel();
a[i].Parent = a_Holder;
a[i].Tag = i;
a[i].Top = (i * 16);
a[i].Left = 10;
a[i].Height = 15;
a[i].Width = 250;
a[i].Click += delegate { abcd( a[i] ) };
}
//on clicking a panel the below method is called
public void abcd (object sender)
{
textbox1.text = convert.tostring(sender.tag);
}
I basically want to be able to click on a panel and have that panels tag come up in the textbox. The above example does not work and im sure im way of base, can anyone help?
Cheers
|
|
|
|
|
This code does not work because object does not have a tag property. First cast it to Panel ( which is what it will be ). Of course, you should replace your delegate with a proper OnClick handler ( I'm sure that's not the right syntax, don't you need an eventargs, and you sure have the syntax for adding an event handler all wrong. ).
'The above example does not work' is not very helpful - in future try telling us why. I doubt this would compile, so report the compiler errors. If it crashes, report which line crashes and what the exception is. Working that stuff out might actually help you to fix the problem yourself ( not that we mind helping, but surely you want to learn how to do it yourself ? )
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Sorry, i've only been using C# for about a week and i've still got a lot to teach myself. However your comments helped and it now makes a lot more sense to me
Thanks for your help!
|
|
|
|
|
<br />
textBox1.Text = Convert.ToString((int)((Panel)sender.Tag));<br />
|
|
|
|
|
Let see this case:
I need to show the aform, and write code
aform f = new aform(someparameter);
f.Show();
and in the form's code. I use "someparameter" to determine if I should still show the form or Close it.
(this is done automatically, in FormLoad, constructor... etc; without anymore interaction from user (like event))
How this can be done?
|
|
|
|
|
this.Close();
It's the wrong model though - you should work out if you want to show it before you do. Anyone looking at this code is right to assume the form will be shown.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
If at all, you want to do -
Override the constructor with parameters public Form3(string args)
{ if args=="dontshow!" this.Close() // and dispose the object and come out }
However, the best and easier way to handle is to do it before hand since you have the parameters in hand before!
|
|
|
|
|
Why do people keep answering questions by posting under someone elses answer ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote:
Why do people keep answering questions by posting under someone elses answer ?
I don't know why, but apparently you seems to be getting a couple of them.
<font=arial>Weiye Chen
Life is hard, yet we are made of flesh...
|
|
|
|
|
Thats because we had answered at the same time! believe from various locations. Take care, sorry for the trouble guys for this thread!
|
|
|
|
|
No, it's not. You clicked on Reply while looking at Christian's answer! Your post is 20 minutes later this his.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello,
I am trying to call c++ dll function from C#.
Could anybody help me?
Here is the C++ function declaration.
long WINAPI GetPredictValues (double& m_vo2Max, double& m_vo2_kg_max, double& m_o2PulseMax)
And this is my declaration in C#.
[DllImport("c:\\ProgramFiles\\VacuMed\\turboFit\\tf32mmf.dll",SetLastError=true)]
public static extern int GetPredictValues(out double vo2Max,out double vo2_kg_Max,out double o2PulseMax);
And I get an error on the line below.
double vo2max,vo2kgmax,o2Pulsemax;
GetPredictValues( out vo2max, out vo2kgmax,out o2Pulsemax);An unhandled exception of type 'System.NullReferenceException' occurred
Additional information: Object reference not set to an instance of an object
Thank you for any help.
Sincerely,
|
|
|
|
|
On what line does the exception occur? I don't think the exception message came up on the line that you posted...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'm sorry I had forgotten to write the line that the error message occur.
The message occur on the line below:
double vo2max,vo2kgmax,o2Pulsemax;
GetPredictValues( out vo2max, out vo2kgmax,out o2Pulsemax);
Thank you for your help
Hai
|
|
|
|
|
anyone know of a tool that can convert c/c++ header to c#, i need to
convert a massive struct which is about 150 lines that has nested
structs and unions.
heres a sample of the struct.
*note* chopped off bits and pieces in the middile.
struct R_OMNI_LINK_MESSAGE {
unsigned char MessageLength;
union {
unsigned char Data[255];
struct {
unsigned char MessageType;
union {
struct {
unsigned char ItemType8;
unsigned char ItemName8[16];
};
struct {
unsigned char TimeDateValidFlag;
unsigned char AreaSecurityMode[8]; // index 0-7
struct {
unsigned char BatteryReading;
} ExpansionEnclosure[8]; // index 0-7
};
struct /* olmMESSAGE_STATUS */ {
unsigned char Data;
} MessageStatus[33];
struct {
unsigned char AreaNumber; // (1-8)
};
struct {
unsigned char UserCodeNumber;
};
}; // union
}; // struct
}; // union
};
Kids don't try this at home!
|
|
|
|
|
There are no unions in C#.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
ok, how do i convert that to c#?
Kids don't try this at home!
|
|
|
|
|
I'm not sure that you can, in a way I'd consider production safe. Why do you need to ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
doesnt matter if its safe or not...i just need it to work with c#, i have it partially converted but its giving me errors about [FieldOffset()] collisions and marshalling errors.
i need to convert this to c# so i can communicate with a piece of hardware, since i dont know enough c++, c# is the only way to go ;(
Kids don't try this at home!
|
|
|
|
|