如何使用EPPlus for A4纸创建Excel文件 [英] How to create Excel file with EPPlus for A4 paper

查看:139
本文介绍了如何使用EPPlus for A4纸创建Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的项目使用EPPlus创建Excel文件。这些文件是由用户打印的,而我试图强制Excel文件仅在A4页中打印,而不管内容的宽度如何。

My current project use EPPlus to create Excel files. These files are printed by the user and I'm trying to force the Excel file to print in only one A4 page, regardless the width og the content.

实际上,当文件被打印,需要两页,第二页仅包含一列。

Actually, when the file is printed, it takes two pages and the second contains just one column.

我的代码:

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;

结果:
我的代码提供的结果

The result: The result provided by my code

我需要什么:

我搜索了诸如自动调整为A4页面之类的东西,但是还没有解决方法。

I searched things like "autofit to A4 page", eso but no solution yet.

备注:所有列都是必需的。我不能在创建文件之前简单地删除一个文件。

Remark: all the columns are needed. I can't simply delete one before creating the file.

感谢您的帮助!

推荐答案

我找到了解决方法。

EPPlus为此提供了printerSettings。
使用的行是

EPPlus has a printerSettings for this. The line to use is

ws.PrinterSettings.FitToPage = true;

通过使用此选项,默认文件属性将强制Excel仅在一页中打印数据。

By using this, the default files properties force Excel to print the data in only one page.

希望对其他开发人员有所帮助。

Hope this help some other devs.

这篇关于如何使用EPPlus for A4纸创建Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆