Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question deleting a row in excel worksheet using Javascript ActiveX Excel Object

    Hi,
    Im opening an excel worksheet and adding data to it using Javascript ActiveX Excel Object as below

    var Excel,Book;
    Excel = new ActiveXObject("Excel.Application");
    Book = Excel.Workbooks.Open("c:/example.xls");
    var excel_sheet = Book.Worksheets("Sheet1");
    Excel.Visible = false;
    var i=1;
    while(excel_addsheet.Cells(i,1).Value!=null)
    {
    excel_addsheet.Cells(i,1).Value = i;
    excel_addsheet.Cells(i,2).Value = "text1"
    excel_addsheet.Cells(i,3).Value = "text2"
    excel_addsheet.Cells(i,4).Value = "text3"
    i++;
    }
    Book.Save;
    Application.Excel.Quit();

    In the above code the column A in excel worksheet will have a unique value.
    I need to delete the entire row matching the value in column A and shift the
    rest of the rows up using this Javascript ActiveX Excel Object.

    Please help me with the solution

  • #2
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    hi,

    i was reading through how to use the activex excel controller after seeing your post. It could be very useful for some projects im working on

    Code:
    var ExcelApp = new ActiveXObject("Excel.Application");
    var ExcelSheet = ExcelApp.Workbooks.Open("C:\\example.xls");
    ExcelSheet.Application.Visible = true;
    
    //i just replaced ur while loop with a for loop for testing
    for(var i = 1; i < 10; i++)
    {
    	ExcelSheet.ActiveSheet.Cells(i,1).Value = i;
    	ExcelSheet.ActiveSheet.Cells(i,2).Value = "text1";
    	ExcelSheet.ActiveSheet.Cells(i,3).Value = "text2";
    	ExcelSheet.ActiveSheet.Cells(i,4).Value = "text3";
    }
    
    ExcelSheet.Save;
    ExcelSheet.Application.Quit();
    this should now work as expected


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •