How to delete rows in an excel file
12 views (last 30 days)
Show older comments
I am working on a project where I have loaded a large amount of data from an excel file and I have unnecessary information that needs to be deleted. I have already found the information which needs to be deleted but I am having trouble coming up with the code to delete the rows which contain that data. Please help ASAP
2 Comments
Jan
on 2 Dec 2017
Please avoid "ASAP", because this is not polite if you ask voluntary members of the forum.
Instead of pushing the readers, it would be more useful if you take the time to explain the details: Where do you want to delete the data? In the Excel file or in the variable imported to Matlab? Do you know how to delete a column of a variable in Matlab? How did you import the data? This information would allow the readers to know, in which format they are available: as cell or table object?
Answers (1)
Image Analyst
on 2 Dec 2017
What is large by your definition? I've heard some people call 500 element arrays "large" believe it or not. Are you talking megabytes? Gigabytes?
One option, which is simplest if your data is fairly small (like under a few megabytes) is to simply read all of the data in, then delete some rows and write back out:
data = xlsread(fullFileName);
data(rowsToBeDeleted, :) = [];
delete(fullFileName); % So extra rows on the end of old worksheet don't stay there after writing new data.
xlswrite(fullFileName);
The other option is to use ActiveX. The programming is more complicated but if you have a huge amount of data that takes too long to haul over and send back, then this is the fastest. I'm attaching a general purpose ActiveX Excel demo, though I don't think that it has code for deleting rows in it. You can easily find out the command for doing that by recording a macro in Excel, deleting rows, and looking at the macro to see what methods it called.
0 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!