html转word

_Nobodyknows _Nobodyknows 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我用的ASP.NET,要做一个导出word的功能。现在导出如下图

把这个拖一下就可以,但在程序里面该怎么设置让他靠左边点?我代码生成代码

string _html = "";
if (Request.Form["hidhtml"] != null && Request.Form["hidhtml"].ToString().Trim() != string.Empty)
{
//取得网页的html代码
_html = Request.Form["hidhtml"].ToString();

_html = new Regex("title(.*?)\"(.*?)\"").Replace(_html, "");

string path = Server.MapPath("\\upload") + GetSaveFilePath(); //创建文件夹算法
//因為Web 是多執行緒環境,避免甲產生的文件被乙下載去,所以檔名都用唯一
string fileNameWithOutExtention = path.Substring(path.LastIndexOf("\\") + 1);

string strPath = path + ".doc";

//生成word
Document _doc = new Document();
DocumentBuilder _builder = new DocumentBuilder(_doc);
_builder.InsertHtml(_html);
_doc.Save(strPath, Aspose.Words.SaveFormat.Doc);

//檔案下載
//把檔案讀進串流
FileStream fs = new FileStream(strPath, FileMode.Open);
byte[] file = new byte[fs.Length];
fs.Read(file, 0, file.Length);
fs.Close();

//Response給用戶端下載
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/msword";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + fileNameWithOutExtention + ".doc");//強制下載
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.BinaryWrite(file);

Response.End();

}
...全文
评论 6
收藏 已收藏
分享
返回顶部
_Nobodyknows
C# 111,129 成员 642,538 内容