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
 Forum for Origin C
 Add New Sheet and Rename
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Thomas83

24 Posts

Posted - 05/27/2013 :  05:08:01 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi.
I want to import files that are numbered in ascending order (e.g. file001, file002, ...). Files with odd numbers should be imported to the first worksheet, files with even numbers to the second worksheet. Worksheet 1 and 2 should be renamed after the import (e.g. "data1", "data2"). The code below imports files with odd numbers at first and than files with even numbers but in the same worksheet. I dont know how to create and rename a second worksheet to import files with even numbers. Can anyone help me please? The code is as follows:


void importfolder()
{
string strPath = "C:\\TEST\\";
StringArray saFiles;
FindFiles(saFiles, strPath, "*.txt");
if( saFiles.GetSize() < 1 )
return;

Worksheet wks = Project.ActiveLayer();
ASCIMP ai;
//Import files with odd numbers

AscImpReadFileStruct(strPath + saFiles[1], &ai);

ai.iMode = ASCIMP_MODE_APPEND_COLS;
ai.iHeaderLines = 7;
ai.iSubHeaderLines = 0;
ai.iRenameCols = 0;
ai.iPartial = 1;
ai.iPartialC1 = 4;
ai.iPartialC2 = 4;
ai.iPartialR1 = 0;
ai.iPartialR2 = 1000;
ai.iDelimited = 1;
ai.iDelimiter = ASCIMP_DELIM_DEMICOLON;
ai.nNumSep = NF_IS_EUROPEAN;
for(int j = 0; j < (saFiles.GetSize())/2; j++ )
wks.ImportASCII(strPath + saFiles[2*j+1], ai);

//Import files with even numbers
//I want to import these files to a new sheet. how?
AscImpReadFileStruct(strPath + saFiles[0], &ai);

ai.iMode = ASCIMP_MODE_APPEND_COLS;
ai.iHeaderLines = 7;
ai.iSubHeaderLines = 0;
ai.iRenameCols = 0;
ai.iPartial = 1;
ai.iPartialC1 = 4;
ai.iPartialC2 = 4;
ai.iPartialR1 = 0;
ai.iPartialR2 = 1000;
ai.iDelimited = 1;
ai.iDelimiter = ASCIMP_DELIM_DEMICOLON;
ai.nNumSep = NF_IS_EUROPEAN;
for(int i = 0; i < (saFiles.GetSize())/2; i++ )
wks.ImportASCII(strPath + saFiles[2*i], ai);

}

Thanks in advance.

PS: I just started programming in Origin.

Penn

China
644 Posts

Posted - 05/29/2013 :  10:18:45 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

In your code, you are using the same worksheet for importing both odd and even files. So, in such way, of course it will import both add and even files into the same worksheet.

To add a new worksheet, see AddLayer method.
To rename the worksheet, see SetName method.

Penn
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