Paste values in excel with MATLAB COM activeX
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Adriano
el 6 de Abr. de 2017
Comentada: Saravana Kumar Balasubramani
el 5 de Abr. de 2022
Hello I need to paste as values in Excel some copied cells. How Can I do? With my code I can copy as formulas and not as values! That's my code:
clc
clear all
excel = actxserver('Excel.Application');
excel.Visible = 1;
excel.DisplayAlerts = 0;
filename = 'C:\Dropbox\Auryn\ESTRATEGIAS\ibs multiactivo2.xlsm';
filename2 = 'C:\Dropbox\Auryn\ESTRATEGIAS\ZEN REAL2.xlsm';
filename3 = 'C:\Dropbox\Auryn\Ordenes\Recommendations2.xlsx';
ibs = excel.Workbooks.Open(filename);
zen = excel.Workbooks.Open(filename2);
rec = excel.Workbooks.Open(filename3);
pause(60)
zen.Activate
invoke(zen,'Save')
zen.Close
ibs.Activate
Sheets = excel.ActiveWorkBook.Sheets;
sheet2 = get(Sheets, 'Item', 5);
invoke(sheet2, 'Activate');
Activesheet = excel.Activesheet;
Activesheet.Range('B64:W104').Copy;
rec.Activate
wksheet = rec.Worksheets.Item('Ordenes');
wksheet.Paste(wksheet.Range('B10'));
0 comentarios
Respuesta aceptada
Guillaume
el 6 de Abr. de 2017
Note: I would recommend against using Active... particularly since you have the references to the original object. With Active... you always run the risk that something else gets activated in between your calls. Instead of
ibs.Activate
Sheets = excel.ActiveWorkBook.Sheets;
simply do
Sheets = ibs.Sheets; %Since ActiveWorkbook should be ibs.
So anyway:
excel = actxserver('Excel.Application');
excel.Visible = true;
excel.DisplayAlerts = false;
filename = 'C:\Dropbox\Auryn\ESTRATEGIAS\ibs multiactivo2.xlsm';
filename2 = 'C:\Dropbox\Auryn\ESTRATEGIAS\ZEN REAL2.xlsm';
filename3 = 'C:\Dropbox\Auryn\Ordenes\Recommendations2.xlsx';
ibs = excel.Workbooks.Open(filename);
zen = excel.Workbooks.Open(filename2);
rec = excel.Workbooks.Open(filename3);
pause(60)
zen.Save; %don't need invoke
zen.Close;
ibsheet = ibs.Sheets.Item(5); %no need for get(...)
ibsheet .Range('B64:W104').Copy;
recsheet = rec.Worksheets.Item('Ordenes');
recsheet.Range('B10').PasteSpecial(-4163); %-4163 for xlPasteValues
3 comentarios
Saravana Kumar Balasubramani
el 5 de Abr. de 2022
@Guillaume could you please let me know what is the equivalent code for xlPasteFormats? And where could I get the codes for other PasteSpecial options?
Saravana Kumar Balasubramani
el 5 de Abr. de 2022
@Guillaume Please ignore this - found it in here:
Más respuestas (0)
Ver también
Categorías
Más información sobre Use COM Objects in MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!