MATLAB Answers

How to insert new column to existing excel sheet?

49 views (last 30 days)
azizullah khan
azizullah khan on 8 Oct 2014
Edited: Guillaume on 8 Oct 2014
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.

Accepted Answer

Guillaume
Guillaume on 8 Oct 2014
Edited: Guillaume on 8 Oct 2014
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 Comments
Guillaume
Guillaume on 8 Oct 2014
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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!