views:

219

answers:

1

Hi, how can I remove specific rows and columns from an excel file using only classic ASP? For example, given the excel file

col1  col2  col3
one   two   three
four  five  six

I want to be able to programmatically delete the first row and second column to produce

one   three
four  six

Thanks!

+1  A: 

You can try using an Excel.Application object. For example:

dim oExcel, oWkBk  
set oExcel = CreateObject( "Excel.Application" )
oExcel.Visible = false
oExcel.DisplayAlerts = false
set oWkBk = oExcel.WorkBooks.Open( "C:\path\file.xls" )

You can then delete any individual cells with:

oExcel.Cells( 1, 1 ).Delete

Or entire rows/columns with:

oExcel.Cells(1,1).EntireColumn.Delete
oExcel.Cells(1,1).EntireRow.Delete

To check if a cell is empty use:

if isEmpty(oExcel.Cells(1,1)) then ...

Finally, cleanup:

oWkBk.Close()
oExcel.Quit()
set oWkBk = nothing
set oExcel = nothing

For more info, try Googling things like "excel application object vbscript." You can find many examples. Unfortunately, I've found it impossible to find a complete reference.

dmb
Thanks! I'll give this a shot and hopefully it'll work for what I'm doing.I knew about the Excel.Application object, but too bad there's no complete reference online.Thanks again.
rdm
Unfortunately I was having permission problems creating Excel.Application...and then I found out our server doesn't have Excel! Anyway, thanks for the help...I'll have to use a workaround in the context of the larger problem.
rdm
Yeah, I've actually got the same problem--but have been avoiding addressing it. If you find a way to avoid an Excel install on each server, I'd love to hear about it!
dmb