473,385 Members | 1,908 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,385 software developers and data experts.

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

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 2516
tlhintoq
3,525 Expert 2GB
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 Expert 2GB
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
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...
0
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...
13
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...
2
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...
5
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...
2
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");...
1
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...
0
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...
5
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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...
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...

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.