473,549 Members | 2,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.O pen(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.Workshee t)book.Workshee ts.Add(Type.Mis sing, Type.Missing, Type.
Missing, Type.Missing);

foreach (Excel.Workshee t work in book.Worksheets )
{
if (work.Name.ToSt ring() == 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.c om
http://www.dotnetmonster.com/Uwe/For...sharp/200611/1

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

chanmm

"sun919 via DotNetMonster.c om" <u23205@uwewrot e in message
news:69430fe3ee cf7@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.O pen(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.Workshee t)book.Workshee ts.Add(Type.Mis sing, Type.Missing,
Type.
Missing, Type.Missing);

foreach (Excel.Workshee t work in book.Worksheets )
{
if (work.Name.ToSt ring() == 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.c om
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.Compa re 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.c om
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
3355
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 process this .txt file. Goal: I am working on a vba script to:
3
1681
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 class that export data to a Excel Workbook. I get 2 types of errors : Option Strict On disallows implicit conversions from 'System.Object' to...
4
2503
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 doesnt want to terminate properly even when i set excelApp.Quit, and excelApp = nothing. has anyone else experienced a problem like this??? code...
2
3695
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 = xlApp.Workbooks.Open("Test.xls") Dim pageWkSht As Excel.Worksheet pageSht = xWorkbook.Sheets("Page") pageSht.Delete() No error is generated and the sheet is NOT...
4
30131
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
15268
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
6935
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 Worksheet Compare Previous Year Worksheet with Current Year Worksheet and if SSN exists in Previous Year Worksheet & Not in Current Year Worksheet -...
1
2331
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 cell. I have tried to do this by first using a recordset and then secondly using a db.Execute (sqlstring). The idea of using the recordset was...
2
2208
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 str_name As String str_path = "C:\Biju\SSIS\Reports\0000215574.xls" str_name = "Loss_Related" Dim appExcel As...
0
7518
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7715
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7469
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7808
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.