can't render to string type...

Hi,

I’m getting data from Excel sheet (A1:E1) and replace var names (varr1, varr2…varr5) in text file with these data.
The first step seems to work (thanks to you) … as I can see cells values in the error message :°)
"Error in MSExcel : can’t render {{“value of A1”,“value of B1”,“value of C1”,“value of D1”,“value of E1”}} to string type. (approximate translation of the message).

tell application "BBEdit" to open file "Macintosh HD:Users:me:testApplescript.xml"

tell application "Microsoft Excel"
	tell active sheet
		set myArray to get value of (get range "A1:E1")
	end tell
end tell
set N to 1

repeat with N from 1 to 5 -- 
	set search_strings to "varr" & N -- search vars (varr1, varr2...varr5) in text file
	set replace_strings to {(item N of myArray)} -- set replacement values to "value of A1","value of B1"..."value of E1
end repeat

tell application "BBEdit"
	activate
set x to 1

	repeat with x from 1 to count search_strings 
		tell application "BBEdit"'s document 1
			replace (search_strings's item x) using (replace_strings's item x) searching in it ¬
				options {returning results:0} saving no
		end tell
	end repeat
end tell

Any idea of what I did wrong?
(Excel 2008)

Thanks for your help

Phil

Hi,

the error message indicates that you’re using a nested list as parameter.
Consider that Excel returns a matrix (list of lists) from “value of range”

The first repeat loop seems to be useless because you’re assigning 5 times a different value to the variables.
The values of the first 4 iterations are lost.

You probably mean this


set search_strings to {} -- defines variables as list
set replace_strings to {}
set flattenedArray to item 1 of myArray -- removes the outer list
repeat with N from 1 to 5 -- 
	set end of search_strings to "varr" & N -- search vars (varr1, varr2...varr5) in text file
	set end of replace_strings to (item N of flattenedArray) -- set replacement values to "value of A1","value of B1"..."value of E1
end repeat

Hi StefanK,

Thanks for your response.
You’re right, that’s exactly what I saw when continuing to work on it !
I’ve succeeded to replace only the varr5 in the text file… but only with the whole list of the first range, and the 4 first vars where lost, indeed.
Your script works fine at the first try !
That’s the first step of the program; now I’ll try to use the data in myArray to change placeholders in others opened text files, getting the name of the desired text file in the first cell of each row. Not won.

Thanks again

Regards

Phil