472,145 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

Problem with Delete worksheet

hi ,
i have a question to ask regarding deleting the worksheet
basically i have written code which find the select worksheet which work fine
but it didn't delete the worksheet from the workbook and i dont know what i
did wrong. Here is my coding

book = app.Workbooks.Open(dir, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.
Missing, Type.Missing, Type.Missing, Type.Missing);

//create new worksheet since current workbook only have one worksheet
sheet = (Excel.Worksheet)book.Worksheets.Add(Type.Missing, Type.Missing, Type.
Missing, Type.Missing);

foreach (Excel.Worksheet work in book.Worksheets)
{
if (work.Name.ToString() == sheetN)
{
work.Delete();
//delete worksheet
}
}
book.Save();
And when i run the function the worksheet is still not deleted, please help
many thanks
sun

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200611/1

Nov 14 '06 #1
3 10437
C# does not compare string using ==. Use String.Compare function instead.

chanmm

"sun919 via DotNetMonster.com" <u23205@uwewrote in message
news:69430fe3eecf7@uwe...
hi ,
i have a question to ask regarding deleting the worksheet
basically i have written code which find the select worksheet which work
fine
but it didn't delete the worksheet from the workbook and i dont know what
i
did wrong. Here is my coding

book = app.Workbooks.Open(dir, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.
Missing, Type.Missing, Type.Missing, Type.Missing);

//create new worksheet since current workbook only have one worksheet
sheet = (Excel.Worksheet)book.Worksheets.Add(Type.Missing, Type.Missing,
Type.
Missing, Type.Missing);

foreach (Excel.Worksheet work in book.Worksheets)
{
if (work.Name.ToString() == sheetN)
{
work.Delete();
//delete worksheet
}
}
book.Save();
And when i run the function the worksheet is still not deleted, please
help
many thanks
sun

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200611/1

Nov 14 '06 #2
Hi,

chanmm wrote:
C# does not compare string using ==. Use String.Compare function instead.

chanmm
Very confused about what you mean with that.

string a = "1234";
string b = "1234";
string c = "2345";
bool test;

test = ( a == b ); // test is true
test = ( a == c ); // test is false

So you can definitely compare strings using '=='. It might be a bit
confusing, because unlike other objects (but like value types), '==' for
strings compares the string's value, not the identity.

String.Compare can be used in Sorting algorithms, for example, because
it returns -1, 0 or 1 depending on the strings' alphabetical sorting order.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Nov 14 '06 #3
sorry it work now apparently i did not exit the excel application ...
thanks u all
sun

Laurent Bugnion wrote:
>Hi,
>C# does not compare string using ==. Use String.Compare function instead.

chanmm

Very confused about what you mean with that.

string a = "1234";
string b = "1234";
string c = "2345";
bool test;

test = ( a == b ); // test is true
test = ( a == c ); // test is false

So you can definitely compare strings using '=='. It might be a bit
confusing, because unlike other objects (but like value types), '==' for
strings compares the string's value, not the identity.

String.Compare can be used in Sorting algorithms, for example, because
it returns -1, 0 or 1 depending on the strings' alphabetical sorting order.

HTH,
Laurent
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...sharp/200611/1

Nov 16 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jorge Cavalheiro | last post: by
4 posts views Thread by msnnews.msn.com | last post: by
2 posts views Thread by Bas | last post: by
2 posts views Thread by Bxitty | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.