c# - 如何使用 EPPlus 创建 A4 纸的 Excel 文件

标签 c# asp.net excel printing epplus

我目前的项目使用 EPPlus 来创建 Excel 文件。这些文件由用户打印,我试图强制 Excel 文件仅在一张 A4 纸上打印,无论内容的宽度如何。

实际上,打印文件时需要两页,第二页仅包含一栏。

我的代码:

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

我搜索了“autofit to A4 page”之类的东西,但还没有解决方案。

备注:所有栏目都是必填项。我不能在创建文件之前简单地删除一个。

感谢您的帮助!

最佳答案

我找到了解决方案。

EPPlus 有一个打印机设置。 要使用的行是

ws.PrinterSettings.FitToPage = true;

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

希望这对其他开发者有帮助。

关于c# - 如何使用 EPPlus 创建 A4 纸的 Excel 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34068831/

相关文章:

c# - 在 WPF 数据网格中展开行

c# - 如何查找位图和 JPEG 文件的结构?

asp.net - 识别 ASP.NET 应用程序中的内存问题

c# - 在 ASP、C# 和 CSS 中更改图像大小

excel - 删除使用 pdfTk 创建的 pdf 中的多个嵌入字体

c# - 如何在多线程时传递不同的实例?

c# - ASP.Net 如何在提交时删除/忽略特定元素的验证?

c# - 多个 Controller 端点之间的 Web Api 交互

Excel VBA - 停止运行由 Shell 启动的程序?

excel - 运行 n 行的计算函数