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
 Range String Pointing to a Worksheet Text Cell
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cdrozdowski111

USA
247 Posts

Posted - 08/06/2013 :  07:18:28 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
OriginPro 9.0.0 SR2 64-bit, Win7 64-bit, running in VMware Fusion 5.0.3

I'm working on an OC function that puts text into a worksheet text cell. A string param containing the range to the cell is passed into the function as well as the text to put in the cell.

How can I determine if the range string points to a valid text cell? And how do I add the text to the cell?


void myText2Cell(string strCellRng, string strText)
{
	// Determine if the string strCellRng points to a valid text cell in a worksheet

	// If so, put strText in that cell
}

Edited by - cdrozdowski111 on 08/06/2013 07:18:49 AM

Penn

China
644 Posts

Posted - 08/06/2013 :  10:44:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Maybe you need to parse the range string to judge if it points to a valid cell. You can refer to the following example.

void myText2Cell(string strCellRng = "[Book1]1!Col(B)[2]", string strText = "My Text")
{
	bool isValid = false;  // whether the cell range is valid
	DataRange dr;
	int nn = dr.Add("X", strCellRng);  // try to add data range by using the range string
	if(nn > 0 && !dr.IsEmpty())  // if added successfully
	{
		int nrc[4];
		Worksheet wksRet;
		// find the worksheet, row index, column index
		if(find_input_range_bounding_box(dr, nrc[0], nrc[1], nrc[2], nrc[3], wksRet, 0, "X"))
		{
			int nRows = wksRet.GetNumRows();  // number of rows in worksheet
			Column col(wksRet, nrc[1]);  // column
			if(col && nRows > nrc[0])  // if column is valid, and row is valid
			{
				isValid = true;  // set to true
				wksRet.SetCell(nrc[0], nrc[1], strText);  // set string to cell
			}
		}
	}
	if(!isValid)
	{
		printf("%s is not a valid range to the cell!", strCellRng);
	}
}


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