ColdFusion、MS Word 文档和希腊字符 [英] ColdFusion, MS Word Document and Greek Characters
问题描述
我正在尝试从数据库动态构建 word 文档(我正在使用 CFC 进行查询处理).我的努力是成功的,但我只能复制英文文档.但是,我的应用程序使用的是希腊语.
I am trying to dynamically build word documents from a database (I am using a CFC for query handling). My efforts were successful, but I can only reproduce docs for the English language. However, my app is uses the Greek language.
当我尝试构建包含希腊字符的文档时,输出如下所示:??????????????????
.我尝试了很多东西,但没有任何效果.奇怪的是,当我使用相同的 CFC 进行 PDF 复制时,希腊字符输出正确.
When I try to build documents containing Greek characters the output looks like this: ??????????????????
. I have tried many things but nothing is working. The strange thing here is when I am using the same CFC for PDF reproduction, Greek characters output correctly.
cfm 文件:
<cfheader name="Content-Disposition" value="inline; filename=Save-Print.doc" charset="utf-8">
<cfcontent type="application/msword">
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Print</title>
<!--[if gte mso 9]>
<xml>
<w:WordDocument>
<w:View>Print</w:View>
<w:Compatibility>
<w:UseAsianBreakRules/>
</w:Compatibility>
<w:Zoom>100</w:Zoom>
<w:DoNotOptimizeForBrowser/>
</w:WordDocument>
</xml>
<![endif]-->
<!--[if supportFields]>
<div style="mso-element:header" id="lala">
<p class=MsoHeader><span style="color:red">
<![endif]-->
<style>
<!--
@page Section1
{
size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;
mso-header:url("http://localhost:8500/BookLedger_Final/resources/cfScripts/Header.html") h1;
mso-footer:url("http://localhost:8500/BookLedger_Final/resources/cfScripts/Header.html") f1;
}
div.Section1 {page:Section1;}
p.MsoHeader {
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #333;
}
p.MsoFooter {
}
-->
</style>
</head>
<body>
<cfif not IsDefined("URL.id")>
<cfelseif not IsDefined("URL.model")>
</cfif>
<!--- Get print details --->
<cfinvoke
component="Print"
method="myPrint"
returnvariable="getMember"
id="#URL.id#"
model="#URL.model#">
<div class=Section1>
<cfoutput query="getMember">
<b id="lala">#Title#</b>
<p style="color:##1c1c1c"><i>#Body#</i></p>
</cfoutput>
</div>
</body>
</html>
cfc 文件:
<cfcomponent>
<cffunction name="myPrint" access="remote" returntype="query" output="no">
<cfargument name="id" default="0" required="false" type="numeric">
<cfargument name="model" default="" required="false" type="any">
<cfset model = #ARGUMENTS.model#>
<cfif model EQ "member">
<cfquery name="getMember" datasource="rental">
SELECT CONCAT(rental.members.firstname,' ',rental.members.lastname) AS 'Title',rental.members.biog AS 'Body'
FROM rental.members
WHERE rental.members.id = #ARGUMENTS.id#
AND rental.members.model = "#ARGUMENTS.model#"
</cfquery>
<!---<cfset queryToString = serializeJson(getMember)>
<cfset strippedQuery = REReplace(queryToString,'<[^>]*>','','all')>--->
<cfreturn getMember>
<cfelseif model EQ "new_member">
<cfquery name="getMember" datasource="rental">
SELECT CONCAT(rental.new_members.firstname,' ',rental.new_members.lastname) AS 'Title',rental.new_members.biog AS 'Body'
FROM rental.new_members
WHERE rental.new_members.id = #ARGUMENTS.id#
AND rental.new_members.model = "#ARGUMENTS.model#"
</cfquery>
<cfreturn getMember>
<cfelseif model EQ "book">
<cfquery name="getMember" datasource="rental">
SELECT rental.books.title AS 'Title',rental.books.description AS 'Body'
FROM rental.books
WHERE rental.books.id = #ARGUMENTS.id#
AND rental.books.model = "#ARGUMENTS.model#"
</cfquery>
<cfreturn getMember>
<cfelseif model EQ "journal">
<cfquery name="getMember" datasource="rental">
SELECT rental.journals.title AS 'Title',rental.journals.description AS 'Body'
FROM rental.journals
WHERE rental.journals.id = #ARGUMENTS.id#
AND rental.journals.model = "#ARGUMENTS.model#"
</cfquery>
<cfreturn getMember>
<cfelseif model EQ "cd">
<cfquery name="getMember" datasource="rental">
SELECT rental.cd.title AS 'Title',rental.cd.description AS 'Body'
FROM rental.cd
WHERE rental.cd.id = #ARGUMENTS.id#
AND rental.cd.model = "#ARGUMENTS.model#"
</cfquery>
<cfreturn getMember>
</cfif>
</cffunction>
</cfcomponent>
推荐答案
当我尝试你的 pastebin 示例时,我也遇到了乱码.看起来您删除了指定 utf-8 的 <meta>
标记.当我重新添加它时,这些字符在 MS Word 中为我正确显示.
When I tried your pastebin example I too got gibberish. It looks like you dropped the <meta>
tag specifying utf-8. When I added it back, the characters displayed properly for me in MS Word.
<cfprocessingdirective pageencoding="utf-8">
<cfheader name="Content-Disposition" value="inline; filename=Save-Print.doc" charset="utf-8">
<cfcontent type="application/msword; charset=utf-8">
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Print</title>
...
这篇关于ColdFusion、MS Word 文档和希腊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!