Basic use of Interface.​000208DA_0​000_0000_C​000_000000​000046

5 vues (au cours des 30 derniers jours)
Mauro Colombano
Mauro Colombano le 20 Mai 2024
Commenté : Mauro Colombano le 17 Juin 2024
I am at the very first use of Interface.000208DA_0000_0000_C000_000000000046, since I need to change an excel, in its fomat and contents, automatically. I have some basic questions, since I have not found clear documentation on them.
1) I know some basic commands, i.e. how to open the excel sheet via "actxserver" and "Workbooks", how to generate "Sheets" objects. I would like to know how can I copy in an excel file, once I have opned it, cells from a sheet to another sheet. These cells shall contain formulas to elaborate the contents of other column that I have generated via a routine of mine.
2) How can I insert in a cell some mixed text, like "Δ Fuel Consumption" (where there is one character using "Symbol" font and the rest is "Calibri")?

Réponses (1)

UDAYA PEDDIRAJU
UDAYA PEDDIRAJU le 14 Juin 2024
Hi Mauro,
I can help you with those basic tasks using MATLAB Interface (.000208DA_0000_0000_C000_000000000046)! Here's how you can tackle your questions:
1. Copying Cells with Formulas between Sheets:
Here's how to copy cells from one sheet to another, including formulas:
% Open the Excel workbook
excel = actxserver('Excel.Application');
workbook = excel.Workbooks.Open('your_excel_file.xlsx');
% Get the source and destination sheets
sourceSheet = workbook.Sheets('Sheet1'); % Replace with actual sheet name
destSheet = workbook.Sheets('Sheet2'); % Replace with actual sheet name
% Define the range of cells to copy (replace with your cell range)
sourceRange = sourceSheet.Range('A1:B10'); % Example range
% Copy the range with formulas to the destination sheet
destRange = destSheet.Range('C1'); % Top-left corner of destination range
sourceRange.Copy.PasteSpecial destRange, xlPasteValuesAndFormulas;
% Close the workbook and quit Excel
workbook.Close;
excel.Quit;
2. Inserting Mixed Text with Font Formatting:
To insert mixed text with different fonts in a cell, you can use the Value and Font properties:
% Get the destination cell (replace with your cell reference)
destCell = destSheet.Range('A1');
% Set the mixed text content
destCell.Value = 'Δ Fuel Consumption';
% Apply font formatting (replace with desired font names)
destCell.Font.Name = 'Calibri'; % Set font for most of the text
destCell.Characters.Item(1).Font.Name = 'Symbol'; % Set font for Δ symbol
% (Optional) Set specific font properties for the symbol
destCell.Characters.Item(1).Font.Size = 12; % Example: Set symbol font size
Tips:
  • Replace placeholders like 'your_excel_file.xlsx' and cell ranges with your actual data.
  • Explore the topics in: https://www.mathworks.com/help/matlab/ref/actxserver.html
  4 commentaires
Walter Roberson
Walter Roberson le 16 Juin 2024
It looks like more correct would be
sourceSheet = workbook.Sheets.Item('Sheet1');
Mauro Colombano
Mauro Colombano le 17 Juin 2024
Thank you Walter for this first suggestion: it works! If you have any siggestion, especially on the topic "destCell.Characters.Item(1).Font.Name = 'Symbol';", it would be really great!

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by