The Origin Forum
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
 LabTalk Forum
 Excel Import

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
alex_eagle Posted - 11/13/2002 : 04:48:50 AM
Hi everybody,

we use the following script to import Excel data into origin worksheets. The script makes the first row of the data the labels of the worksheet with the doc -e command.
However, when the script is executed more than once, the doc -e command also affects the already imported data.
What commands can be chosen to only affect the data which is about to be imported with the script ?

thanx
Alex
run.section(,Init);

FDLOG.UseGroup(Excel);

if(FDLOG.Open(A))

return 1;

%B=FDLOG.path$;

ExOpen=system.Excel.OpenAsExcel;

ExProm=system.Excel.OpenAsPrompt;

system.Excel.OpenAsExcel=0;

system.Excel.OpenAsPrompt=0;

%B=FDlog.path$;

doc -append %B%A; ;

doc -e W {thisrow=1;
loop(jj,1,wks.ncols) {wks.col$(jj).label$=%(%H,jj,thisrow);}
wks.labels();
mark -d %(%H,1) -b thisrow -e thisrow;}


system.Excel.OpenAsExcel=ExOpen;

system.Excel.OpenAsPrompt=ExProm;

delete -v ExOpen;

delete -v ExProm;


4   L A T E S T    R E P L I E S    (Newest First)
Mike Buess Posted - 11/20/2002 : 09:07:25 AM
Alex,

I think your method will work fine. I haven't used doc.wksname$(number)$, but if it returns wks names in creation order as advertised there should be no problem. Now you don't have to use doc -e W and I assume that your script looks something like this.
...
doc -cw; cc1=count+1;
doc -append %B%A;
doc -cw; cc2=count;
loop (ii,cc1,cc2) {
%W=doc.wksname$(ii)$;
win -o %W {
thisrow=1;
loop(jj,1,wks.ncols) {wks.col$(jj).label$=%(%H,jj,thisrow);}
wks.labels();
mark -d %(%H,1) -b thisrow -e thisrow;
};
};
...




Mike Buess
Origin WebRing Member
alex_eagle Posted - 11/20/2002 : 04:02:00 AM
Thank you Mike for your suggestions.

I am absolutely sure they work fine.
However, I managed my problem in another way.
I count the worksheets in the project prior to importing and after importing. Then I do the modifications only on the newly imported worksheets using the %Z=doc.wksname$(number)$ command.
But I am not sure if this is a very safe method.
Is it guaranteed that the newly imported worksheets always get the highest numbers? What happens if a worksheet is deleted ? What if some graph windows are also present ?
If there are some possible bugs with this method, I have to use some of your programs.

Alex


Mike Buess Posted - 11/19/2002 : 5:10:15 PM
Hi Alex,

You could also use the column labels themselves as markers...
doc -e W {
%L=wks.col1.label$;
// is the label empty?
if(%L=="") {
thisrow=1;
loop(jj,1,wks.ncols) {wks.col$(jj).label$=%(%H,jj,thisrow);}
wks.labels();
mark -d %(%H,1) -b thisrow -e thisrow;
};
};

Or you could minimize all worksheets prior to the import and then just operate on non-minimized windows...
doc -e W {win -i};
doc -append %B%A;
doc -e O {
// is this a new worksheet window?
if(exist(%H)==2) {
thisrow=1;
loop(jj,1,wks.ncols) {wks.col$(jj).label$=%(%H,jj,thisrow);}
wks.labels();
mark -d %(%H,1) -b thisrow -e thisrow;
};
};


Mike Buess
Origin WebRing Member
greg Posted - 11/19/2002 : 2:10:49 PM
You need to manage this on your own. You could keep track of what has been processed and exclude those worksheets from further processing.
Here is a modification of your script that uses the cell in row 9999 of column 1 as a marker (keeps track that this sheet is done):

run.section(file,Init);
FDLOG.UseGroup(Excel);
if(FDLOG.Open(A)) return 1;
%B=FDLOG.path$;
ExOpen=system.Excel.OpenAsExcel;
ExProm=system.Excel.OpenAsPrompt;
system.Excel.OpenAsExcel=0;
system.Excel.OpenAsPrompt=0;
%B=FDlog.path$;
doc -append %B%A;
doc -e W
{
thisrow=1;
if(wcol(1)[9999]==0/0) // Is the cell empty?
{
wcol(1)[9999]=1; // Now it isn't empty, it's marked
loop(jj,1,wks.ncols)
{
wks.col$(jj).label$=%(%H,jj,thisrow);
}
wks.labels();
mark -d %(%H,1) -b thisrow -e thisrow;
}
}
system.Excel.OpenAsExcel=ExOpen;
system.Excel.OpenAsPrompt=ExProm;
delete -v ExOpen;
delete -v ExProm;

If you have Origin 7 SR2, you can try this:

run.section(file,Init);
FDLOG.UseGroup(Excel);
if(FDLOG.Open(A)) return 1;
%B=FDLOG.path$;
ExOpen=system.Excel.OpenAsExcel;
ExProm=system.Excel.OpenAsPrompt;
system.Excel.OpenAsExcel=0;
system.Excel.OpenAsPrompt=0;
%B=FDlog.path$;
doc -append %B%A;
doc -e W
{
thisrow=1;
if(page.info.scripts.ImportAndMove != 1) // Is this set to 1?
{
page.info.add(Scripts); // Create storage
page.info.scripts.ImportAndMove = 1; // Create and Set
loop(jj,1,wks.ncols)
{
wks.col$(jj).label$=%(%H,jj,thisrow);
}
wks.labels();
mark -d %(%H,1) -b thisrow -e thisrow;
}
}
system.Excel.OpenAsExcel=ExOpen;
system.Excel.OpenAsPrompt=ExProm;
delete -v ExOpen;
delete -v ExProm;

Note that "Info Storage" is a feature that is still in beta, so you might not want to use it for a production script and I won't document the properties and methods here - since they are subject to change.


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000