如何防止打印左侧 "gutter"(行号)列(EPPlus)?
How can I prevent the left "gutter" (row number) column from printing (EPPlus)?
使用我的 EPPlus 代码创建的电子表格的 "Print Preview" 显示 gutter/row 数字列(可以说是第 0 列):
如何以编程方式阻止打印 gutter/row 数字 ("crack?") 列?
目前我的打印设置代码如下:
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;
}
PrinterSettings 对象中有一个名为 ShowHeaders
的 属性,它应该可以满足您的需要。您那里似乎没有它,所以您可能会遗漏它。
customerWorksheet.PrinterSettings.ShowHeaders = false;
customerWorksheet.View.ShowHeaders = false;
您可以在 ExcelPrinterSettings
class 的 source code 中更明确地看到这一点。
/// <summary>
/// Print headings (column letter and row numbers)
/// </summary>
public bool ShowHeaders
{
get
{
return GetXmlNodeBool(_headersPath, false);
}
set
{
SetXmlNodeBool(_headersPath, value, false);
}
}
希望对 B 有帮助。;)
如果我理解您的要求,您想要显示第 header 列(将 "Row 0" 说成 "A"、"B"、"C" , ...) 但不显示行 headers(比如 "Column 0" 为“1”、“2”3 等)。如果是这样,我从未见过这样做的方法. 根据 DocumentFormat.OpenXml.Spreadsheet.PrintOptions,你可以隐藏 row/col header 或同时显示但不显示 either-or。基本上你和 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(":");
//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();
}
这在输出中给出了这个:
打印预览中的这个(我向下滚动了几页):
使用我的 EPPlus 代码创建的电子表格的 "Print Preview" 显示 gutter/row 数字列(可以说是第 0 列):
如何以编程方式阻止打印 gutter/row 数字 ("crack?") 列?
目前我的打印设置代码如下:
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;
}
PrinterSettings 对象中有一个名为 ShowHeaders
的 属性,它应该可以满足您的需要。您那里似乎没有它,所以您可能会遗漏它。
customerWorksheet.PrinterSettings.ShowHeaders = false;
customerWorksheet.View.ShowHeaders = false;
您可以在 ExcelPrinterSettings
class 的 source code 中更明确地看到这一点。
/// <summary>
/// Print headings (column letter and row numbers)
/// </summary>
public bool ShowHeaders
{
get
{
return GetXmlNodeBool(_headersPath, false);
}
set
{
SetXmlNodeBool(_headersPath, value, false);
}
}
希望对 B 有帮助。;)
如果我理解您的要求,您想要显示第 header 列(将 "Row 0" 说成 "A"、"B"、"C" , ...) 但不显示行 headers(比如 "Column 0" 为“1”、“2”3 等)。如果是这样,我从未见过这样做的方法. 根据 DocumentFormat.OpenXml.Spreadsheet.PrintOptions,你可以隐藏 row/col header 或同时显示但不显示 either-or。基本上你和 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(":");
//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();
}
这在输出中给出了这个:
打印预览中的这个(我向下滚动了几页):