2014年8月1日 星期五

文件橫式列印的做法

http://mandylins.blogspot.tw/2007/07/blog-post_5357.html
(1) Server端安裝scriptX的元件
(2) 先在程式裡加入這段object link scriptx的元件---
object id="factory" viewastext style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="http://www.meadroid.com/scriptx/smsx.cab#Version=6,3,435,20"

(3) 加入這段 javascript---
function window.onload() {
factory.printing.portrait = false //橫式
factory.printing.header = "&b<%=heading%>" //頁首
factory.printing.footer = "&b&p / &P" //頁尾
factory.printing.leftMargin = 1.0 //左邊界
factory.printing.topMargin = 1.0 //上邊界
factory.printing.rightMargin = 1.0 //右邊界
factory.printing.bottomMargin = 1.0 //下邊
}

(4)執行程式時,如果Client端沒有ScriptX的元件時,瀏覽器會要求安裝..所以大概得寫提示告知Client端的user,必須下載該元件並安裝。

控制 ASP.Net 匯出為 Word 時的直印 / 橫印


一般常見到透過 Asp.Net 匯出為 Excel 或是 Word 的需求時,只是將網頁事先透過 Html 去定義好 每個 Table 的內容,再透過設定 ContentType 為 application/vnd.ms-word 或 application/vnd.ms-excel 來決定是要用 MS-Word 或 MS-Excel 來開啟。

如果你很滿意自己的作品,想進一步要做列印時,那有可能會遇到直印/橫印的問題,畢竟,寸有所長「紙」有所短啊!為了要解決指定 Word 檔 直印 / 橫印的問題,第一步,就是要知道這兩種模式的英文名詞叫什麼,才能去 google 上查嘛!原來,直印的英文用法是 Portrait,橫印則是 Landscape。

在網路上找到一篇蠻詳細的文章,http://forums.asp.net/p/1014751/1394975.aspx

其中,節錄出橫印的用法:


Response.Write("@page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}")

Response.Write("div.Section2 {page:Section2;}")

而之後,則僅需將你的內容包在一個 < div > 裡,並設定他的 class = Section2 就可以完成橫印的設定了。


asp.net gridview 匯出成EXCEL後,EXCEL如何預設成為 預覽時候會看到"橫向列印"?

若只靠匯出 GridView 方式產製 Excel 的方法是做不到的。
你可以考慮用 ExcelML / MIME / Automation 方式輸出,控制橫向列印



沒有留言: