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
 SetCell function and multiple variable types
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

jweinber

USA
Posts

Posted - 08/11/2005 :  11:34:00 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5
Operating System: XP

Hi, I'm trying to write my first origin c code and I'm having a problem. I am trying to combine a whole bunch of different worksheets (all in the same folder in project explorer) onto one worksheet.

I started by copying the first worksheet, so that I would have the correct designations and formats for the columns, and then just wanted to write out the cells for all the rest of the worksheets. All numerical values are being copied just fine, but the text values are not, I just get a - for all those fields.

I'm sure there is a more elegant way to write the code, but this is what I have done: Can setcell not change the cast for the third parameter back and forth?

Thanks for any help/suggestions!

Jennifer


// Combine selected worksheets (from the active folder in project explorer) into one worksheet.

void CombineWks()

{

StringArray sa;

GetWksList(sa);

Worksheet wks;
Worksheet SummaryWks;
int nRows=0;
int rows;
int col;


for(int i=0;i<sa.GetSize();i++) {

wks.Attach(sa[i]);

if (i==0) {
SummaryWks.CreateCopy(wks);
}
else {
nRows +=wks.GetNumRows();
}
}
ASSERT(SummaryWks.AppendRows(nRows));

for (i=0; i<sa.GetSize();i++) {
wks.Attach(sa[i]);
if (i==0) {
nRows=wks.GetNumRows();
}
else {
for (rows=0; rows<wks.GetNumRows();rows++) {

for (col=0;col<wks.GetNumCols(); col++) {

SummaryWks.SetCell(nRows, col, wks.Cell(rows,col));
}
nRows++;
}
}
}


SummaryWks.GetPage().Refresh(TRUE);

}

easwar

USA
1965 Posts

Posted - 08/11/2005 :  11:47:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Jennifer,

The problem is not with SetCell, which is overloaded and can handle both double and string, but with the argument that you pass to it.

You are using
SummaryWks.SetCell(nRows, col, wks.Cell(rows,col));

where the wks.Cell() method assumes what you are getting is double. To get string there is a wks.TCell() method.

Easwar
OriginLab


Go to Top of Page

jweinber

USA
Posts

Posted - 08/11/2005 :  12:18:34 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks. Is there a function that will read either a double or a string? I have both types in my worksheets that I am trying to copy, or would the best thing be to use an OR statement?

Thanks!
Jennifer
Go to Top of Page

easwar

USA
1965 Posts

Posted - 08/11/2005 :  12:57:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Jennifer,

I see that earlier you posted in general forum and you are working with the PFM report worksheets?

I see that with the PFM report sheets, the column type is set to Numeric for columns that contain numbers such as peak centroid and other columns are either Text or Text&Numeric.

So one option is to check in the code what is the column type for the cell that you are copying - you know the col index and so can declare a col object with that and check the GetType() property - and then switch in your code based on what type it is?

Easwar
OriginLab


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