How to insert new column to existing excel sheet?

조회 수: 18 (최근 30일)
azizullah khan
azizullah khan 2014년 10월 8일
편집: Guillaume 2014년 10월 8일
My aim is to insert new column/Cells (for specific range e.g B2:B8 ) with out interrupting other cells or data.More specific i want to insert New cells without disturbing remaining pattern and data. If it is possible using actxserver kindly share your experience with me thanks.

채택된 답변

Guillaume
Guillaume 2014년 10월 8일
편집: Guillaume 2014년 10월 8일
Not tested:
excel = actxsever('Excel.Application');
wb = excel.Workbooks.Open('somefile.xlsx');
ws = wb.Worksheets.Item('sheetname');
ws.Range('B2:B8').Insert;
%other code
wb.Save;
excel.Quit;
delete(excel);
edited for numerous errors!
  댓글 수: 9
Iain
Iain 2014년 10월 8일
The easiest way is probably to use the matlab supplied xlsread and xlswrite functions:
[n t data] = xlsread(...)
data(:,3:end+1) = data(:,2:end);
data(2:8,2) = %your new stuff...
xlswrite(..., data);
But if you want to do it all yourself (and there are reasons you might), then the code in xlswrite probably tells you how to add stuff in a way you want.
Guillaume
Guillaume 2014년 10월 8일
To write values to a range:
ws.Range('B2:B8').Value = [1 2 3 4 5 6 7]'; %array must be same shape as range

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

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