1

I need to write a small script to take the contents of an XLS file and lay them out nicely in a web page. So far, so easy. However, the spreadsheet text will be the content of a series of social media posts which includes emojis within that content. I did a very basic test and found that the emojis turn into question marks when dropped to the page by the script.

I don't particularly like emojis myself but I don't get to choose whether they are included in the text, and they need to appear in the end result.

Here's what a stripped back version of the script looks like, with no formatting etc.

<%@ Language=VBScript%>
<html><head></head>
<body>
<%
Dim objConn, objRS
Set objConn = Server.CreateObject("ADODB.Connection")
filepath = "xls/OPG.xls"
objConn.Open "DRIVER={Microsoft Excel Driver (*.xls)}; IMEX=1; HDR=NO; Excel 8.0; DBQ=" & Server.MapPath(filepath) & "; "
strSQL = "SELECT * FROM A1:C400"
Set objRS=objConn.Execute(strSQL)

Set DataList = CreateObject("ADOR.Recordset")

Do Until objRS.EOF

Response.Write objRS.Fields("Post Description").Value & "<br /><br />"
objRS.MoveNext
Loop
objConn.Close
Set objConn=Nothing
%>
</body>
</html>

Here's what the original XLS file looks like...

Excel file original

...and here's how that comes into the web page...

the result

How do I get around this? Any ideas?

Thanks

Schlepper
  • 39
  • 2
  • I doubt it will be as easy as this, but try changing `<%@ Language=VBScript%>` to `<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>` and adding `response.Charset = "utf-8"`. – Adam Mar 22 '19 at 15:47
  • Possible duplicate of [Classic ASP - how to save data to CSV file with UTF-8](https://stackoverflow.com/questions/25704440/classic-asp-how-to-save-data-to-csv-file-with-utf-8) – user692942 Mar 22 '19 at 15:51

1 Answers1

1

The Microsoft Access Database Engine is able to read and display emojis from Excel files: https://www.microsoft.com/en-us/download/details.aspx?id=54920

You will need to set your codepage and charset to UTF-8 though:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%

    response.Charset = "utf-8"

%>

Connection string:

objConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Server.MapPath(filepath) & ";Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1"";"

Tested and working.

Adam
  • 836
  • 2
  • 8
  • 13