2015-12-03 86 views
2

我目前的項目使用EPPlus來創建Excel文件。這些文件是由用戶打印的,我試圖強制Excel文件只打印一個A4頁面,而不管內容的寬度。如何使用EPPlus爲A4紙創建Excel文件

實際上,當打印文件時,它需要兩頁,第二頁只包含一列。

我的代碼:

ws.PrinterSettings.Orientation = eOrientation.Landscape; 
ws.PrinterSettings.PrintArea = ws.Cells[ws_dimension_adress]; 
ws.PrinterSettings.TopMargin= 0; 
ws.PrinterSettings.RightMargin = 0; 
ws.PrinterSettings.BottomMargin = 0; 
ws.PrinterSettings.LeftMargin = 0; 
ws.Cells[ws_dimension_adress].AutoFitColumns(); 
ws.Cells[ws_dimension_adress].Style.Font.Size = 9; 

結果: 由我提供的代碼,結果

enter image description here

我需要什麼:

enter image description here

我搜索之類的東西「AUT到A4頁面「,但還沒有解決方案。

備註:所有列都需要。在創建文件之前,我不能簡單地刪除一個。

感謝您的幫助!

回答

5

我找到了解決方案。

EPPlus有一個printerSettings爲此。 使用該生產線是

ws.PrinterSettings.FitToPage = true; 

使用,缺省文件的屬性強制Excel打印僅在一個頁面中的數據。

希望這可以幫助其他一些開發者。

0

您也可以使用該行代碼爲特定的紙張尺寸:

ws.PrinterSettings.PaperSize = ePaperSize.A4; 

Hopte這可以幫助其他一些人。