繁体   English   中英

如何使用Spreadsheet Light配置纸张的打印区域和其他打印属性?

[英]How can I configure the print area and other printing properties of a sheet using Spreadsheet Light?

使用Excel Interop,我可以使用以下代码配置要打印的工作表:

_xlSheetPlatypus.PageSetup.PrintArea = "A1:" + 
    GetExcelTextColumnName(
        _xlSheetPlatypus.UsedRange.Columns.Count) + 
        _xlSheetPlatypus.UsedRange.Rows.Count;
_xlSheetPlatypus.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape;
_xlSheetPlatypus.PageSetup.Zoom = false;
_xlSheetPlatypus.PageSetup.FitToPagesWide = 1;
_xlSheetPlatypus.PageSetup.FitToPagesTall = 100;

_xlSheetPlatypus.PageSetup.LeftMargin = _xlApp.Application.InchesToPoints(0.5);
_xlSheetPlatypus.PageSetup.RightMargin = _xlApp.Application.InchesToPoints(0.5);
_xlSheetPlatypus.PageSetup.TopMargin = _xlApp.Application.InchesToPoints(0.5);
_xlSheetPlatypus.PageSetup.BottomMargin = _xlApp.Application.InchesToPoints(0.5);
_xlSheetPlatypus.PageSetup.HeaderMargin = _xlApp.Application.InchesToPoints(0.5);
_xlSheetPlatypus.PageSetup.FooterMargin = _xlApp.Application.InchesToPoints(0.5);

_xlSheetPlatypus.PageSetup.PrintTitleRows = String.Format("${0}:${0}", CUSTOMER_HEADING_ROW);

我想我可以使用Spreadsheet Light通过以下代码来模拟:

SLPageSettings ps = new SLPageSettings();
// PrintArea
// ???

// PrintTitleRows
ps.PrintHeadings = true;
ps.SetCenterHeaderText(String.Format("${0}:${0}", CUSTOMER_HEADING_ROW); 

// Margins
ps.SetNarrowMargins();
ps.TopMargin = 0.5;
ps.BottomMargin = 0.5;
ps.LeftMargin = 0.5;
ps.RightMargin = 0.5;
ps.HeaderMargin = 0.5;
ps.FooterMargin = 0.5;

// Orientation
ps.Orientation = OrientationValues.Landscape;

// Zoom
//psByCust.ZoomScale = what should this be? Is not a boolean...

// FitToPagesWide
//psByCust.FitToWidth = ; "cannot be assigned to" so how can I set this?

// FitToPagesTall
//psByCust.FitToHeight = 100; "cannot be assigned to" so how can I set this?

不过,我不确定其中的许多内容,尤其是“ PrintTitleRows”的替代代码(“ PrintHeadings”和“ SetCenterHeaderText”),但Spreadsheet Light似乎完全缺少一件事,即“ PrintArea”。

另外,“缩放”值应该是什么? 与“ FitToPagesWide”和“ FitToPagesTall”对应的是什么?

使用Spreadsheet Light可以完成相同任务的类似方法是什么? 还是Spreadsheet Light会根据非空单元格自动确定要打印的范围?

我可以为您提供一些帮助。 首先,打印区域。

正如Vincent 所说 :规则1:一切以SLDocument开始和结束

SLDocument myWorkbook = new SLDocument();
myWorkbook.SetPrintArea("A1", "E10");
// or
myWorkbook.SetPrintArea(1, 1, 10, 5);

下一页:适合页面:

SLPageSettings settings = new SLPageSettings();
settings.ScalePage(2, 3)  // print 2 pages wide and 3 long
// There is no info on how to just scale in one dimension, I would use 
// a definitely too big™ number in the field you don't care about
// Eg for fit all columns on one page:
settings.ScalePage(1, 99999); 

缩放是一种视图(而非打印)功能,可以在10到400之间更改以设置缩放百分比-相当于在查看电子表格时按Ctrl滚动。

PrintHeadings在打印时显示行标题(1、2、3,...)和列标题(A,B,C,...),因此您可以很容易地看到D25中的值。

对于打印标题,请使用SLPageSettings中的Set <position> HeaderText:

settings.SetCenterHeaderText("My Workbook Title");

同样,SetLeftHeaderText和SetRightHeaderText

我不知道如何设置与Interop的PrintTitleRows相匹配的'RowsToRepeatAtTop'和'ColumnsToRepeatAtLeft'。

ProTip:SpreadsheetLight随附的chm帮助文件非常有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM