Question about deploying an Excel Add-In using MATLAB Library compiler
조회 수: 2 (최근 30일)
이전 댓글 표시
Meghashyam Panyam
2017년 10월 27일
댓글: Meghashyam Panyam
2017년 10월 31일
Hello, I am trying to build an excel add-in from Matlab that can take in cells as inputs, search for specific columns, and print the data to a text file. I was able to compile the function using the library compiler and import the add-in to excel as explained in the link below: https://www.mathworks.com/videos/getting-started-excel-add-ins-using-matlab-compiler-100089.html My code looks something like this:
function [ flag ] = test(x)
data = x;
headers = data(1,:);
CH_Type = data(:,1);
c = clock;
c = fix(c);
filename = fullfile(pwd,'test_file.txt');
fid = fopen(filename,'w');
fprintf(fid,'<DATE>%i/%i/%i \t %02i:%02i:%02i</DATE>\n',c(1),c(2),c(3),c(4),c(5),c(6));
fclose(fid);
flag = {'Successfully Completed!'};
end
When I package this function as an excel add-in and call it from within excel, I get the following error: "Error in test.Class1.1_0:Invalid File Identifier. Use fopen to generate a valid file identifier." After searching on MATLAB forums, I found that the function fopen behaves differently when deployed in a standalone application. I thought that using the pwd command with fopen would force the application to get the right fid because I put the text file with the same name in the folder with the excel add in as well as the actual excel sheet. However, the error persists. I am not sure if I am doing something wrong. Is there a workaround to this error? Thanks in advance. Shyam
댓글 수: 0
채택된 답변
Ankitha Kollegal Arjun
2017년 10월 31일
The error message of type 'Invalid File Identifier. Use fopen to generate a valid file identifier' is due to the fact that all deployed applications look for a file relative to the "ctfroot", unless the file has been packaged along with the application while compiling it.
As a workaround, use the entire path of the file as the argument to the "fopen" command as shown below:
[FileName,PathName] = uigetfile('*.csv')
fullpath = [PathName FileName];
fid = fopen(fullpath);
The file identifier would now be valid.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Excel Integration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!