我目前使用asp.NET生成一個.doc文件,內容爲html。在生成的HTML中插入分頁符.doc
我想插入一個分頁符到頁面,但不知道如何。
我試過使用css style ='page-break-before:always'但它什麼也沒做。
這是分配給一個按鈕單擊事件代碼:
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset ="";
HttpContext.Current.Response.ContentType ="application/msword";
string strFileName = "GenerateDocument"+ ".doc";
HttpContext.Current.Response.AddHeader("Content-Disposition","inline;filename=" + strFileName);
StringBuilder strHTMLContent = new StringBuilder();
strHTMLContent.Append("<p align='Center'>Content Before Page Break</p>".ToString());
strHTMLContent.Append("<br><br>".ToString());
strHTMLContent.Append("<p class='pageBreak' style='mso-special-character:line-break;'>meh</p>".ToString());
strHTMLContent.Append("<br><br>".ToString());
strHTMLContent.Append("<p align='Center'>Content After Page Break</p>".ToString());
HttpContext.Current.Response.Write(strHTMLContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
你正在用HTML創建一個MS Word文檔? – 2011-02-04 10:23:06
聲稱文檔是MS Word不會使它成爲MS Word。它只是讓用戶配置的任何應用程序處理Word文檔嘗試處理HTML文檔。如果你想提供一個MS Word文檔,然後生成一個真正的。不要發送包裝在一堆謊言中的HTML。 – Quentin 2011-02-04 10:24:32
你可能會更喜歡看'docx`規範 - 你可以用類似的方式生成它,並輸出一個支持的格式,而不是希望單詞/任何程序處理`doc`文件可以拾取片斷 – Basic 2011-02-04 10:28:08