Excel Spreadsheet Autofill Range (Multiple rows) via MATLAB command

조회 수: 2 (최근 30일)
Salah
Salah 2022년 8월 10일
편집: dpb 2022년 8월 11일
Hi there!
I am working automating excel work flow and trying to get MATLAB to autofill a range in an Excel spreadsheet.
The range I am looking into is multiple rows in a column with various equations and the fuction would emulate selecting those rows in the column and autofilling the adjacent column with the equations by draging the "Plus" at the bottom right corner of the cell.
I ran into similar challanegs the memebers faced but the solution I found is unclear. Any help would be amazing.
Thank you!

채택된 답변

dpb
dpb 2022년 8월 10일
Start by creating a macro that does what you want done and look at in in VBA -- I usually just paste it into the MATLAB editor as comments as my rosetta stone. Then look up the VBA doc for the methods referenced and translate from VBA syntax to COM, remembering there is no VBA compiler to translate named parameters nor autocomplete named constants -- you've got to do it all.
<Excel.range.autofill> is link to the method; there's link there to the named constants for type; you'll have to be able to set the range object from user input or program logic.
Oh...just noticed a previous <Answers/165083-autofill-range-in-excel-using-matlab> solved the problem for you already...that's one I hadn't yet needed.
  댓글 수: 4
dpb
dpb 2022년 8월 11일
workbook = Excel.Workbooks.Open(excelFullFileName);
sheets=workbook.Sheets;
Sheet=sheets.Item('Sheet1');
sourceRange=Sheet.Range('I2:J3');
fillRange=Sheet.Range('I2:J10');
sourceRange.AutoFill(fillRange,0)
Excel.ActiveWorkbook.Save
Excel.ActiveWorkbook.Close(0)
did, in fact, work as advertised. I started with
time in S
0.0113222 566110 0.011322
0.02264294 566111 0.033965
as the content of E1:J3 where I2:I3 were the constants shown and J2:J3 were
=J1+E2
=J2+E3
The result was the continuation of the series in both columns -- numeric in I and the formula in J, just as if had selected I2:J3 in the sheet and drug the corner down.
"Piece 'o cake!!!!" it appears...although I'd not had need to try it before, I think I'll take the template and add to the Excel utilities class here.
Salah
Salah 2022년 8월 11일
This clears things out. I tried it and it worked. Thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by