473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 10521
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to...
3
by: Jorge Cavalheiro | last post by:
Hello After reading yesterday's thread on performance of C# and vb.net i've just turn it on my solution and spent 2 hours correcting the errors :) I have a problem i don't how to fix i have a...
4
by: msnnews.msn.com | last post by:
hi there, i've got a form that populates a datagrid, and a button that calls a function to export to an excel file. All is well with the export, no errors are returned, but the Excel instance...
2
by: Bas | last post by:
I',m trying to delete a named worksheet - what's wrong with this?? xlApp = New Excel.Application() Dim xWorkbook As Excel.Workbook Dim PageSht As Excel.Worksheet xWorkbook =...
4
by: B.N.Prabhu | last post by:
How to delete first row from an Excel Sheet using C#.Net. Please Help. Its very urgent.
3
by: Rene | last post by:
Hi Proggies, i try to delete an excel worksheet but nothing happens (work on vb.net 2005) ..... xlSheet = xlApp.Sheets("Master") xlSheet.select xlSheet.delete also try
13
by: Shelley | last post by:
Compare Current Year Worksheet with Previous Year Worksheet and if SSN exists in Current Year Worksheet & Not in Previous Year - Copy this Row from Current Year Worksheet & Paste into Previous Year...
1
by: SteveBark | last post by:
Hello all I am currently trying to develop a script that will take a value from an Excel spreadsheet cell and use that to run a query against an Access table to delete all rows that match the...
2
by: Bxitty | last post by:
Hello all, I am trying the below code to delete a worksheet using VB.NET..I amgeeting an error with the delete...any idea where this could be wrong.. Dim str_path As String Dim...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.