gpt4 book ai didi

c# - 如何防止打印左侧 "gutter"(行号)列(EPPlus)?

转载 作者:太空宇宙 更新时间:2023-11-03 12:40:00 28 4
gpt4 key购买 nike

使用我的 EPPlus 代码创建的电子表格的“打印预览”显示了装订线/行号列(可以这么说,第 0 列):

enter image description here

如何以编程方式防止打印间距/行号(“裂缝?”)列?

目前我的打印设置代码如下:

private void ConfigureCustomerSheetForPrinting()
{
string columnName = GetExcelTextColumnName(customerWorksheet.Dimension.End.Column);
string printArea = string.Format("A1:{0}{1}", columnName, customerWorksheet.Dimension.End.Row);
customerWorksheet.PrinterSettings.PrintArea = customerWorksheet.Cells[printArea];
customerWorksheet.PrinterSettings.FitToPage = true;
customerWorksheet.PrinterSettings.Orientation = eOrientation.Landscape;
customerWorksheet.View.ZoomScale = 100;
customerWorksheet.PrinterSettings.FitToPage = true;
customerWorksheet.PrinterSettings.FitToHeight = 100;
customerWorksheet.PrinterSettings.Scale = 100;

customerWorksheet.PrinterSettings.LeftMargin = (decimal).5 / 2.54M;
customerWorksheet.PrinterSettings.RightMargin = (decimal).5 / 2.54M;
customerWorksheet.PrinterSettings.TopMargin = (decimal).5 / 2.54M;
customerWorksheet.PrinterSettings.BottomMargin = (decimal).5 / 2.54M;
customerWorksheet.PrinterSettings.HeaderMargin = (decimal).5 / 2.54M;
customerWorksheet.PrinterSettings.FooterMargin = (decimal).5 / 2.54M;
}

最佳答案

如果我理解您的要求,您想要显示列标题(将“第 0 行”表示为“A”、“B”、“C”...)但不显示行标题(例如“Column 0"as "1", "2"3", etc.)。如果是这样,我从来没有见过这样做的方法。您可以隐藏行/列标题或同时显示两者,但不能两者都显示-或根据DocumentFormat.OpenXml.Spreadsheet.PrintOptions。基本上是您和 Richardo 讨论过的 ShowHeaders 选项。

我能想到的唯一体面的工作就是用这样的东西来伪造它。这包括将第一行设置为重复。我也将第一行设置为卡住,但这是可选的:

using (var pck = new ExcelPackage(fi))
{
var wb = pck.Workbook;
var ws = wb.Worksheets.Add("Sheet1");

//Make sure headers are not show
ws.PrinterSettings.ShowHeaders = false;

//Header
ws.Cells[1, 1].Value = "A";
ws.Cells[1, 2].Value = "B";
ws.Cells[1, 3].Value = "C";
ws.Cells[1, 4].Value = "D";

var headerrange = ws.Cells[1, 1, 1, 4];
headerrange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
headerrange.Style.Border.Top.Style = ExcelBorderStyle.Thin;
headerrange.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
headerrange.Style.Border.Left.Style = ExcelBorderStyle.Thin;
headerrange.Style.Border.Right.Style = ExcelBorderStyle.Thin;

ws.View.FreezePanes(1,4);
ws.PrinterSettings.RepeatRows = new ExcelAddress("$1:$1");

//Some data > 1 page
for (var i = 0; i < 1000; i++)
{
ws.Cells[2 + i, 1].Value = DateTime.Now.AddDays(i);
ws.Cells[2 + i, 2].Value = i;
ws.Cells[2 + i, 3].Value = i*100;
ws.Cells[2 + i, 4].Value = Path.GetRandomFileName();
}

//Save it
pck.Save();
}

在输出中给出了这个:

enter image description here

打印预览中的这个(我向下滚动了几页):

enter image description here

关于c# - 如何防止打印左侧 "gutter"(行号)列(EPPlus)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39416679/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com