File Exchange
Try Origin for Free
The Origin Forum
Home
|
Profile
|
Register
|
Active Topics
|
Members
|
Search
|
FAQ
|
Send File to Tech support
All Forums
Origin Forum for Programming
Forum for Automation Server/COM and LabVIEW
matlab loading data from origin workbooks
Note:
Only the poster of this message, and the Moderator can edit the message.
Screensize:
640 x 480
800 x 600
1024 x 768
1280 x 1024
UserName:
Password:
Anti-Spam Code:
Format Mode:
Basic
Help
Prompt
Format:
Font
Andale Mono
Arial
Arial Black
Book Antiqua
Century Gothic
Comic Sans MS
Courier New
Georgia
Impact
Lucida Console
Script MT Bold
Stencil
Tahoma
Times New Roman
Trebuchet MS
Verdana
Size
1
2
3
4
5
6
Color
Black
Red
Yellow
Pink
Green
Orange
Purple
Blue
Beige
Brown
Teal
Navy
Maroon
LimeGreen
Message:
* HTML is OFF
*
Forum Code
is ON
Smilies
Hi, Couple of things need to be changed in your script: 1. change iterator index b, c to int32(b), int32(c), etc. (Line 9, 18, 38) 2. Column type returns strings, need to change line 46, 49. Please try the following script: [code] tempdata = struct('name',[],'xy',[]); tempdata(1) = []; originObj = actxserver('Origin.ApplicationSI'); workbooksHandle = invoke(originObj,'WorksheetPages'); nbooks = get(workbooksHandle,'Count') % Number of workbooks in project for b = 0:nbooks-1 % Loop all workbooks %workbookHandle = get(workbooksHandle,'Parent',b) workbookHandle = get(workbooksHandle,'Item',int32(b)); % Handle to workbook b workbookName = get(workbookHandle,'Name'); % Short name of workbook b workbookLongName = get(workbookHandle,'LongName') % Long name of workbook b % Identify worksheets worksheetsHandle = get(workbookHandle,'layers'); % Handle to worksheets of workbook b nsheets = get(worksheetsHandle,'Count'); % Number of sheets in workbook b for s = 0:nsheets-1 % Loop all worksheets worksheetHandle = get(worksheetsHandle,'Item',int32(s)); % Handle to sheet s worksheetName = get(worksheetHandle,'Name'); % Short name of sheet s worksheetLongName = get(worksheetHandle,'LongName'); % Long name of sheet s worksheetData = invoke(originObj,'GetWorksheet',sprintf('[%s]%s',workbookName,worksheetName)); % Get worksheet data fh = @(x) all(isnan(x(:))); worksheetData(cellfun(fh, worksheetData)) = {[]}; % Remove all NaN from cell array fh = @(x) all(ischar(x(:))); worksheetData(cellfun(fh, worksheetData)) = {[]}; % Remove all strings from cell array if ~iscell(worksheetData) || isempty(worksheetData) % If there is no worksheet data found, continue to next continue end % Identify columns columnsHandle = get(worksheetHandle,'Columns'); % Handle to columns of worksheet s ncolumns = get(columnsHandle,'Count'); % Number of columns in sheet s x = []; y = []; for c = 0:ncolumns-1 % Loop all columns columnHandle = get(columnsHandle,'Item',int32(c)); % Handle to column c columnName = get(columnHandle,'Name'); % Name of column c columnType = get(columnHandle,'Type'); % Column type: 0 (Y), 3 (X) or 5 (Z) columnLongName = get(columnHandle,'LongName'); % Long name of column c columnsUnits = get(columnHandle,'Units'); % Units specified in column c (not actually used here) columnComment = get(columnHandle,'Comments'); % Comments specified in column c (not actually used here) % Store column data if columnType=='COLTYPE_X' % If x-vector x = [worksheetData{:,c+1}]'; x(isnan(x)) = []; % Remove NaN elseif columnType=='COLTYPE_Y' % If y-vector y = [worksheetData{:,c+1}]'; y(isnan(y)) = []; % Remove NaN % Check x,y data if ~isnumeric(x) || ~isnumeric(y) || ismember(1,isnan(x)) || ismember(1,isnan(y)) || isempty(x) || isempty(y) % || length(x)<5 || length(y)<5 % If x and y are not actual data, skip to next continue end % Put (x,y) pair into tempdata structure tempdata(end+1).name = sprintf('Book[%s]: Sheet[%s]: Col(%s): Name(%s)',workbookLongName,worksheetName,columnName,columnLongName); if length(x)>length(y) tempdata(end).xy = [x(1:length(y)) y]; % Cut x elseif length(x)<length(y) tempdata(end).xy = [x y(1:length(x))]; % Cut y else tempdata(end).xy = [x y]; % Equal sizes of x and y end else % If z-vector, skip continue end end end end tempdata.xy [/code] Thank you, Yiming
Check here to subscribe to this topic.
The Origin Forum
© 2020 Originlab Corporation
Snitz Forums 2000