0001 function workbook=loadWorkbook(fileName,createEmpty)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if nargin<2
0015 createEmpty=false;
0016 end
0017
0018
0019
0020 if exist('vaderSentimentScores.m')== 2
0021 error(['MATLAB Text Analytics Toolbox found. This should be uninstalled ' ...
0022 'if you want to read/write Excel files. See RAVEN GitHub Issues '...
0023 'page for instructions.'])
0024 end
0025
0026
0027 addJavaPaths();
0028
0029
0030 import org.apache.poi.ss.usermodel.*;
0031 import org.apache.poi.ss.util.*;
0032 import java.io.FileInputStream;
0033 import org.apache.poi.hssf.usermodel.*;
0034 import org.apache.poi.xssf.usermodel.*;
0035
0036
0037 if ~isfile(fileName)
0038 if createEmpty==false
0039 EM='The Excel file could not be found';
0040 dispEM(EM);
0041 else
0042
0043 [~,~,I]=fileparts(fileName);
0044 if strcmpi(I,'.xls')
0045 workbook=HSSFWorkbook();
0046 else
0047 if strcmpi(I,'.xlsx')
0048 workbook=XSSFWorkbook();
0049 else
0050 EM='The file name must end in .xls or .xlsx';
0051 dispEM(EM);
0052 end
0053 end
0054 end
0055 else
0056
0057
0058 is=FileInputStream(getFullPath(fileName));
0059 workbook=WorkbookFactory.create(is);
0060 is.close();
0061 end
0062 end