time | Calls | line |
---|
< 0.001 | 2 | 1 | classdef AcceptsSheetNameOrNumber < matlab.io.internal.FunctionInterface
|
| | 2 | %
|
| | 3 |
|
| | 4 | % Copyright 2018-2019 The MathWorks, Inc.
|
| | 5 |
|
| | 6 | properties (Parameter)
|
| | 7 | %SHEET the sheet from which to read
|
| | 8 | % Sheet can be a character vector containing the name of a sheet, or a
|
| | 9 | % positive scalar integer value, or an empty character array.
|
| | 10 | %
|
| | 11 | % If specified as a name, the used sheet will match the name, regardless
|
| | 12 | % of sheet order. The sheet must appear in any file being read.
|
| | 13 | %
|
| | 14 | % If specified as an integer, then the sheet in that position will be
|
| | 15 | % read, regardless of the sheet name.
|
| | 16 | %
|
| | 17 | % If empty, no sheet is specified and the importing function will read
|
| | 18 | % from the appropriate sheet(s).
|
| | 19 | %
|
| | 20 | % See also matlab.io.spreadsheet.SpreadsheetImportOptions
|
| | 21 | Sheet = '';
|
| | 22 | end
|
| | 23 |
|
| | 24 | methods
|
| | 25 | function func = set.Sheet(func,rhs)
|
| | 26 | [sh,func] = func.setSheet(rhs);
|
| | 27 | func.Sheet = convertStringsToChars(sh);
|
| | 28 | end
|
| | 29 |
|
| | 30 | function val = get.Sheet(func)
|
| | 31 | containsOpts = any(strcmp(fieldnames(func),"Options"));
|
| | 32 | try
|
| | 33 | if containsOpts && any(strcmp(fieldnames(func.Options),"Sheet")) ...
|
| | 34 | && strcmp(func.Sheet,'')
|
| | 35 | % if the Options object is well-formed and Sheet has
|
| | 36 | % been initialized properly
|
| | 37 | val = func.Options.Sheet;
|
| | 38 | else
|
| | 39 | % if the Sheet was supplied via NV pairs
|
| | 40 | val = func.Sheet;
|
| | 41 | end
|
| | 42 | catch
|
| | 43 | % If the Options object is not well-formed
|
| | 44 | val = func.Sheet;
|
| | 45 | end
|
| | 46 | end
|
| | 47 |
|
| | 48 | function [S, func] = executeImplCatch(func)
|
| | 49 | ext = extractAfter(func.Extension,'.');
|
| | 50 | if isempty(ext)
|
| | 51 | ext = matlab.io.spreadsheet.internal.getExtension(func.Filename);
|
| | 52 | end
|
| | 53 | if isempty(func.Sheet)
|
| | 54 | defaultSheet = 1;
|
| | 55 | else
|
| | 56 | defaultSheet = func.Sheet;
|
| | 57 | end
|
| | 58 | book = matlab.io.spreadsheet.internal.createWorkbook(ext, ...
|
| | 59 | func.Filename, func.UseExcel, defaultSheet);
|
| | 60 | % .ods and .xlsb files are interactive. Therefore, they require
|
| | 61 | % the use of an Excel COM server to be read properly.
|
| | 62 | if(book.Interactive)
|
| | 63 | func.UseExcel = true;
|
| | 64 | end
|
| | 65 | if isempty(defaultSheet) || numel(book.SheetNames) == 1
|
| | 66 | sheet = book.getSheet(1);
|
| | 67 | if (ischar(defaultSheet) || isstring(defaultSheet)) && ...
|
| | 68 | ~isempty(defaultSheet) && ~strcmp(sheet.Name, defaultSheet)
|
| | 69 | error(message("MATLAB:spreadsheet:book:openSheetName",defaultSheet));
|
| | 70 | end
|
| | 71 | else
|
| | 72 | sheet = book.getSheet(defaultSheet);
|
| | 73 | end
|
| | 74 | S = struct("Book",book, "Sheet", sheet);
|
| | 75 | end
|
| | 76 | end
|
| | 77 |
|
| | 78 | methods (Access='protected', Abstract)
|
| | 79 | [val,func] = setSheet(func,val);
|
| | 80 | end
|
| | 81 | end
|
| | 82 |
|