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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harichinna
    New Member
    • Dec 2009
    • 1

    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

    Code:
    Microsoft.Office.Interop.Excel.Application ObjExcel = new Microsoft.Office.Interop.Excel.Application();
                Microsoft.Office.Interop.Excel.Workbook ObjWorkBook=null;            
                String s = "ValueToCompare";
                try
                {
                  Microsoft.Office.Interop.Excel.Worksheet ObjWorkSheet;
                  Microsoft.Office.Interop.Excel.Worksheet ObjWork;
                  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);
                   
                    int workbookCount = ObjWorkBook.Worksheets.Count;                
                    for (int r = 0; r <= workbookCount - 1; r++)
                    {
     ObjWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)ObjWorkBook.Worksheets[r + 1];
                     //   rng = ObjWorkSheet.get_Range("L1", "L1");
                        string str = (ObjWorkSheet.Cells[13, 13]);                   
                            ObjWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)ObjWorkBook.Worksheets[r + 1];
                            if (s == str)
                            {
                                ObjWorkSheet.get_Range("L1", "L1").EntireColumn.Delete(13);
                            }
    
    if (File.Exists("D:/New Folder/WatiNSample.xls"))
                            {
                                //File.Delete("D:/New Folder/WatiNSample.xls");
                            }
                            // ObjExcel.Quit();
                        }
                    }           
                catch (FileNotFoundException e)
                {
                    Console.WriteLine(e.Message);
                }
                finally
                {
                    if (ObjWorkBook != null)
                    {
                        ObjWorkBook.Save();                   ObjWorkBook.Close(Microsoft.Office.Interop.Excel.XlSaveAction.xlSaveChanges, Type.Missing, Type.Missing);
                    }
                    ObjExcel = null;
       }
    }
    thanx

    Hari.
    Last edited by tlhintoq; Dec 28 '09, 04:37 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    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.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      when comparing it showing some errors,
      Help us to help you... where are you getting the errors (what line #)... and what are the errors?

      Comment

      Working...