필터 지우기
필터 지우기

How to delete data in excel file?

조회 수: 9 (최근 30일)
dinh tai
dinh tai 2012년 6월 5일
How to delete data in excel file from Guide? Thanks!

채택된 답변

Image Analyst
Image Analyst 2012년 6월 5일
Use ActiveX programming. Several examples of using ActiveX to control Excel are in this Answers forum and in the Mathworks help or web site. I haven't cleared cells exactly yet. But I've cleared comments from cells and the code looks like this:
%---------------------------------------------------------------------------------------------------------------------
% Add comments to cells on sheet.
% Sometimes this throws exception #0x800A03EC on the second and subsequent images. It looks like this:
% "Error: Object returned error code: 0x800A03EC"
% It is because of trying to insert a comment for a worksheet cell when a comment already exists for that worksheet cell.
% So in that case, rather than deleting the comment and then inserting it, I'll just let it throw the exception
% but I won't pop up any warning message for the user.
function InsertComments(Excel, caComments, sheetNumber, startingRow, startingColumn)
try
worksheets = Excel.sheets;
% thisSheet = get(worksheets, 'Item', sheetNumber);
thisSheet = Excel.ActiveSheet;
thisSheetsName = Excel.ActiveSheet.Name; % For info only.
numberOfComments = size(caComments, 1); % # rows
for columnNumber = 1 : numberOfComments
columnLetterCode = cell2mat(ExcelCol(startingColumn + columnNumber - 1));
% Get the comment for this row.
myComment = sprintf('%s', caComments{columnNumber});
% Get a reference to the cell at this row in column A.
cellReference = sprintf('%s%d', columnLetterCode, startingRow);
theCell = thisSheet.Range(cellReference);
% You need to clear any existing comment or else the AddComment method will throw an exception.
theCell.ClearComments();
% Add the comment to the cell.
theCell.AddComment(myComment);
end
catch ME
errorMessage = sprintf('Error in function InsertComments.\n\nError Message:\n%s', ME.message);
fprintf(errorMessage);
WarnUser(errorMessage);
end
return; % from InsertComments
The above is a nice little function if you have a list of comments that you want to add to the cells. They will popup when you hover the cursor over them. To clear a cell, my guess is that you'd probably do something like
theCell.Clear();
but you might have to check the API reference or play around with it a little bit.
  댓글 수: 3
Image Analyst
Image Analyst 2012년 6월 5일
if exist(fullFileName, 'file')
delete(fullFileName);
end
dinh tai
dinh tai 2012년 6월 5일
yes. Спасибо ! :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by