简体   繁体   中英

classic asp delete rows and columns from an excel file

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM