append new rows in the middle of an excel file's sheet

3 ビュー (過去 30 日間)
AMINE EL MOUATAMID
AMINE EL MOUATAMID 2019 年 4 月 26 日
コメント済み: Guillaume 2019 年 4 月 28 日
I am working on an excel file using actx function
then I want to add some rows in the middle of the sheet
is there a way to solve this ?
Captureaa.PNG
  1 件のコメント
AMINE EL MOUATAMID
AMINE EL MOUATAMID 2019 年 4 月 26 日
this is how I want it to be
d.PNG

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2019 年 4 月 26 日
Probably the easiest way to find out the code you need to use is to record a macro in excel while you do the insertion and fix the formatting (which excel will inevitably mess up). The code you then use in matlab will be more or less identical to the VBA code generated by the macro (with adjustments for the difference in language syntax).
  2 件のコメント
AMINE EL MOUATAMID
AMINE EL MOUATAMID 2019 年 4 月 26 日
is there something like that in matlabCaptureaa.PNG
Guillaume
Guillaume 2019 年 4 月 28 日
For some reasons, I never saw your comment until today.
Once you've connected to excel with actxserver you use more or less the same commands in matlab as you would in VBA. So, yes:
excel = actxserver('Excel.Application'); %connect to excel
wb = excel.Workbooks.Open('C:\somewhere\somefolder\somefile.xlsx');
ws = wb.Worksheets.Item('Sheet1'); %One major difference is that you HAVE to use the Item property to access elements of collections
rg = ws.Range('1:4');
rg.Insert(-4121); %The other difference is that you have to use numeric values for constants. -4121 is the numeric value of XlShiftDown

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by