...

View Full Version : deleting a row in excel worksheet using Javascript ActiveX Excel Object



accetdinesh
05-26-2009, 02:31 PM
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

mic2100
05-27-2009, 12:06 AM
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 :)



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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum