Continue to use Hiroto's solution, as it is working for you.
I wanted to revise/finish what I started earlier. The updated script now expects name and replacement data from the Excel spreadsheet, as it will use these to construct a proper key/value pair dictionary. The script extracts the "B_nn" fields that it finds in the input HTML file — into a third list. It is this list that is used to match its items to keys in the dictionary, and sets the replacement string from the matched value. If there are redundancies in the HTML, these are handled accurately.
For use on OS X Yosemite (10.10.*) and later.
Code:
use scripting additions
use framework "Foundation"
use AppleScriptversion "2.4" -- Yosemite or later
set the_desktop to ((path to desktop) as text) as alias
set infile to (choose file of type {"public.html"})'s POSIX path
set outfile to (choose file namewith prompt "Output HTML File:" default name ¬
"out.html" default location the_desktop)'s POSIX path
(*
-- if this works, use it to set the Excel keys (xx) and values (yy)
tell application "Microsoft Excel"
tell active sheet's range "B1:B38"
set {xx, yy} to every cell's {name, value}
end tell
end tell
*)
-- test data can be removed with working Excel keys and values solution
set xx to {"B_1", "B_2", "B_3", "B_4", "B_5", "B_6", "B_7", "B_8", "B_9", "B_10", "B_11", "B_12", "B_13", "B_14", "B_15", "B_16", "B_17", "B_18", "B_19", "B_20", "B_21", "B_22", "B_23", "B_24", "B_25", "B_26", "B_27", "B_28", "B_29", "B_30"}
set yy to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4"}
-- get actual "B_nn" fields in the HTML to drive find/replace process
set hkeys to words of (do shell script "sed -En 's/^.+\\>(B_[0-9]+)\\<.+/\\1/p' " & infile)
set myHTML to read (POSIX file infile as alias)
-- make the AppleScript lists into Objective-C Arrays
-- me's is a shorthand for the customary current application's
set excel_keys to me's NSArray'sarrayWithArray:xx
set excel_values to me's NSArray'sarrayWithArray:yy
set html_key to me's NSArray'sarrayWithArray:hkeys
-- make an Objective-C dictionary from Excel keys and values range data
set kvmDict to me's NSDictionary'sdictionaryWithObjects:excel_valuesforKeys:excel_keys
-- Use the HTML "B_nn" fields as dictionary lookup keys for matching replacement values
-- Handles field redundancies in the HTML document
repeat with ndx from 0 to ((html_key's |count|()) - 1)
set findStr to (html_key'sobjectAtIndex:ndx) as text
set replaceStr to (kvmDict'sobjectForKey:findStr) as text
set srcString to (me's NSString'sstringWithString:myHTML)
set loc to (srcString'srangeOfString:findStr)
set myHTML to (srcString'sstringByReplacingCharactersInRange:locwithString:replaceStr) as text
-- log (findStr & tab & replaceStr) as text
end repeat
-- write out replacement HTML
set replaced to open for access (outfile as POSIX file) with write permission
set eofreplacedto 0
write (myHTML as text) toreplaced
close accessreplaced
return