This is a static copy of a profile report

Home

createWorkbook (Calls: 2, Time: 0.010 s)
Generated 04-Jun-2021 04:11:08 using performance time.
function in file C:\Program Files\MATLAB\R2020b\toolbox\shared\spreadsheet\+matlab\+io\+spreadsheet\+internal\createWorkbook.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
UsesWorksheet>UsesWorksheet.openBookclass method2
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
80
book = constructWorkbook(forma...
20.008 s77.3%
68
stringCheck = ~emptySheet &...
20.001 s5.8%
44
initLibrary();
20.000 s4.7%
48
tryInterop = ispc && (...
20.000 s2.2%
67
numericScalarCheck = ~emptyShe...
20.000 s1.5%
All other lines  0.001 s8.6%
Totals  0.010 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
createWorkbook>constructWorkbooksubfunction20.008 s75.6%
createWorkbook>initLibrarysubfunction20.000 s2.8%
Self time (built-ins, overhead, etc.)  0.002 s21.5%
Totals  0.010 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function103
Non-code lines (comments, blank lines)42
Code lines (lines that can run)61
Code lines that did run30
Code lines that did not run31
Coverage (did run/can run)49.18 %
Function listing
time 
Calls 
 line
   1 
function book = createWorkbook(format, filename, interop, sheet, sheetNamesOnly)
   2 
%CREATEWORKBOOK Create a Workbook object
   3 
%
   4 
%   BOOK = CREATEWORKBOOK(FMT) creates a new book from the format
   5 
%   specified by FMT.
   6 
%
   7 
%   BOOK = CREATEWORKBOOK(FMT, FILENAME) creates a book from the file
   8 
%   specified by FILENAME.  FMT must match the format of the spreadsheet
   9 
%   specified by FILENAME.
  10 
%
  11 
%   BOOK = CREATEWORKBOOK(..., true|false) an optional third input argument
  12 
%   specifies whether to use an interactive application to instantiate the Workbook.
  13 
%
  14 
%   BOOK = CREATEWORKBOOK(..., sheet) an optional fourth input argument
  15 
%   specifies to sheet to read from the Workbook.
  16 
%
  17 
%   BOOK = CREATEWORKBOOK(..., sheetNames) an optional fifth logical input
  18 
%   argument that specifies that only the sheet names need to be returned
  19 
%
  20 
%   Example interactive workbook:
  21 
%   book = matlab.io.spreadsheet.internal.Workbook('xlsx','airlinesmall_subset.xlsx', false, 1); 
  22 
%
  23 
% See also matlab.io.spreadsheet.internal.Book,
  24 
% matlab.io.spreadsheet.internal.Sheet
  25 
%
  26 

  27 
% Copyright 2015-2019 The MathWorks, Inc.
  28 

< 0.001 
      2 
  29
narginchk(1, 5); 
< 0.001 
      2 
  30
    nargoutchk(0, 1); 
  31 

< 0.001 
      2 
  32
    if nargin < 2 
  33 
        filename = [];
      2 
  34
    end 
< 0.001 
      2 
  35
    if nargin < 3 || isempty(interop) 
  36 
        interop = false;
      2 
  37
    end 
< 0.001 
      2 
  38
    if nargin < 4 
  39 
        sheet = [];
< 0.001 
      2 
  40
    end 
< 0.001 
      2 
  41
    if nargin < 5 
< 0.001 
      2 
  42
        sheetNamesOnly = false; 
      2 
  43
    end 
< 0.001 
      2 
  44
    initLibrary(); 
  45 

< 0.001 
      2 
  46
    isODSorXLSB = contains(format, {'ods', 'xlsb'}, 'IgnoreCase',true); 
  47 
    % Use COM on Windows if UseExcel i.e. interop is true or input file format is ods / xlsb
< 0.001 
      2 
  48
    tryInterop = ispc && (interop || isODSorXLSB); 
< 0.001 
      2 
  49
    if interop && isWebServerCheck 
  50 
        warning(message("MATLAB:spreadsheet:book:webserviceExcelWarn"));
< 0.001 
      2 
  51
    end 
  52 

< 0.001 
      2 
  53
    if(interop && ~tryInterop) 
  54 
        oldState = warning('off','backtrace');
  55 
        % Warn on Non-Windows platforms if 'UseExcel' is set to true & silently switching to LibXL
  56 
        warning(message('MATLAB:spreadsheet:book:noExcel'));
  57 
        warning(oldState);
< 0.001 
      2 
  58
    end 
  59 

  60 
    % determine whether sheet should be set to empty - 
  61 
    %    1) if filename was not passed in
  62 
    %    2) if sheet was not passed in
  63 
    %    3) if sheet was passed in as a char/string
  64 
    %    4) if sheet was passed in as a numeric vector
< 0.001 
      2 
  65
    emptySheet = (nargin == 4 && isempty(sheet)); 
< 0.001 
      2 
  66
    emptyFile = isempty(filename); 
< 0.001 
      2 
  67
    numericScalarCheck = ~emptySheet && isnumeric(sheet) && numel(sheet) > 1; 
< 0.001 
      2 
  68
    stringCheck = ~emptySheet && (isstring(sheet) || ischar(sheet)); 
< 0.001 
      2 
  69
    comMode = tryInterop == 1; 
< 0.001 
      2 
  70
    if emptyFile || emptySheet || numericScalarCheck || stringCheck || comMode 
  71 
        sheet = [];
< 0.001 
      2 
  72
    end 
  73 

< 0.001 
      2 
  74
    if isODSorXLSB 
  75 
        % this optimization is not possible for Windows
  76 
        sheetNamesOnly = [];
< 0.001 
      2 
  77
    end 
  78 

< 0.001 
      2 
  79
    try %#ok<TRYNC> 
  0.008 
      2 
  80
        book = constructWorkbook(format, filename, tryInterop, sheet, sheetNamesOnly); 
< 0.001 
      2 
  81
        return; 
  82 
    end
  83 
    try
  84 
        book = constructWorkbook(format, filename, false, sheet, sheetNamesOnly);
  85 
        return;
  86 
    catch ME
  87 
        if ~tryInterop
  88 
            if strcmp(ME.identifier, 'MATLAB:spreadsheet:book:unsupportedFormat')
  89 
                switch format
  90 
                    case {'ods', 'xlsb'}
  91 
                        error(message('MATLAB:spreadsheet:book:fileTypeUnsupported', format));
  92 
                    case {'csv'}
  93 
                        invalidFormatError(ispc);
  94 
                    otherwise
  95 
                        rethrow(ME);
  96 
                end
  97 
            elseif strcmp(ME.identifier, 'MATLAB:spreadsheet:book:invalidFormat')
  98 
                invalidFormatError(ispc);
  99 
            end
 100 
        end
 101 
    end
 102 
    rethrow(ME);
 103 
end

Other subfunctions in this file are not included in this listing.