Connecting Tech Pros Worldwide Forums | Help | Site Map

Writing table contents into a Text file

Newbie
 
Join Date: Jan 2008
Posts: 17
#1: Jan 21 '08
Hi All,
I have stored contents of a table as a variable as shown below:
partner_table = get_table("//table.1.1")

Now i need to write the contents of "partner_table" into a TEXT file.
There is should be some way, does it require file.open command!!

Hoping to hear from you soon.

Cheers
ideal

Expert
 
Join Date: May 2007
Posts: 213
#2: Jan 21 '08

re: Writing table contents into a Text file


Something like the following should work for you.
Expand|Select|Wrap|Line Numbers
  1. # Create new file called 'filename.txt' at a specified path.
  2. my_file = File.new("path/filename.txt","w")
  3. # Write text to the file.
  4. my_file.write "text to be written to file"
  5. # Close the file.
  6. my_file.close
Newbie
 
Join Date: Jan 2008
Posts: 17
#3: Jan 22 '08

re: Writing table contents into a Text file


Thanks for Code, it works fine :)
I have one more stuff to go with writing the text files,
My present output looks like this:

Upload Result\n filename status #Rows Quantity #Ignored #Deleted #Modified Messages FISCAL-CALENDAR.xls Loaded 140 0 0 0 0 On Hold 0 0 0 0 0

I rather like to see new line after each sentence, what should i do for that? Is there a way i can say to insert new line character after each sentence!
something like this-

Upload Result
filename status
#Rows Quantity
#Ignored

Cheers
Expert
 
Join Date: May 2007
Posts: 213
#4: Jan 22 '08

re: Writing table contents into a Text file


Use "\n" for a new line. Make sure its in double quotes, not single quotes. Using double quotes will output a new line, using single quotes will output the text \n.
Expand|Select|Wrap|Line Numbers
  1. my_file.write @table_cell.to_s + "\n"
Reply