473,587 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the column value and compare it in spread sheet using c sharp

1 New Member
Hi to all,

My name is hari, iam trying to delete the column value of spread sheet using c sharp,
iam trying to get the value and compare, when comparing it showing some errors, can any one help me, to slove this issue
i pasted code below

Expand|Select|Wrap|Line Numbers
  1. Microsoft.Office.Interop.Excel.Application ObjExcel = new Microsoft.Office.Interop.Excel.Application();
  2.             Microsoft.Office.Interop.Excel.Workbook ObjWorkBook=null;            
  3.             String s = "ValueToCompare";
  4.             try
  5.             {
  6.               Microsoft.Office.Interop.Excel.Worksheet ObjWorkSheet;
  7.               Microsoft.Office.Interop.Excel.Worksheet ObjWork;
  8.               ObjWorkBook = ObjExcel.Workbooks.Open("D:/New Folder/WatiNSample.xls", 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);
  9.  
  10.                 int workbookCount = ObjWorkBook.Worksheets.Count;                
  11.                 for (int r = 0; r <= workbookCount - 1; r++)
  12.                 {
  13.  ObjWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)ObjWorkBook.Worksheets[r + 1];
  14.                  //   rng = ObjWorkSheet.get_Range("L1", "L1");
  15.                     string str = (ObjWorkSheet.Cells[13, 13]);                   
  16.                         ObjWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)ObjWorkBook.Worksheets[r + 1];
  17.                         if (s == str)
  18.                         {
  19.                             ObjWorkSheet.get_Range("L1", "L1").EntireColumn.Delete(13);
  20.                         }
  21.  
  22. if (File.Exists("D:/New Folder/WatiNSample.xls"))
  23.                         {
  24.                             //File.Delete("D:/New Folder/WatiNSample.xls");
  25.                         }
  26.                         // ObjExcel.Quit();
  27.                     }
  28.                 }           
  29.             catch (FileNotFoundException e)
  30.             {
  31.                 Console.WriteLine(e.Message);
  32.             }
  33.             finally
  34.             {
  35.                 if (ObjWorkBook != null)
  36.                 {
  37.                     ObjWorkBook.Save();                   ObjWorkBook.Close(Microsoft.Office.Interop.Excel.XlSaveAction.xlSaveChanges, Type.Missing, Type.Missing);
  38.                 }
  39.                 ObjExcel = null;
  40.    }
  41. }
thanx

Hari.
Dec 28 '09 #1
2 2525
tlhintoq
3,525 Recognized Expert Specialist
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Dec 28 '09 #2
tlhintoq
3,525 Recognized Expert Specialist
when comparing it showing some errors,
Help us to help you... where are you getting the errors (what line #)... and what are the errors?
Dec 28 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

19
25445
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to sort columns based on the column header the user has clicked in both Ascending and Descending formats.
0
1184
by: WStoreyII | last post by:
Hello, I was wondering if there was a way to open a spread sheet up in a windows mdi form. I have tried the spreadsheet control but that does not work because i wish to open up an exisiting spread sheet that i have. How Can this be done? WStoreyII
13
8594
by: UnaCoder | last post by:
Hi, I'm trying to use client side JavaScript from an HTML file to open and make changes to an Excel SpreadSheet using ADO w/ ODBC. What a pain it is to do this. Anyways, I am able to open the excel file but I don't know how to use ADO to work with it's contents. So far I have the following code that works: <html> <script>...
2
2227
by: RICHARD BROMBERG | last post by:
I wrote a small Access application that accepts a City Name and a Street Name and runs a Query based on them . I want to create an Excel Spread sheet that contains all the matches found by the Query. . Does anyone know how to do this . On a quick and dirty basis I was able to "cut and paste" the query results into an Excel Spread...
5
3181
by: stuart79 | last post by:
I am looking for a code that enables me to open another excel spread sheet while i am in my XL form i have this code - Workbooks.Open Filename:= "OtherFilename.xls" - which opens up the XL spread sheet that i need however my form sits ontop of the xl spread sheet and i am unable to do anything to the spread sheet in the back ground. I need a...
2
2672
by: glibo | last post by:
I am trying to change the tab name when i open a excell spread sheet on the run time in c#. I changed it in the code: Response.AddHeader("content-disposition","filename=" + sFileName + ".xls"); But it works only on save mode but on the display mode still display the name of the page i am calling this excell spread sheet, in other words i see...
1
3942
by: pvenu | last post by:
Hi, I know basic perl (regular expressions, pattern matching, string manipulation, reading writing into text files). Yet, my requirement is to read an input text file -> process this input file through a Perl script and the output generated from this script is to be written into an Excel sheet file (into each cells of the sheet). Can you...
0
1010
by: Manikandan | last post by:
Hi, I'm using office web components11 for my c# application. I'm creating a excel spread sheet with data's programmatically. I have written codes for double click event handler. if the data in cell is in edit mode means(whole data selected while doubleclicking sometimes), double click event handler won't work. I tried the properties like...
5
2441
by: cdavii | last post by:
Anyone have an idea why i get null values when i import data from a ms spread sheet in a sql tbl. The table elemet(Spread sheet) in question contains alpha numerics. The sql table is populated with "NULL" when the value is numeric only. Example: A-ASP21A1-- imports perfect 6500012111-- results in "NULL" in the sql...
0
7920
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
7849
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
8215
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. ...
0
8347
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...
1
7973
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...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5394
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
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.