国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

DevExpress ASPxHtmlEditor控件格式化并導出Word (修復中文字體導出丟失)

2019-11-17 02:13:18
字體:
來源:轉載
供稿:網友

DevExPRess aspxHtmlEditor控件格式化并導出Word (修復中文字體導出丟失)

在前臺頁面中先插入一個ASPxHtmlEditor控件,名為ASPxHtmlEditor1。 我用的Dev版本為14.1

格式化文本

在后臺插入如下代碼

1conststringCSS="style='text-align:justify;"http://兩端對齊2+"text-justify:inter-ideograph;"3+"text-indent:2em;"http://首行縮進2字符4+"line-height:1.25;"http://1.25倍行距5+"margin-top:0;margin-bottom:0;"http://段前段后0行6+"font-size:12pt;"http://字體:小四7+"font-family:TimesNewRoman,宋體;'"; //中文字體:宋體,西文字體:TimesNewRoman8910ASPxHtmlEditor1.Html="<p"+css+">";//段落用標簽p標記11for(inti=0;i<30;i++)12ASPxHtmlEditor1.Html+="測試文本123abCD"; //這是內容13ASPxHtmlEditor1.Html+="</p>

上述代碼實現了對文字的格式化,可以基本滿足生成一般報告的格式需要。

Word導出及頁面設置

對于ASPxHtmlEditor控件,無法直接設置導出Word或其他格式文件的頁面(頁邊距、紙張大小等),需借助RichEditDocumentServer來轉存實現。

添加如下引用:

1usingDevExpress.XtraRichEdit;2usingDevExpress.XtraRichEdit.API.Native;

插入下面兩個函數

1privatevoidSetPrintOptions(IRichEditDocumentServerrichedit)//設置格式

2{3foreach(Section_sectioninrichedit.Document.Sections)4{5_section.Page.PaperKind=System.Drawing.Printing.PaperKind.A4;//A4紙6_section.Page.Landscape=false;//豎版7_section.Margins.Left=295f;//左側頁邊距2.5cm8_section.Margins.Right=295f;9_section.Margins.Top=295f;10_section.Margins.Bottom=295f;1112}13}1415protectedvoidPushToBrowser(stringfileName)//導出文件16{1718FileStreamfs=newFileStream(fileName,FileMode.Open);19byte[]bytes=newbyte[(int)fs.Length];20fs.Read(bytes,0,bytes.Length);21fs.Close();22if(File.Exists(fileName))23File.Delete(fileName);2425Response.ContentType="application/octet-stream";26Response.AddHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(fileName,System.Text.Encoding.UTF8));27Response.BinaryWrite(bytes);28Response.Flush();29Response.End();30}

在執行導出的事件(如Button_Click事件)中添加如下代碼

1stringoutputFileName="newtext.doc";//導出文件的名稱

23FileStreamfs=newFileStream("test.rtf",FileMode.Create);4ASPxHtmlEditor1.Export(DevExpress.Web.ASPxHtmlEditor.HtmlEditorExportFormat.Rtf,fs); //注意此處 先導出Rtf格式5fs.Close();6fs.Close();78RichEditDocumentServersrv=newRichEditDocumentServer();9srv.LoadDocument("test.rtf",DocumentFormat.Rtf);10srv.BeginUpdate();11SetPrintOptions(srv);12srv.EndUpdate();13srv.SaveDocument(outputFileName,DocumentFormat.Doc); //再導出Doc格式 如果導出Openxml(.Docx)格式,則中文字體丟失1415if(File.Exists("test.rtf"))16File.Delete("test.rtf");1718PushToBrowser(outputFileName);

輸出的文本如下:

p.s.關于頁邊距設置成cm的換算

試了幾組數據,做了個3次擬合,先湊合用吧。(x是期望設置的厘米數 如2.5cm y就是程序的中用到的參數 如295 )

轉載請注明出處http://www.survivalescaperooms.com/LFDX/p/4688938.html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 兴业县| 小金县| 冷水江市| 沂水县| 城步| 东乡族自治县| 清涧县| 黄平县| 邯郸县| 于都县| 全椒县| 台北县| 永胜县| 东乌| 沁水县| 江华| 竹溪县| 呈贡县| 临潭县| 志丹县| 潮安县| 威海市| 鄂托克旗| 西盟| 科技| 开江县| 邳州市| 临城县| 阳泉市| 延吉市| 榆林市| 镇远县| 湘阴县| 黄石市| 桂东县| 泽库县| 浑源县| 达拉特旗| 邵阳县| 仪陇县| 南康市|