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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Exporting all worksheets in active workbook
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

KMnO4aq

3 Posts

Posted - 12/01/2014 :  11:41:46 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 8.5.0
Operating System: Windows XP running on Parallels on my Mac


I am trying to export all of the worksheets in my active workbook to a specific directory. I have tried:

fdlog.openpath(B); // choose directory
doc -e W {save -w %H %B%H.txt};

But this only saves the first worksheet in each workbook. Any ideas?

cdrozdowski111

USA
247 Posts

Posted - 12/02/2014 :  07:55:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Here is some code that saves every worksheet in the active workbook. It is much more complex but is also more robust (better folder dialog, error checking, etc)

int count;
doc -cw;	// Count the number of pages in project
if (count == 0)	// Make sure there is at least one
{
	// Output message and stop script
	type "There are no workbooks in project.";
	return;
}

string sPageName$ = page.name$;	// Get the short name of the active page (window)

if (exist(%(page.name$), 2) != 2)	// Make sure sure active page is a workbook.
{
	// Output message and stop script
	type "Current Window is not a workbook.";
	return;
}

string sPath$;
dlgPath -sb path:=sPath title:="Choose a Folder" showfiles:=0;	// This X-function is better than fdlog. It has more options if you are interested.
if (sPath.GetLength() == 0)	// If user clicked Cancel button, sPath$ will be empty.
{
	// Output message and stop script
	type "Operation Cancelled";
	return;
}

// User selected a folder, so continue script
for (int ii = 1; ii <= page.nlayers; ii++)	// Loop through every layer (worksheet) in active page (workbook).
{
	page.active = ii; // Activate layer (worksheet).
	string sFile$ = "%(sPath$)\%(page.name$)%(layer.name$).txt";	// Create full path to the file name to save the worksheet.
																 	// The "layer" variable is an object that represents the
																	// currently active layer (worksheet).
	save -w %(layer.name$) "%(sFile$)";	// Save the worksheet into the file.
}

type "All worksheets in active workbook exported";


Note: If you are so inclined, the expASC X-function (http://www.originlab.com/doc/X-Function/ref/expASC) offers much more control over your data export than the save command.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000