xlswrite an empty string

조회 수: 18 (최근 30일)
Jim
Jim 2012년 8월 10일
I have a list of words in an excel file. I want to delete on item from the list and then move up the words below so there are no blanks, empty cells. I read the file with xlsread. Then I get the shorten list. Finally, I write that array into the same file. The problem is the last item of the original array is still there. For example if the list of words is 'word1 word2 word3' and I delete 'word2' producing 'word1 word3' When I wire this the file contains 'word1 word3 word3' I do not want the second 'word3' there. I've tried putting '' in the last row but that appears as NaN in the excel file.
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 10일
it's not clear

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

채택된 답변

Oleg Komarov
Oleg Komarov 2012년 8월 10일
You can control the excel file directly without importing it through ActiveX:
% Open the excel file (it remains invisible however)
excel = actxserver ('Excel.Application');
% excel.Visible = 1;
workbook = excel.Workbooks.Open('C:\Users\ok1011\Desktop\test.xlsx');
% Activate the sheet you need (optional if the sheet is the first)
workbook.Worksheets.Item(1).Activate;
% Delete A2, shifts upwards
workbook.ActiveSheet.Range('A2').Delete
% Now save/close/quit/delete
% excel.Visible = 0;
workbook.Save;
excel.Workbook.Close;
invoke(excel, 'Quit');
delete(excel)
  댓글 수: 3
Oleg Komarov
Oleg Komarov 2012년 8월 10일
workbook.ActiveSheet.Range(sprintf('A%d',wordelete(1,1))).Delete
Jim
Jim 2012년 8월 11일
thanks again

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

추가 답변 (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