As in the following sreenshots, roughly speaking, Out[43] is CellObject[97601].

enter image description here enter image description here

I want to set var1 = the content of CellObject[97601]. So that

In[44] var1=SomeFunction[CellObject[97601]]
Out[44] 123456789101112

But I do not know how to get the content of CellObject[97601]. How can I construct SomeFunction?


Thank you, Michael E2, it works well :

enter image description here

Copy As Cell Object : CellObject[99121]

enter image description here

Similar method does not work for Text Cell. But the solution is simpler :

enter image description here


1 Answer 1


NotebookRead gives the cell expression (see the first example in the docs for CellObject); ToExpression can convert the boxes:

  RowBox[{"Integrate", "[", 
    RowBox[{RowBox[{"1", "/", SqrtBox[RowBox[{"1", "-", "x"}]]}], ",",
       "x"}], "]"}]], "Input", CellChangeTimes -> {3.86329*10^9}]

 First@First@NotebookRead[cobj], StandardForm, HoldComplete]

(*  HoldComplete[\[Integral]1/Sqrt[1 - x] \[DifferentialD]x]  *)

The cell read was an input cell containing Integrate[1/Sqrt[1 - x], x], but ToExpression does convert boxes to InputForm.

  • $\begingroup$ Thank you, NotebookRead is important. $\endgroup$
    – imida k
    Commented Jun 4, 2022 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.