0

I have a java code that replaces name from names column in excel. I want code to be dynamic like:

Dear $name

Your code is $code,

However I am not supposed to use %s as I am not sure of column sequence. How can I do it. Thanks in advance

dpkcs
  • 91
  • 1
  • 4
  • 1
    How you do this currently, show your code please – Yu Jiaao Jun 12 '17 at 11:18
  • The template would look like EMAIL_BODY_TEXT="Dear %s,

    " + "In Referenece to our conversation on 12-12-1093, I would like to offer you a discount of %s
    " + "Hope u had a pleasant experience

    " + "Thanks and Regards,
    " + "******* " . To call this , the code would be String message=String.format(EMAIL_BODY_TEXT,"xyz","123"); the value xyz and 123 are read from excel sheet. But I need to add $name which is linked to name column of excel sheet.
    – dpkcs Jun 12 '17 at 11:41
  • Please update the question with your comment's content. – Markus Jun 12 '17 at 12:46
  • Possible duplicate: https://stackoverflow.com/questions/3655424/string-replacement-in-java-similar-to-a-velocity-template – Markus Jun 12 '17 at 12:46
  • Thanks Markus, It helped a bit. But real issue is mapping of excel column .For example is there any way that I can link one column of table say emailId to ${emailId} of string subsr.?? Or I have to parse each row and give value at run time?? valuesMap.put("email", emailMetaData.getEmailId()); valuesMap.put("fname", emailMetaData.getFirstName()); valuesMap.put("lname", emailMetaData.getLastName()); valuesMap.put("ccode", emailMetaData.getCouponCode()); StrSubstitutor sub = new StrSubstitutor(valuesMap); String EMAIL_BODY = sub.replace(emailBody); – dpkcs Jun 13 '17 at 04:53

0 Answers0