62,074
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aspose.Words;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;
using System.Text;
public partial class Bom2_exportWord : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string html = Request.Form["content"].ToString();
string filename = Request.Form["filename"].ToString();
string hostpath = Request.Url.AbsoluteUri.ToString().Substring(0, Request.Url.AbsoluteUri.ToString().Length - Request.Url.LocalPath.ToString().Length+1);
Regex rx = new Regex(@"(?<=src="")(.*?)(?="")", RegexOptions.IgnoreCase | RegexOptions.Singleline);
html = rx.Replace(html, hostpath + "$1");
rx = new Regex(@"(?<=href="")(.*?)(?="")", RegexOptions.IgnoreCase | RegexOptions.Singleline);
html = rx.Replace(html, hostpath + "$1");
//TextBox1.Text = html;
//return;
Document doc = new Document();
doc.ViewOptions.ViewType = Aspose.Words.ViewType.Web;
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertHtml(html);
foreach (Aspose.Words.Section section in doc)
{
section.PageSetup.TopMargin = 20;
section.PageSetup.BottomMargin = 20;
section.PageSetup.LeftMargin = 20;
section.PageSetup.RightMargin = 20;
}
Response.Clear();
Request.Url.Host.ToString();
doc.Save(filename, SaveFormat.Doc, SaveType.OpenInWord, Response);
}
}