Quote become " on PHPExcel - phpexcel

I'm using PHPExcel to export data into excel report. But the below characters are being altered.
" become "
& become &
Example:
"The Company" --> become "The Company"
Me & My Company --> become Me & My Company
Can anyone help me on how can I fix it. Thanks!!

Double-check the strings that you are passing to PHPExcel to make sure that they don't already have the HTML elements in them. Note that if you are debugging by dumping output to your browser then the string in your PHP code may actually already be
This & That
but the browser will display it as
This & That.

Related

ASP Classic CDOSYS Email via HTMLBody format

I have an issue sending an email using CDOSYS messaging system in ASP Classic using HTMLBody format. It seems to have a character limit, and when the email message is being sent, it cuts the message off around the bottom of the email. At first, I thought the message was being sent before the entire email could be written, but then after some troubleshooting and research, there is some sort of CDOSys message character limit when using HTMLBody. My question is, is there any way to override the character limit or get around the restriction? This is only for HTMLBODY.
EDIT: The "duplicate" flag would not have helped me. This is not a truncation issue, but an issue with HTMLBody limitations that prevent lengthy messages from fully being sent in the message. I checked that article and it was not what I was looking at an answer to. The responses on this thread were sufficient in answering my question. Thank you all.
Here is my code:
Set myMail=CreateObject("CDO.Message")
HTML = HTML & "<html>"
HTML = HTML & "<body>"
HTML = HTML & "<font face='calibri'>"
HTML = HTML & "<img src='http://" & SupportTagURLWebPath & "/images/SkypeEmailHeader.png'>"
HTML = HTML & "<br><Br>"
HTML = HTML & "<font face='calibri'>"
HTML = HTML & "<b>To " & Request.Form("SkypeTemplateName") & ":</b>"
HTML = HTML & "<br><br>"
HTML = HTML & "Thank you for contacting the Bank of America Service Desk. We're committed to providing seamless support in the moments that matter."
HTML = HTML & "<br><br>"
HTML = HTML & "We heard your concerns with Skype for Business audio/video, and recommend using approved Skype for Business devices to resolve the issue."
HTML = HTML & "<br><br>"
HTML = HTML & "<h4><font color='red'>What do I need to do?</font></h4>"
HTML = HTML & "<div style='background-color: #FFF8DC;'>"
HTML = HTML & "1. Visit the <a href='http://u.go/pchk'>Skype for Business Peripheral Checker</a> & complete the form.<br>"
HTML = HTML & "<img src='http://" &SupportTagURLWebPath & "/images/SkypeEmailbody.png'><br>"
HTML = HTML & "4. Once approved, your new device(s) will be shipped to you. To get started, visit the <a href='http://u.go/tIxvB5'>Skype for Business page</a> and select <i>Setup your equipment</i> tab."
HTML = HTML & "</div>"
HTML = HTML & "<br><br>"
HTML = HTML & "<br>"
HTML = HTML & "If you still encounter Skype for Business audio/visual issues with your new device(s), please <a href='http://u.go/7I76vm'>submit a web ticket</a> and one of our expert Bank of America Service Desk employees will reach out to you."
HTML = HTML & "Thank you,"
HTML = HTML & "<br>"
HTML = HTML & "Premium Service Desk"
HTML = HTML & "<br><Br>"
HTML = HTML & "<img src='http://" & SupportTagURLWebPath & "/images/SkypeEmailFooter.png'>"
HTML = HTML & "</font>"
HTML = HTML & "</body>"
HTML = HTML & "</html>"
myMail.Subject= "Skype for Business audio/visual experience"
myMail.From=EMAILADDRESS
myMail.To=Request.Form("SkypeTemplateEmail")
'mymail.CC= Request.Form("displayemail")
myMail.BCC="psd.wmwhc#bao.com"
myMail.ReplyTo="Do Not Reply"
'myMail.TextBody="This is a message."
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="amta3dns.bo.com"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail.Configuration.Fields.Update
'myMail.TextBody= Request.Form("genfeedback")
myMail.HTMLBody=HTML
myMail.Send
set myMail=nothing
It is a line length issue. Without the crlf you blow out the max length at 998 characters. Best thing to do would be to write a function that splits the content in mid-string, avoiding the html tags. HTML text, e.g. in a para, ignores line breaks.
The RFC says
There are two limits that this standard places on the number of
characters in a line. Each line of characters MUST be no more than
998 characters, and SHOULD be no more than 78 characters, excluding
the CRLF.
The 998 character limit is due to limitations in many implementations
which send, receive, or store Internet Message Format messages that
simply cannot handle more than 998 characters on a line. Receiving
implementations would do well to handle an arbitrarily large number
of characters in a line for robustness sake. However, there are so
many implementations which (in compliance with the transport
requirements of [RFC2821]) do not accept messages containing more
than 1000 character including the CR and LF per line, it is important
for implementations not to create such messages.
The more conservative 78 character recommendation is to accommodate
the many implementations of user interfaces that display these
messages which may truncate, or disastrously wrap, the display of
more than 78 characters per line, in spite of the fact that such
implementations are non-conformant to the intent of this
specification (and that of [RFC2821] if they actually cause
information to be lost). Again, even though this limitation is put on
messages, it is encumbant upon implementations which display messages
Thanks go to the blog at emailonacid for the pointer.
I was able to figure it out via another thread doing a google search. If you place the below line for every 3-5 lines of the email message, it seems to "reset" or loop the number limit back to the beginning without changing the format of the email. I am not sure if this is the correct way of handling it, but it seems to work for a number of messages I created today which have pretty lengthy messages that would otherwise be cut off when the message is sent. I hope this helps anyone else with this issue.
HTML = HTML & vbCrLf
Instead of inserting the message body in the script and using a lot of HTML = HTML & "text goes here", I created an actual HTML file and read each line in to the HTMLBody:
Set myFSO=Server.CreateObject("Scripting.FileSystemObject")
' Read Email Template File
Set myFile=myFSO.OpenTextFile(Server.MapPath("..\msg\"+Request.Form("Template")+".html"), 1)
EmailBodyTemplate=""
Do While myFile.AtEndOfStream=False
EmailBodyTemplate=EmailBodyTemplate&myFile.ReadLine
Loop
myFile.Close
Set myFile=Nothing
Set myFSO=Nothing
myMail.HTMLBody=EmailBodyTemplate
Not only will this automatically place a vbCrLf at the end of each line read in from the file but it also makes the function generic so that you can send any email you wish by changing the template name.

Write a file containing ASP delimiters

We have lots of files containing image / static file references to resources on our site. As we are moving these files to S3 hosting, I am writing a script that reads each of our ASP files, replaces each reference so that each one points at a globally defined variable, and rewrites those changes to the file, so that we don't have to update all these files manually!
This works alright with references inside actual code.
eg.
Response.Write "<img src=""http://www.site.com/images/image.gif"">"
becomes
Response.Write "<img src=""" & s3BucketName & "/images/image.gif"">"
But when it comes to replacing code like this :
<script src="/javascript/script.js">
It's more difficult - as we have to place the ASP delimiters <%= %>
around the global var around it.
eg.
<script src="<%=s3BucketName%>/javascript/script.js">
Because the script delimiters actually stop the page where they are, and generate an error, that's what I'm finding difficult. URLencoding the <%=s3BucketName%> string, and writing, just writes the encoded text (unusable by ASP), doesn't transform into what I want.
Any ideas gratefully received.
Thanks, Adam
Ok, I've come up with a solution, seems to work. If you find a better one, please comment.
textToReplace = "src="""& chr(60) & chr(37) & chr(61) & "s3BucketName" & chr(37) & chr(62) & "/javascript/script.js"
Basically each symbol of <%= and %> is converted into chr() values.
You could use the basetag in the head section of your pages then you can leave the relative urls like your script example alone, you can combine this technique with the one peedeeaay suggests.
<base href="http://www.s3bucketdomain.com/directory/" />

Using a variable from a VBScript in a ASP.Net website

I've been researching this for a majority of the day and can't find the answer. I am relatively new to stackoverflow. Is there a certain etiquette for asking a number of questions (I've asked three in the last few days)?
Anyways,
Here is the code in a codebehind file. It executes a script systeminfo.vbs, and that is working fine. But in the script I have some variables assigned.
Dim WshShell = CreateObject("WScript.Shell")
WshShell.Run("wscript.exe c:\systeminfo.vbs")
vbscript
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
dim osName
osName = objOperatingSystem.Name
Wscript.Echo "OS Name: " & objOperatingSystem.Name
dim osVer
osVer = objOperatingSystem.Version
Wscript.Echo "Version: " & objOperatingSystem.Version
Wscript.Echo "Service Pack: " & _
objOperatingSystem.ServicePackMajorVersion _
& "." & objOperatingSystem.ServicePackMinorVersion
Wscript.Echo "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles
Next
I want to use osName and osVer and put the values into a label on the ASP side.
I understand that osName and osVer are simple examples, but I just need to figure out the concept of putting variables from a VBScript into ASP. My client has multiple VBScripts they use on a daily basis and I need to automate those scripts and produce a report saying if it failed or not.
Thank you for the help.
David,
As a person new to Stack Overflow myself, I was happy to find this very comprehensive FAQ for Stack Exchange sites. See the 3rd question "Is there a limit on how many questions I can ask?" for an answer to your first inquiry.
Regarding the heart of your question, I agree with #Ramhound that using a log file to exchange information between your WSH/VBScript script and your ASP.NET page is a feasible approach.
What you need is the Scripting.FileSystemObject. Here is a comprehensive WSH reference as a downloadable Windows help file.
Hint: as the download page advises at the bottom, to unblock the help page, 1) Right click on script56.chm, 2) Choose Properties, and 3) Click on "Unblock."
You'll find an intro to FileSystemObject under the heading "Script Runtime."
One more suggestion: since you'll be running this script via ASP.NET in a multi-user environment, you may find you'll need to create a log file per user or per page access. If that is the case, you'll need to generate a temporary file name for each log file to avoid name collisions with other log files. To generate your temporary file, see GetTempName in the WSH reference.

HtmlEncoding values that are already HtmlEncoded

We have taken over a .NET project recently and upon looking at the db we have the following in some columns:
1) Some columns have values such as
" & etc etc
2) Some have <script> tags and other non html encoded tags
This data is displayed all over the site. When trying out HtmlEncoding on point number 1 we get the following " -> &quot;
Obviously we are wanting to htmlencode when displaying as point 2 contains javascript which we don't want executed.
Is there a way to use HtmlEncoded on values that might or might not be already encoded?
Is there a way to use HtmlEncoded on values that might or might not be already encoded?
No there isn't.
What i would suggest is that you write a quick script that goes through the database and unencode the already encoded data. Then use something like the Microsoft AntiXSS library (tutorial here) to encode all output before it gets output to the web page. Remember that it is fine to store the data unencoded1, the danger is when you echo it back out to the end user.
Some controls already encode output using encode functionality built into the .Net framework - which is not bulletproof to XSS - you just have to either avoid using those controls or just not encode the data displayed by them. There is a FAQ question pertaining to the MS controls that encode at the bottom of the page for the first link which you should read. Also some third party control vendors encode the output of their controls, you would do yourself a favor if you test them to make sure they are not still susceptible to XSS.
1Don't forget to take steps to prevent SQL injection though!
Before applying HtmlEncode( "myText" ) use HtmlDecode method to the input text.
That way you will decode your string from:
& quot; & amp; etc etc < script>
to
" & etc etc < script>
and afterwards apply encode "from scratch".

Can you declare a variable in ASP classic like this?

I am trying to see if this can be done in classic ASP:
Dim myVar
myVar = <<< END
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>test</title>
</head>
<BODY>
END
I can do this in PHP, but I am not positivte if it can be done in ASP.
Problem is I need to handle the HTML output via a variable, and I don't want to go through the HTML and convert " to ""
EDIT:
I've found that this is called HEREDOC syntax in PHP.
Since its been asked, what I am trying to do is store HTML type tags (which may contain ', " characters which would otherwise break
myVar = "<stuff color="red">here</stuff>"
so I would need to fix it by replacing color="red" with color=""red""
PART OF THE PROBLEM:
I don't want to have to replace " with "" for the content as I assign it, I guess a HEREDOC syntax is not available for ASP classic.
OK FINE... :P
Since everyone is asking me WHY I am going about it this way, here is why, I have to support this old ASP code, I don't want to, but suddenly the scope of this old app changes that they want the contents (which used to be an HTML page) to be emailed, SO... I wanted to HEREDOC the HTML output, pass it to the mail function and have it email. Having said that, I know its sloppy, and I know it works better the other way, however this is what the job called for, I didn't want to re-write it, I just wanted to augment the output from HTML to HTML-EMAIL...
Hope that makes more sense ;)
The easiest thing to do would be to keep the HTML in a separate file, and then open that file using a TextStream object, reading the string into a variable.
No. One language's syntax isn't going to work in a different language. You can, however, assign a string literal to the variable:
Dim myVar
myVar = _
"<html xmlns=""http://www.w3.org/1999/xhtml"" lang=""en"" xml:lang=""en"">" & vbCrLf & _
"<head>" & vbCrLf & _
" <title>test</title>" & vbCrLf & _
"</head>" & vbCrLf & _
"" & vbCrLf & _
"<BODY>" & vbCrLf
I'm pretty sure you can't do exactly what you're asking here.
It might help, however, if you explained what you're trying to do. There may be some other way.
update:
You could consider putting your HTML fragments into seperate files. This would allow you to define them without having to do any reformatting of the HTML. In a similar manner you could put them into a database or even into resource files.
I'm still not 100% clear why you want these HTML fragments defined as variables, but these approaches would work.
there is no herodoc for asp :) gogo escape - its the only useable way

Resources