이 코드는 주어진 rgb로 J1 셀의 색을 지정해야합니다.Matlab : 내가 색칠 할 때 이상한 파일이 생성되었습니다
row_number_excel = 1;
representative_red = 205;
representative_green = 211;
representative_blue = 201;
headers = {'J'};
rgb = [representative_red representative_green representative_blue]; %# if you have 0 to 1 values multiply by 255 and round
clr = rgb * [1 256 256^2]'; %# convert to long number Excel understands
pwd = 'D:\grapes\main';
e = actxserver ('Excel.Application'); % open Activex server
filename = fullfile(pwd,'example.xls'); %# full path required
if exist(filename,'file')
ewb = e.Workbooks.Open(filename); %# open the file
else
error('File does not exist.') %# or create a new file
end
esh = ewb.ActiveSheet;
for c = 1:row_number_excel
str = num2str(row_number_excel);
esh.Range(strcat(headers{1},str)).Interior.Color = clr;
end
ewb.Save
ewb.Close(false)
e.Quit
이 코드를 실행하려고했지만 셀이 주어진 rgb와 다른 색으로 표시되었습니다. 두 번째 시간에 코드를 실행하면 내 디렉토리에 "2E60F720"이라는 파일이 만들어졌습니다. 유형은 '파일'입니다. 그런 다음 프로그램이 실행되고 실행되어 작업 관리자가 'EXCEL.EXE'를 중지 할 때까지 중지되지 않았습니다. 그 후 MATLAB이 나를 썼습니다 :
"??? Error: The remote procedure call failed.
Error in ==> test1 at 212 ewb.
Close(false);"
도와 주실 수 있습니까? 화면을 캡처했습니다. 왼쪽에는 프로그램이 여전히 실행 중이며, 오른쪽에는 내 디렉토리입니다. 내가 만든 파일을 표시했습니다. 감사합니다. 내 질문을 해결
솔루션은 다음과 같습니다
row_number_excel = 1;
representative_red = 205;
representative_green = 211;
representative_blue = 201;
headers = {'J'};
rgb = [representative_red representative_green representative_blue]; %# if you have 0 to 1 values multiply by 255 and round
clr = rgb * [1 256 256^2]'; %# convert to long number Excel understands
pwd = 'D:\grapes\main';
e = actxserver ('Excel.Application'); % open Activex server
filename = fullfile(pwd,'example.xls'); %# full path required
if exist(filename,'file')
ewb = e.Workbooks.Open(filename); %# open the file
else
error('File does not exist.') %# or create a new file
end
esh = ewb.ActiveSheet;
for c = 1:row_number_excel
str = num2str(row_number_excel);
esh.Range(strcat(headers{1},str)).Interior.Color = clr;
end
xlWorkbookDefault = 51; %# it's the Excel constant, not sure how to pass it other way
ewb.SaveAs(fullfile(pwd,'example2'), xlWorkbookDefault)
ewb.Close(false)
e.Quit
덕분에 @yuk하기!
가능한 중복 [matlab에 이상한 파일이 생성 될 때 Excel에서 I 색 세포 (http://stackoverflow.com/questions/10125937/matlab-strange-file-was- : 마지막 라인으로이를 넣어 @ -i-color-cell-in-excel) – Jonas
@Jonas : 링크가 죽었습니다 ... – Lucas
@ 루카스 : 다른 질문이 삭제 되었기 때문에. – Jonas