473,695 Members | 1,993 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 10543
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
3366
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
1689
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 'Excel.Worksheet' and Option Strict On disallows late
4
2515
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 below:
2
3701
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 deleted
4
30141
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
15276
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
6954
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 - Delete this Row out of Previous Year Worksheet - THIS IS WHERE I'M HAVING TROUBLE. This is the...
1
2343
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 that I thought it would return all of the records matched, however it just deletes the 1 row not all of...
2
2212
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 Excel.Application
0
8586
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9004
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8864
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8838
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7685
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5843
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4351
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2290
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.