1 classdef ExcelFileUtils
3 function [isPos,activeXObj]=isExcelInstalled()
5 activeXObj = matlab.io.internal.getExcelInstance;
12 [success,theMessage,fileName]=xlsOrCsvWrite(fileName,dataMat,...
18 function [isSuccess,SStatus,fileName]=xlsOrCsvWrite(fileName,dataMat,varargin)
20 import
mxberry.log.log4j.Log4jConfigurator;
21 logger=Log4jConfigurator.getLogger();
26 [~,~,fileExt]=fileparts(fileName);
27 isXLSX=strcmpi(fileExt,'.xlsx');
29 isDataEmpty=isempty(dataMat);
31 isTooManyRows=~isXLSX&&(size(dataMat,1)>N_MAX_XLS_ROWS);
32 isTooManyCols=~isXLSX&&(size(dataMat,2)>N_MAX_XLS_COLS);
34 if isDataEmpty||isTooManyRows||isTooManyCols
37 warnStr='data is empty';
39 warnStr='too many rows';
41 warnStr='too many columns';
43 logger.warn(sprintf(['Result will be written to ',...
44 'csv file, reason: %s'],warnStr));
48 logger.warn(['Cannot get access to Excel ActiveX ',...
49 'server, using CSV format']);
50 % write data as CSV file, that is, comma delimited.
58 fileName = regexprep(fileName,'(\.xls[^.]*+)$','.csv');
63 SStatus.identifier='';
67 'An error occurred on data export in CSV format.');
68 exceptionNew = exceptionNew.addCause(exception);
74 SStatus.message = exceptionNew.getReport;
75 SStatus.identifier = exceptionNew.identifier;
76 SStatus.exceptionObject=exceptionNew;
80 [isSuccess,SStatus]=xlswrite(fileName,dataMat,varargin{:});
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function csvwrite(in fileName, in inpCMat, in varargin)
CSVWRITE writes a specified cell matrix into a comma-separated file specified by name. All columns of the matrix are expected to be of the same type. As of the moment only 'char' and all numeric types are supported.