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
 Forum for Origin C
 Import Filters Origin C without wizard

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
peter.cook Posted - 07/12/2004 : 06:31:33 AM
Hi,

I'm trying to adapt example filters set up for importing multiple spreadsheets. I have two issues that I'd be very grateful for any assist with..

i) I would like to code all this so as not to display the import wizard eg click on a buton and user only has to select the (.xls) file.

ii) I would like to attach both filters (multipleworksheets.oif and singleworksheet.oif) to the project and use these.

Say I might have a generic MultipleWorksheets.oif file in filters folder but would like to override with oif file attached to project.

Thanks,

cheers,

pete

7   L A T E S T    R E P L I E S    (Newest First)
hajo_old Posted - 07/14/2004 : 08:16:36 AM
Hello, Easwar

thanks for the comments ..
It is just the same way I'm handling a similar problem, so ...

Thanks again
Hajo

-- --
Dipl.-Ing. Hans-Joerg Koch
SiemensVDO Automotive
Regensburg
easwar Posted - 07/13/2004 : 09:35:44 AM
quote:

Did I get you all right, that I can use XLS files with the ASCII import filter tool?



Hi Hajo,

There is currently no direct way to import XLS files into Origin - other than opening an XLS file as Excel or as an Origin workbook. In Pete's case, his XLS files had (header) text at the top of each sheet, and so opening it directly into Origin would just bring the text in as is. He wanted to instead treat each sheet as an input file and have it "filtered" by separating header section etc. and brining in the data into Origin columns.

So we set up an Origin C based import filter that opens the XLS file using COM, then exports each sheet to an ASCII file, and then imports each one of those ASCII files into Origin using another preset import filter. This works well if all sheets have the same format for the data (including header text etc) which may be the case when instruments write out data to multiple XLS sheets from multiple measurements for example.

This sample can be found in the product under:
\Samples\Programming\User Defined Import

Easwar
OriginLab

hajo_old Posted - 07/13/2004 : 03:23:26 AM
Hello, all

just a question a little bit off topic ...

Did I get you all right, that I can use XLS files with the ASCII import filter tool?

Can I get some hints about that?

Thanks
Hajo

-- --
Dipl.-Ing. Hans-Joerg Koch
SiemensVDO Automotive
Regensburg
easwar Posted - 07/12/2004 : 4:24:35 PM
Hi Pete,

There are multiple OC functions that can perform the importing programmatically. The ImportFile function in the code I posted takes a filter file name as argument. There is also an ImportFile function that takes a filter tree as argument. If you use that function instead, you can load the filter first into a tree, then "change" the appropriate tree node to reorient the OC file needed to be coming from an OPJ attachment instead, and then call the ImportFile function with the modified filter tree.

From what you are trying to do, I think the following may be a simpler approach:
1> Get rid of the two-level filter system
2> Move all the code that writes out multiple sheets to ASCII and imports them one by one - the code that exists in the OC file associated with the first filter - move them to the OC file attached to the OPJ instead, and have your button call a function in the attached file.

Perhaps that would simplify things?

Easwar
OriginLab


peter.cook Posted - 07/12/2004 : 4:05:34 PM
Hi Easwar,

Thanks for code and quick response!

All works fine as expected.

One question - I would really like to set the path to the .C file as specified in the attached .oif file to also point to an attached .c file. I've messed around but had no luck. Can this be done - it would be really neat if it could.

Cheers,

Pete

Mike Buess Posted - 07/12/2004 : 3:26:31 PM
Hi Pete,

Just a note about your first point... If your Excel filter is in Origin's (or User's) Filters folder then (*.xls) should appear as a choice on the "Files of type:" list of the standard File->Open dialog. You can select multiple files with control+click or shift+click.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 07/12/2004 3:29:32 PM
easwar Posted - 07/12/2004 : 10:26:48 AM
Hi Pete,

You can call appropriate functions in OC to import a file using a specified filter, without having to go thru the Import Wizard interface.

In order to do this, you will first need to ensure that all necessary files are loaded into your workspace. You can do that with script (or use OC) such as below, attached to your button:


%a=system.path.program$;
i=run.loadoc(%aOriginC\OriginLab\ImportWiz.ocw);
if( 0 != i )
{
type -b Could not load import wizard workspace!;
return;
};


Then, once the above is done, you can call an OC function that will call the requisite import function.

Now, you also wanted to use either a generic filter, or a filter attached with the OPJ. You can do this by having your OC function do a FindFile on the subfolder that holds all attached files.

The following code segment shows you how to do that, and also call the import function. Note that you should include the fileimport.h header file in your OC file in order to call the import function.


#include <Origin.h>
#include <..\Originlab\fileimport.h>


void test()
{
// Create a worksheet to receive data from file
WorksheetPage wpg;
wpg.Create( "Origin.otp" );
Worksheet wks;
wks = wpg.Layers(0);

// Point to data file
string strDataFile ="your_path\your_file.xls";

// Check if a special filter exists, that is attached to the OPJ
string strFilterFile;
char szTemp[MAXFULLPATH];
lstrcpy( szTemp, GetProjectAttachedFilesPath() );
if( FindFile( "MultipleWorksheets.oif", szTemp ) )
{
// A filter attached to OPJ was found - set filter file to this one
strFilterFile = szTemp + "MultipleWorksheets.oif";
}
else
{
// No filter attached to OPJ was found - just use the generic one
strFilterFile = "point to your generic filter location";
}

// Now import the file by calling import function
int iRet = ImportFile( wpg, strFilterFile, strDataFile );
}


Easwar
OriginLab




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