|
Hey all. I have been fooling around with Excel and can create Worksheets, files, etc, however, when I try to modify the contents of a cell, I get the following exception:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Exception from HRESULT: 0x800A03EC.
The code is:
Excel.Application excel = new Excel.ApplicationClass();
Excel.Workbook workbook = null;
Excel.Sheets sheets = null;
Excel.Worksheet currentSheet = null;
workbook = excel.Workbooks.Add( Excel.XlWBATemplate.xlWBATWorksheet );
sheets = workbook.Worksheets;
currentSheet = (Excel.Worksheet)sheets[ 1 ];
((Excel.Range)currentSheet.Cells[ 0, 0 ]).Value2 = "text";
I have researched this on the net but to no avail. My code seemed to have worked before, but it doesn't now and it's ticking me off. I have tried several variations to modify the contents of the cell, but nada.
Any help would be greatly appreciated!
Thanks,
Josh
|
|
|
|
|
Hi,
((Excel.Range)currentSheet.Cells[ 0, 0 ]).Value2 = "text";
cell[0,0] is an readonly cell , you cant modify value in it.
use ((Excel.Range)currentSheet.Cells[ 1, 1 ]).Value2 = "text";
hope this works.
Nitin...
|
|
|
|
|
Thanks for the response. Interesting that you can't modify 0,0. Perhaps they should mention that somewhere. Anyway, I tried using different Cell coords, however, no data appeared, but I am not that concerned since I didn't receive an error.
I ended up using this to modify cell contents:
Excel.Range r = currentSheet.get_Range( "C1", Type.Missing );
r.Value2 = "Some Text";
r = currentSheet.get_Range( "D1", Type.Missing );
r.Value2 = "Some Text";
This seems to work fine.
Thanks!
|
|
|
|
|
Hi,
can anyone offer some opinions on the best method for creating a wizard style form. To clarify, I mean having Back/Next buttons in the bottom right, and displaying different options and information as you progress.
In VB6, you could do that array thing with controls, which wasnt so bad. But what about in .Net?
The solution Im thinking of at the moment is, having several panels, and just hiding them, and moving off screen at runtime. So when a user clicks Next, the current panel is turned invisible, moved to maybe -10000, 0 location. The next panel would then be made visible and moved to 0,0 location. But its just soooooo clunky.
Is there something easier? For instance, is it possible to use a tabcontrol, but hide the tab markers at the top for example? And then just manipulate which tabpage is selected?
What is the preferred method of doing this? Or other ways?
Any response gratefully appreciated.
Mark
|
|
|
|
|
Hello
I go for the hide/show pattern, but why moving your panels to extreme locations?!! Make all your panels in the designer beside each other -just for designing-, then you got to options:
1- If you are sure that you finished designing all your panels pile them up on top of each other and resize your form to a "fit all" size.
2- If you still want to make adjustments to your panels, keep them apart, and then in your forms constructor move all the panels to Location(0,0) programatically, and resize your form to the "fit all" size.
Now the last line of your constructor would be hide all except first. When the Next/Back buttons are clicked Hide/Show panels accordingly.
About the TabControls you can do that is you make your custom control. Inherit it from the TabControl, and in your custom draw event, don't draw the tab headers. I still prefer the above method.
One more less graceful way is to make a form for each step. It would make your life with the designer easier, but I strongly don't recommend it due to poor performance and memory wasting.
Regards
|
|
|
|
|
The way that I create Wizards in my applications is to put a "placeholder" panel at the location that I want all of the wizard pages to appear. Then I "supersize" my form so that I can place each of the individual wizard pages (also panels) side by side at the bottom. At run-time, I add the template page and each of the wizard pages to an ArrayList, make them invisible and resize the form back down to the appropriate size. Create your Back, Next, Finish, and Cancel buttons and in each of the click event handlers, I manipulate an index (simple int.)
On a Next click:
if(wizardPageIndex < (WizardPages.Count-1)
{
wizardPageIndex++;
btnBack.Enabled = true;
if(wizardPageIndex == WizardPages.Count-1)
{
btnNext.Visible = false;
btnFinish.Visible = true;
}
else
{
btnBack.Enabled = true;
btnBack.Visible = true;
}
DisplayWizardPage(wizardPageIndex);
}
...do something similar for the back click. (It's simply reverse logic of the Next click) ...Easiest way to get it done without creating a custom control. I've been planning on making one for a while, but this way has worked well for every application I've needed a Wizard for,so there's been no need to.
|
|
|
|
|
Hello Alaric_
Would you kindly repost this answer to the guy who asked the question instead of me.
Regards
|
|
|
|
|
This is not the most elegant way -- but cheaper than buying a wizard control:
Create a form and make sure the border style is fixed.
Add a tabbed control and create as many tabs as you need pages.
Subscribe to the tab index change event.
Add buttons to a panel positioned below the tabbed control.
Add a panel above the tabbed control and stretch it down to hide the tabs.
As the next button is clicked determine which tab index to move to based on the current tab index.
|
|
|
|
|
hi everyone,
i want to populate a treeview from an xml message i'm sending or i recieved. now i want that xml message (all the elements and attributes in that element) to be displayed in a tree view. the problem is, if the element has alot of attributes, not all of the attributes will be displayed. is there any way for me to display all the attributes? i tried adding levels for each attribute of an element but i'm not getting the right order. any advice, sample code , or anything...i'll really appreciate it. thanks.
|
|
|
|
|
Hey guys,
Suppose you have a textbox and you have "Hello World" inside it. How do I parse this string so that I can add each word into a text file (sort of like creating a dictionary)? Also, how can I keep adding or appending words to the file without deleting the previous words there? Do I just not close the streamreader/streamwriter? I'm confused about that... so any answer will do... thanks a lot I appreciate it.
Roberto
|
|
|
|
|
You can open a file in append mode, so stuff gets added to the end and the file not overwritten.
You can remove the .'s from a string and then use the Split method to turn a string into an array of words ( split on a space ).
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
To avoid duplicates you'll need to load your file into a dictionary.
Then when the event to save comes time use:
string[] words = textBox1.Text.Split(' ');
Then take each word in the array and add it to the dictionary.
Finally you persist by just feeding your stream with the dictionary values.
|
|
|
|
|
Hi,
I have very peculiar problem regarding GZipStream class under System.IO.Compresion namespace.
The problem is like this:
I have an ArrayList with large amount of data. I want to serialize it after compressing it. I used the following algorithm:
1. Create a MemoryStream
2. Serialize the ArrayList into that stream.
3. Compress the memorystream
4. Write the compressed stream into a file.
this runs ok without any error. but problems occur when I want to deserialize it after decompression as follows:
1. Create a file stream from the file.
2. Decompress it into a memorystream
3. Deserialize the stream into an ArrayList
exception is thrown here, it say somesort of like this: Binary header broken cannot deserialize from the stream. This is a peculiar problem, the compression process is not reversible! I don't know how to get rid of this problem. Anyone please help me.
Thank's in advance.......
With regards,
Anindya Chatterjee
|
|
|
|
|
hi
i have CrystalReports XI and VS2005.
i want to print my form with CrystalReports .. but i don't know how to do .. Please help me !!
thanks ..
|
|
|
|
|
Good day
Im having a problem passing an object from one form to another. Im trying to achieve this by passing it through another form's constructor. It does not give me any errors but the form im passing the object to doesnt show anything. all my controls disappear, it's like a new created form.
Am i doing this the wrong way and which is the right way to do it.
Thank you in advance
Kulile --- RSA
|
|
|
|
|
kulile wrote:
Im having a problem passing an object from one form to another. Im trying to achieve this by passing it through another form's constructor. It does not give me any errors but the form im passing the object to doesnt show anything. all my controls disappear, it's like a new created form.
Am i doing this the wrong way and which is the right way to do it.
Without seeing your code, it is hard to spot what you are doing wrong. Have a read of
this article[^] which shows the best ways of passing information from one form to another.
|
|
|
|
|
Thanks Michael. I found what the problem was. I was doing everything right except that in my new constructor, I didn't call the InitializeComponent(); method. that was the problem.
Thanks again
Kulile --- RSA
|
|
|
|
|
Hello,
I want to create control(s) that would act like MS office 2007, so that when you press ALT key all controls that have hotkey will be repainted with hotkey drawn on itself.
I dont want to use KeyDown, KeyPress, KeyUp events.
Could it be all done trought some kind of extending of controls or so ?
overriding WndProc or so ?
Thanks.
|
|
|
|
|
You could override the control classes, or you could use CreateGraphics to draw your keys direct to the screen, then call Invalidate in the key up, so the form gets repainted.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Chris,
Yes I want to paint them on control but how to handle pressing of ALT+KEY ?
I dont want to use KeyPress, KeyDown events?
|
|
|
|
|
Vertyg0 wrote: I dont want to use KeyPress, KeyDown events?
Why on earth not ?
You can use a WndProc to catch these events earlier, but you really have no option but to use them, you want to catch when a key is down, and when it's raised again.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello
You can set a property called KeyPreview to true in your form itself. Then handle KeyDown event in the Form level. It will catch any KeyDown events in any control in that form before it is sent to that control.
Regards
|
|
|
|
|
Try adding & in front of the letter that will be the hot key
Do your best to be the best
|
|
|
|
|
Hello. I am developing some classes that access SQL and Oracle databases.
These classes are to be used by different applications, (windows and web applications).
Thus, I need to put the database connection strings on a global location so that all applications see them (this way if I need to do changes to a connection string all applications are affected).
I found that machine.config might be a proper location to do that, under the <connectionstrings> section.
- Is machine.config a good solution for global connection strings?
- If so, how can I access the <connectionstrings> section in my code?
Thanks.
|
|
|
|
|