How can I copy the formatting of a row from an Excel spreadsheet and paste it into another Excel spreadsheet using MATLAB?
5 views (last 30 days)
Show older comments
I have an input spreadsheet and an output spreadsheet that's generated after calculations are run through MATLAB. I need the formatting of the output spreadsheet's header row to match the input spreadsheet's header row. Can anyone please help with the MATLAB code for this? Perhaps utilizing format-copy and paste in Excel?
Any help would be greatly appreciated.
0 Comments
0 Comments
Answers (1)
Rahul
on 17 Feb 2025
In order to transfer formatting from one excel spreadsheet to another, consider using 'Copy' function of the 'Range' of the sheet and 'PasteSpecial' function to apply it to the other excel spreadsheet.
Here is an example:
% Open Excel application
excel = actxserver('Excel.Application');
excel.Visible = true;
% Open the input and output spreadsheets
inputWorkbook = excel.Workbooks.Open('C:\path\to\your\input.xlsx');
inputSheet = inputWorkbook.Sheets.Item(1);
outputWorkbook = excel.Workbooks.Open('C:\path\to\your\output.xlsx');
outputSheet = outputWorkbook.Sheets.Item(1);
% Get the header range from the input sheet - adjust as needed
inputHeaderRange = inputSheet.Range('A1:Z1');
outputHeaderRange = outputSheet.Range('A1:Z1');
% Copy the format from the input header to the output header
inputHeaderRange.Copy;
outputHeaderRange.PasteSpecial('xlPasteFormats');
% Clean up
inputWorkbook.Save;
outputWorkbook.Save;
inputWorkbook.Close;
outputWorkbook.Close;
excel.Quit;
delete(excel);
Refer to the following MATLAB Answer:
0 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!