Problem with Delete worksheet

  • Thread starter Thread starter sun919 via DotNetMonster.com
  • Start date Start date
S

sun919 via DotNetMonster.com

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
 
C# does not compare string using ==. Use String.Compare function instead.

chanmm
 
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
 
sorry it work now apparently i did not exit the excel application ...
thanks u all
sun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top