|
Hi,
I have several excel file with the same design, but with different content. The files are containing two sheets. Now I want to import from each file the first sheet en put al the sheets into one new excel file. What is the most easy way to do this. Are there any sheet objects in c#.
Regards,
Omy
|
|
|
|
|
Hi,
Do you have Visual Studio 2008 professional edition?
In code project there are some articles with classes to edit MS excel more easyer.
Good Luck
|
|
|
|
|
I 've got VS 2005. I am looking for a code snippet wich can load an compleet active sheet from a excelfile to an another excelfile.
|
|
|
|
|
I have a method which takes a DataRow as an out argument. The method fills out the DataRow with data, and returns it.
So,
public CreateTheFancyTable()
{
DataTable dt = new DataTable();
DataColumn dc1 = new DataColumn("First_Column", System.Int32);
DataColumn dc2 = new DataColumn("Second_Column", System.String);
dc1.AllowDBNull = false;
dc2.AlllowDBNull = false;
DataRow dr = dt.NewRow();
bool fSucceeded = FillOutMyRow(dr);
}
public bool FillOutMyRow(DataRow dr)
{
dr["First_Column"] = 1;
dr["Second_Column"] = "";
}
Please don't focus on the bugs in my quick sample here, the real code is a lot more complex than this.
Now, the last line is going to fail, because dt.Columns[dc2].AllowDBNull is false.
How, in the code of FillOutMyRow(), can I find out the properties of the columns in the row that was passed to me? I only know how to get the column properties of a table, and I don't have the table.
Can I refer directly to the column properties of a row (and if so, how?)? Or do I need to get the parent container of the row (the table), and if so, how?
Thanks,
Joe
|
|
|
|
|
DataRow has a Table property.
|
|
|
|
|
Thanks for the help. Of course, I figured that out about 5 seconds after clicking "Post"
I always assume the more complex answer first (I was starting to research "parent containers" when I noticed Table sitting there...)
|
|
|
|
|
JoeRip wrote: Now, the last line is going to fail, because dt.Columns[dc2].AllowDBNull is false.
No it wont, you're setting the value to an empty string not DbNull.Value.
Anyway, you should be able to go back to the table/columns from the datarow.
dr.Table.Columns
so you could do if(dr.Table.Columns["Second_Column"].AllowDBNull) { ... }
|
|
|
|
|
Meanwhile, I'm stuck on the fact that I can't test the passed in DataRow to see if it's null or not..
given
public bool FillOutMyRow(out DataRow dr)
{
if (dr == null)
{
return false;
}
dr["first_column"] = 1;
return true;
}
The compiler is complaining: "use of unassigned parameter dr"
What's the problem here?
|
|
|
|
|
|
Do you actually need ref? DataRow being a class isnt it passed in by reference in any case?
|
|
|
|
|
Why have you changed the param to an out? That wasn't there in your original post!
|
|
|
|
|
That's true, it wasn't. My original post was a quick and dirty bit done from memory, and therefore incomplete.
Are you saying that ref or out is not required here at all? I can pass a DataRow and modify it to my heart's content?
I did test out "ref" when "out" failed, and that does work. Still not sure why "out" doesn't work in the "if (dr == null) case, but it's not clear to me what "unassigned" means here when the caller has already assigned a value to the variable...
|
|
|
|
|
the ref keyword forces the argument to be passed by reference, it has no effect on reference types such as DataRow, but consider the following example with a value type:
static void Main()
{
int i = 1;
NoRef(i);
Console.WriteLine(i);
WithRef(ref i);
Console.WriteLine(i);
}
static void NoRef(int i)
{
i = i +1;
}
static void WithRef(ref int i)
{
i = i + 1;
}
as for the out keyword, this means that the method itself has to set the value of the param before using it. Hence why you cant check it for null before initializing it to some value.
static void Main()
{
int i = 0;
SetOut(out i);
Console.WriteLine(i);
}
static vouid SetOut(out int i)
{
i = 1;
}
So to cut a long story short, just remove the out/ref keyword altogether from your method. You can still change the values of your DataRow within your method.
|
|
|
|
|
Hello,
I want to develop small application for Desktop Sharing if you provide me any example or any link will be good for me.
Thanks
Best Regards,
Chetan Patel
|
|
|
|
|
Look at the source code of VNC, I am sure that will scare you off, as this is no small feat.
|
|
|
|
|
i planning to create a web base vb script editor by c#
but i have no idea about this....
have any suggestion how to create it??
can i apply msscript.ocx for this editor?
|
|
|
|
|
how to insert float value from string into sql from C# .net in float column in database. It should accept only the given decimal point.
Ashok
|
|
|
|
|
Hello Ashok,
If I get it correctly, you wish to retrieve a value from a string variable
containing a floating value. If thats the case, you can try this.
String str = "123.32";
float f = float.Parse(str);
I hope this helps.
Regards,
Allen
Allen Smith
ComponentOne LLC
www.componentone.com
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace TestApplication
{
public partial class Form1 : Form
{
progress prg = new progress();// this is a form
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(loop));
t.Start();
}
public void loop()
{
showProgress();
for (long i = 0; i < 500000000; i++)
{
}
this.BeginInvoke(new MethodInvoker(showC));
}
public void showProgress()
{
//if (this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(showP));
}
}
public void showP()
{
prg.ShowDialog();
}
public void showC()
{
prg.Close();
}
}
}
|
|
|
|
|
You need to show the progress window until the "Loop" finishes, right ? Then your code is wrong. prg.ShowDialog() in the "Loop" method blocks the current thread, which means your loop won't get executed until the progress closes.
Show the progress from the main thread and execute the "Loop" method in the thread which you created. Something like
private void button1_Click(object sender, EventArgs e) {
progress prg = new progress();
Thread t = new Thread(new ParameterizedThreadStart(loop));
t.Start(prg);
prg.ShowDialog();
}
delegate void ProgressCloseInvoker(progress prg);
public void loop(object obj) {
progress prg = obj as progress;
for (long i = 0; i < 500000000; i++) {
}
this.BeginInvoke(new ProgressCloseInvoker(CloseProgress), prg);
}
public void CloseProgress(progress prg) {
prg.Close();
}
|
|
|
|
|
N a v a n e e t h wrote: prg.ShowDialog() in the "Loop" method blocks the current thread, which means your loop won't get executed until the progress closes.
Not really, the OP is using BeginInvoke, which pushes the delegate to the UI thread and returns immediately.
|
|
|
|
|
S. Senthil Kumar wrote: the OP is using BeginInvoke
Ohh I didn't noticed that. Thanks for pointing it
|
|
|
|
|
Senthil, i have read you article and then implemented this program
http://www.codeproject.com/KB/cpp/begininvoke.aspx[^]
But what does the exactly invokerequired() do does it checks whether message is posted in message queue if it is posted then it returns true or false.
Clear me
|
|
|
|
|
I didn't noticed BeginInvoke on your sample, your code is correct then. As you are showing the progress as modal, there is no chance of clicking the button for one more thread to create. So there won't be any thread safety issues, AFAIK.
|
|
|
|
|
Senthil, i have read you article and then implemented this program
http://www.codeproject.com/KB/cpp/begininvoke.aspx[^]
But what does the exactly invokerequired() do does it checks whether message is posted in message queue if it is posted then it returns true or false.
Clear me
modified on Monday, July 21, 2008 3:57 AM
|
|
|
|