T O P I C R E V I E W |
smordi |
Posted - 03/10/2009 : 09:53:42 AM winXP Prof, Origin Pro 8
Hi, I have two workbooks created. One is filled with ImportASCII, and now I want to copy all columns of, let's say row 10-230 to a new workbook. The creation and the importing works fine, I just don't know how to copy it. Probably possible with a lot of Datasets, but there must be an easier way as I want to copy ALL columns.
Thanks for any suggestions, I'm really lost here :)
Greetings from Budapest Steffen |
7 L A T E S T R E P L I E S (Newest First) |
additive |
Posted - 12/15/2009 : 2:11:29 PM Thanks to OriginLab, they've updated the CopytTo method in version 8.1 SR0. You can set the destination row using the optional argument nDestR1:
int CopyTo( Worksheet & wksDest, int nC1, int nC2, int nR1, int nR2, int nDestC1, int nLNRow = -1,
DWORD dwCntrl = CPYT_EXTERN_UPDATE_ORIGIN, int nDestR1 = 0, vector<int>* pvnLabelTypes = NULL )
Hope this helps!
Michael |
malkovich |
Posted - 12/15/2009 : 05:44:25 AM Hi Iris,
thank you for your help, it works now. But one more question: I want to specify the row of the destination worksheet to copy different rows of the source wks to consecutive rows of the destination wks. I modified the code to:
void Worksheet_CopyTo_Ex2(int Row1 = 0, int Row2 = 1)
{
Worksheet wksSrc, wksDest;
if( wksSrc.Attach("Book1") && wksDest.Attach("Book2") )
{
int nC1 = 0, nC2 = wksSrc.GetNumCols()-1; //want to copy all columns
int nR1 = Row1, nR2 = Row2; // want to copy rows 10-230
int nDestC1 = 0; // copy data to destination worksheet start from the first column
DWORD dwCtrl = CPYT_COPY_COLUMN_FORMAT | CPYT_COPY_COLUMN_DESIGNATIONS; // want to keep column format and designations with copied data
int nRet = wksSrc.CopyTo(wksDest, nC1, nC2, nR1, nR2, nDestC1, -1, dwCtrl);
}
else
{
out_str("error attaching worksheets");
}
}
I first create two Workseets "Book1" and "Book2", type some numbers into cells of Book1 and then execute the function.
Now I need a parameter to copy first Book1 row 1 to Book2 row 1 and the let's say Book1 row 3 to Book2 row 2 and so on. How can I do this?
Greetings and Thanks in advance |
Iris_Bai |
Posted - 12/14/2009 : 9:44:36 PM Hi,
Please take a look on the sample code Laurie posted above, nR2 = 230, if source worksheet not have 230 rows, CopyTo function will do nothing except prepare the number of column. This is bug, tracker as #14850, we should always copy data from nR1 to last row if nR2 over the number of rows of worksheet.
For now, you can set nR2 = -1, -1 means last row.
If still not work, please send your data file or *ogw file to us according to Sending a File to OriginLab Technical Support
Iris |
malkovich |
Posted - 12/14/2009 : 09:04:02 AM Hello Iris,
thanks for your reply. I tried this already but it does not work. The function CopyTo does not seem to work for me, no matter what parameters I use. The sample code Laurie posted does not copy the worksheet contents but only creates a new worksheet with the same numbers of comlumns as the current worksheet. The funtion is not described in the help files so I have no idea what I can try instead. |
Iris_Bai |
Posted - 12/13/2009 : 8:52:01 PM Hi,
If you want to copy one row, for example, the first row in source worksheet, please set r1=0 and r2=1. r2 is the ending row index, default is -1 for last row and exclusive.
Iris |
malkovich |
Posted - 12/11/2009 : 05:36:49 AM WinXP pro., Origin 8G.0.63.988 SR6 v8.0988
I tried to use CopyTo to copy a row from one worksheet to another, but it does not work. It should copy six times one row. The function always returns "0", and copies one row of the source worksheet to the first row of the dest worksheet. Also it copies a row of the source wks to the "longname" row of the dest wks. When I execute the example of Laurie Origin creates a new worksheet with the correct numbers of cols but not enough rows and copies nothing.
Any idea? |
Laurie |
Posted - 04/01/2009 : 1:58:51 PM
void Worksheet_CopyTo_Ex1()
{
Worksheet wks = Project.ActiveLayer();
if(wks)
{
Worksheet wksDest;
wksDest.Create("origin");
int nC1 = 0, nC2 = wks.GetNumCols()-1; //want to copy all columns
int nR1 = 9, nR2 = 230; // want to copy rows 10-230
int nDestC1 = 0; // copy data to destination worksheet start from the first column
DWORD dwCtrl = CPYT_COPY_COLUMN_FORMAT | CPYT_COPY_COLUMN_DESIGNATIONS; // want to keep column format and designations with copied data
int nRet = wks.CopyTo(wksDest, nC1, nC2, nR1, nR2, nDestC1, -1, dwCtrl);
}
}
OriginLab Technical Support |
|
|