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