简体   繁体   English

经典的ASP从Excel文件中删除行和列

[英]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? 如何仅使用经典ASP从excel文件中删除特定的行和列? For example, given the excel file 例如,给定excel文件

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. 您可以尝试使用Excel.Application对象。 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." 有关更多信息,请尝试使用Google搜索功能,例如“ excel应用程序对象vbscript”。 You can find many examples. 您可以找到许多示例。 Unfortunately, I've found it impossible to find a complete reference. 不幸的是,我发现找不到完整的参考资料。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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