Message Boards Message Boards

0
|
5357 Views
|
7 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to export a string from one notebook to another?

Posted 2 years ago

I have a notebook called CardManipulation2.nb

it contains data, a list of 101 strings

I would like to move (Export?) data [[1]] to notebook CardManipulation1.nb

I also have a notebook titled (perhaps incorrectly) "X2382901".nb

and would like to move data [[13]] to it

I can't find the proper incantation to accomplish. I've tried a bunch of Export* 's

POSTED BY: Lewis Robinson
7 Replies
Posted 2 years ago

Rohit

Xref.nb does exist. I created it using the file menu

All I did to get

XRef = NotebookOpen[FileNameJoin[{Directory[], "XRef.nb"}], Visible -> False]

Was take your example

X2382901 = NotebookOpen[FileNameJoin[{Directory[], "X2382901.nb"}], Visible -> False];

And replace X2382901 by Xref and replace X2382901.nb by Xref.nb

So I'm assuming that

FileNameJoin[{Directory[], "XRef.nb"}] 

exists

Once again, thanks for your patience with me.

POSTED BY: Lewis Robinson
Posted 2 years ago

This works fine, which is the same as the code in the answer above except that there is no symbol the string is set to.

xRefcardTitle = "XREF \"X2383901\" 2580879";
XRef = NotebookOpen[FileNameJoin[{Directory[], "XRef.nb"}], Visible -> False]
SelectionMove[XRef, After, Notebook];
NotebookWrite[XRef, Cell[ToString[xRefcardTitle, InputForm], "Input"]]

Does this file exist?

FileNameJoin[{Directory[], "XRef.nb"}]

Please learn how to format code in your questions. Read the "Post Editor" and "Code Formatting" sections here.

POSTED BY: Rohit Namjoshi
Posted 2 years ago

Apologies to all for repeating a question, but I have been unable to get the replies to work

The following two commands did work

XRef = NotebookOpen[FileNameJoin[{Directory[], "XRef.nb"}], 
   Visible -> False];
SelectionMove[XRef, After, Notebook];

I have a string variable defined as follows

xRefcardTitle = "XREF " <> cardName <> " " <> cardID

Which yields -- "XREF \"X2383901\" 2580879"

The following fails

NotebookWrite[XRef, Cell[xRefcardTitle , "Input"]]
xRefcardTitle

Yielding

NotebookWrite[$Failed, Cell["XREF \"X2383901\" 2580879", "Input"]]

How do I write this simple string variable (xRefcardTitle) to Xref.nb ?

POSTED BY: Updating Name

Here I move a list of 101 strings into a new notebook:

CreateDocument[ExpressionCell[RandomWord[101]]]

You could also insert into an existing notebook.

POSTED BY: Gustavo Delfino
Posted 2 years ago

To append to an existing notebook

list = RandomWord[5]

(* Open existing notebook *)
X2382901 = NotebookOpen[FileNameJoin[{Directory[], "X2382901.nb"}], Visible -> False];

(* Move selection point to end of notebook *)
SelectionMove[X2382901, After, Notebook];

(* Insert *)
NotebookWrite[X2382901, Cell["list = " <> ToString[list, InputForm], "Input"]]

(* Save *)
NotebookSave[X2382901]
POSTED BY: Rohit Namjoshi

You can also use Iconize[ ]. The resulted object is easy to copy, paste and saved in any notebook.

POSTED BY: Ahmed Elbanna
Posted 2 years ago

Look at the documentation on DumpSave and Get. You could use them to transfer the entire list. You could also transfer a particular string by assigning it to a separate symbol. Kind regards, David

POSTED BY: David Keith
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract