Excel Spreadsheet Autofill Range (Multiple rows) via MATLAB command

5 次查看(过去 30 天)
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.

请先登录,再进行评论。

更多回答(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