1 const string css = "style=‘text-align:justify;" //两端对齐
2 + "text-justify:inter-ideograph;"
3 + "text-indent: 2em;" //首行缩进2字符
4 + "line-height:1.25;" //1.25倍行距
5 + "margin-top:0;margin-bottom:0;" //段前段后0行
6 + "font-size: 12pt;" //字体:小四
7 + "font-family:Times New Roman,宋体;‘"; //中文字体:宋体,西文字体:Times New Roman
8
9
10 ASPxHtmlEditor1.Html = "<p " + css + ">"; //段落用标签p标记
11 for (int i = 0; i < 30;i++)
12 ASPxHtmlEditor1.Html += "测试文本123abCD"; //这是内容
13 ASPxHtmlEditor1.Html += "</p>
1 using DevExpress.XtraRichEdit;
2 using DevExpress.XtraRichEdit.API.Native;
1 private void SetPrintOptions(IRichEditDocumentServer richedit) //设置格式
2 {
3 foreach (Section _section in richedit.Document.Sections)
4 {
5 _section.Page.PaperKind = System.Drawing.Printing.PaperKind.A4; //A4纸
6 _section.Page.Landscape = false; //竖版
7 _section.Margins.Left = 295f; //左侧页边距 2.5cm
8 _section.Margins.Right = 295f;
9 _section.Margins.Top = 295f;
10 _section.Margins.Bottom = 295f;
11
12 }
13 }
14
15 protected void PushToBrowser(string fileName) //导出文件
16 {
17
18 FileStream fs = new FileStream(fileName, FileMode.Open);
19 byte[] bytes = new byte[(int)fs.Length];
20 fs.Read(bytes, 0, bytes.Length);
21 fs.Close();
22 if (File.Exists(fileName))
23 File.Delete(fileName);
24
25 Response.ContentType = "application/octet-stream";
26 Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
27 Response.BinaryWrite(bytes);
28 Response.Flush();
29 Response.End();
30 }
1 string outputFileName = "newtext.docx"; //导出文件的名称
2
3 FileStream fs = new FileStream("test.docx", FileMode.Create);
4 ASPxHtmlEditor1.Export(DevExpress.Web.ASPxHtmlEditor.HtmlEditorExportFormat.Docx, fs);
5 fs.Close();
6 fs.Close();
7
8 RichEditDocumentServer srv = new RichEditDocumentServer();
9 srv.LoadDocument("test.docx", DocumentFormat.OpenXml);
10 srv.BeginUpdate();
11 SetPrintOptions(srv);
12 srv.EndUpdate();
13 srv.SaveDocument(outputFileName, DocumentFormat.OpenXml);
14
15 if (File.Exists("test.docx"))
16 File.Delete("test.docx");
17
18 PushToBrowser(outputFileName);