Question about deploying an Excel Add-In using MATLAB Library compiler

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Ankitha Kollegal Arjun
Ankitha Kollegal Arjun il 31 Ott 2017
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.

Più risposte (0)

Categorie

Scopri di più su Excel Add-Ins in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by