Hello, i have a matrix that i'm stocking it into an excel file and i'm trying to color a cell of my excel file, which function should i use please, i don't think that xlswrite allow me to do that ? thank you!!

4 commentaires

Rik
Rik le 17 Juil 2018
You will probably need to look into ActiveX controls.
omar Benamiar Messari
omar Benamiar Messari le 17 Juil 2018
Modifié(e) : omar Benamiar Messari le 17 Juil 2018
i was locking into activix i tried some stuff but didn't work. can you give me any exemple of doing that this is what i have done
global matrix;
[filename, pathname] = uiputfile('*.xls', 'Choose a file name');
outname = fullfile(pathname, filename);
xlswrite(outname, matrix );
%[dec2base27(4),num2str(1) : dec2base27(4),num2str(1)]
%ActiviX to color excel cell
% Connect to Excel
Excel = actxserver('excel.application');
% Get Workbook object
WB = Excel.Workbooks.Open(outname);
% Set the color of cell "A1" of Sheet 1 to RGB
WB.Worksheets.Item(1).Range('A1').Interior.Color = hex2dec('00FF00');
% Save Workbook
WB.Save();
% Close Workbook
WB.Close();
% Quit Excel
Excel.Quit();
Dennis
Dennis le 17 Juil 2018
do you always need to color the same cells or do they vary?
omar Benamiar Messari
omar Benamiar Messari le 17 Juil 2018
Modifié(e) : omar Benamiar Messari le 17 Juil 2018
they vary it's depend on their values.
but trying first to color just one and then i'll try to collor others . from a simple exemple (if it's work) i can move to complicate application

Connectez-vous pour commenter.

 Réponse acceptée

Dennis
Dennis le 17 Juil 2018
Modifié(e) : Dennis le 17 Juil 2018

4 votes

Actually your code looks good despite a small typo.
Excel = actxserver('excel.application');
% ^ capital E
Copy & paste exampel:
a={'This', 'is','a','test'};
[filename, pathname] = uiputfile('*.xls', 'Choose a file name');
outname = fullfile(pathname, filename);
xlswrite(outname,a);
excel=actxserver('Excel.application');
wb=excel.Workbooks.Open(outname);
wb.Worksheets.Item(1).Range('A1').Interior.Color=hex2dec('00FF00');
wb.Save
wb.Close
winopen(outname)

4 commentaires

omar Benamiar Messari
omar Benamiar Messari le 17 Juil 2018
do you have any idea of how can we use this form [dec2base27(4),num2str(1)] in wb.Worksheets.Item(1).Range('A1').Interior.Color=hex2dec('00FF00'); to have for exemple different cell ??
x=0; %0 to 25 (A - Z)
[char(65+x),num2str(1)]
If you can only read it you probably opened an excel application at one point and got an error, then it wasn't closed. Maybe check your task manager for any excel processes and get rid of them.
omar Benamiar Messari
omar Benamiar Messari le 17 Juil 2018
Modifié(e) : omar Benamiar Messari le 17 Juil 2018
ok i don't know why but your test is working without any problem, but mine had some so i just changed your a into matrice and it's working, (this is magic :p)
thank you so much for your help
Dennis
Dennis le 17 Juil 2018
char() converts a number to an ASCII sign. 'A' has index 65 on ASCII table - that's pretty much all i know about it =P
I think the first 128 (0-127) chars are set in stone. All others can vary depending on your local setting.

Connectez-vous pour commenter.

Plus de réponses (1)

omar Benamiar Messari
omar Benamiar Messari le 17 Juil 2018

0 votes

your exemple is working perfectlly but i have now some errors in mine, when i save it's saving normally but when i open it it's teeling me that we can just open this file as reading file and the color stuff is not working on my code, but your exemple is working normally, i really can't understand why

Community Treasure Hunt

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

Start Hunting!

Translated by