Author |
Topic  |
|
peter.cook
UK
356 Posts |
Posted - 05/04/2004 : 04:22:34 AM
|
Hi,
Can anyone please suggest the best (any?!) way to copy text datasets using Origin C.
Case in point is simply to copy eg all of text format column Col(1) to text column Col(2).
I have no problems with text and numeric but I tend to use text datasets.
I think the problems stem from being unable to assign an Origin C Dataset or vector to an Origin text column.
Thanks,
Cheers,
pete
|
|
rlewis
Canada
253 Posts |
Posted - 05/04/2004 : 10:27:18 AM
|
Hi Peter ...
The combination of the OriginC functions listed below seems to work. Perhaps it might do what you want. bool CopyTextColumn(Column source, Column Dest) { // Callable form OriginC if(source.GetFormat()==OKCOLTYPE_TEXT) { Dest.SetFormat(OKCOLTYPE_TEXT); Dest.SetNumRows(source.GetNumRows()); string dsSource=source.GetDatasetName(); string dsDest=Dest.GetDatasetName(); string strLTCommand; strLTCommand.Format("copy "+dsSource+" "+dsDest); LT_execute(strLTCommand); return (true); } return (false); }
bool CopyWksTextCol(string wksName, int SourceCol, int DestCol) { //Callable from LabTalk and OriginC if(SourceCol!=DestCol) { Worksheet wks; if(wks.Attach(wksName)) { Column source, Dest; if(source.Attach(wks, SourceCol) && Dest.Attach(wks, DestCol)) { if(CopyTextColumn(source, Dest)) { return (true); } } } } return (false); }
|
 |
|
peter.cook
UK
356 Posts |
Posted - 05/04/2004 : 11:01:14 AM
|
Hi Ruthven,
Thanks for reply.
Essentially then you have to use the labtalk copy command..
Is there no 'pure C' way to do this?
Cheers,
pete
|
 |
|
rlewis
Canada
253 Posts |
Posted - 05/04/2004 : 11:21:05 AM
|
One can also use the a combination of Worksheet.GetCell() and Worksheet.SetCell() function calls within a loop to do the same thing. However, the above approach is faster (at least on my machine) |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 05/04/2004 : 11:57:15 AM
|
This should work but I haven't actually tried it...
Worksheet wks = Project.ActiveLayer(); Dataset ds1(wks,0); Dataset ds2(wks,1); StringArray sa; ds1.GetStringArray(sa); ds2.PutStringArray(sa);
Mike Buess Origin WebRing Member |
 |
|
rlewis
Canada
253 Posts |
Posted - 05/04/2004 : 12:31:21 PM
|
I just tried Mike's approach using the following ... bool CopyTextColumn(Column source, Column Dest) { if(source.GetFormat()==OKCOLTYPE_TEXT) { Dest.SetFormat(OKCOLTYPE_TEXT); Dest.SetNumRows(source.GetNumRows()); string dsSource=source.GetDatasetName(); string dsDest=Dest.GetDatasetName(); Dataset sourceD, DestD; if(sourceD.Attach(dsSource) && DestD.Attach(dsDest)) { StringArray sa; sourceD.GetStringArray(sa); DestD.PutStringArray(sa); return (true); } } return (false); }
However this approach fails because the test condition .. "if(sourceD.Attach(dsSource) && DestD.Attach(dsDest))" always fails when the Worksheet column is set as "Text". However, it works when the Worksheet column is set as "Text and Numeric" (i.e Peter's Original concern) |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 05/04/2004 : 1:12:11 PM
|
I see what you mean. So the real solution to Pete's problem is to set the Format for both columns to Text&Numeric (OKCOLTYPE_TEXT_NUMERIC) first, copy using any method that works for datasets and changing them back to OKCOLTYPE_TEXT (if necessary) when done.
Mike Buess Origin WebRing Member |
 |
|
rlewis
Canada
253 Posts |
Posted - 05/05/2004 : 12:47:02 AM
|
Yup ... The following "pure OriginC" approach seems to work quite well ...
bool CopyTextNumericColumn(Column source, Column Dest) { // Callable from OriginC if(source.GetFormat()==OKCOLTYPE_TEXT_NUMERIC) { Dest.SetFormat(OKCOLTYPE_TEXT_NUMERIC); Dest.SetNumRows(source.GetNumRows()); string dsSource=source.GetDatasetName(); string dsDest=Dest.GetDatasetName(); Dataset sourceD, DestD; if(sourceD.Attach(dsSource) && DestD.Attach(dsDest)) { StringArray sa; sourceD.GetStringArray(sa); DestD.PutStringArray(sa); return (true); } } return (false); }
bool CopyWksColumn(string wksName, int SourceCol, int DestCol) { //Callable from LabTalk and OriginC if(SourceCol!=DestCol) { Worksheet wks; if(wks.Attach(wksName)) { int SourceFormat=wks.Columns(SourceCol).GetFormat(); wks.Columns(SourceCol).SetFormat(OKCOLTYPE_TEXT_NUMERIC); wks.Columns(DestCol).SetFormat(OKCOLTYPE_TEXT_NUMERIC); Column source, Dest; if(source.Attach(wks, SourceCol) && Dest.Attach(wks, DestCol)) { if(CopyTextNumericColumn(source, Dest)) { source.SetFormat(SourceFormat); Dest.SetFormat(SourceFormat); return (true); } } } } return (false); }
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 05/05/2004 : 11:22:15 AM
|
I think that the Dataset class should be fixed to handle Text formatted columns or else this limitation should be pointed out more clearly in the documentation. For example, Dataset::GetStringArray speaks of "Text Datasets" which can be miscontrued as allowing datasets attached to Text formatted columns. Granted, the Dataset entry includes this line...quote: Dataset is a template class with a default type of double but a Dataset of any basic data type (including char, byte, short, word, int, and uint but not string) can be constructed using the syntax Dataset<type>.
but I believe the matter requires more emphasis.
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 05/05/2004 11:28:57 AM |
 |
|
peter.cook
UK
356 Posts |
Posted - 05/10/2004 : 09:05:58 AM
|
Hi Mike, Ruthven,
Thanks for your thoughts.
I really would like to see text datasets better handled generally!
I don't believe the changing format to text and numeric is always appropriate as I'm then back to the old problem of numeric formatting and missing values which is why I often use text datasets.
Cheers,
Pete
|
 |
|
|
Topic  |
|