简体   繁体   English

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

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

Using Excel Interop, I can configure a sheet for printing with code like this: 使用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);

I think I can pretty much emulate that with Spreadsheet Light with this code: 我想我可以使用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?

I'm not sure about many of these, though, especially the replacement code for "PrintTitleRows" ("PrintHeadings" and "SetCenterHeaderText"), but one thing seems to be totally missing from Spreadsheet Light, namely "PrintArea". 不过,我不确定其中的许多内容,尤其是“ PrintTitleRows”的替代代码(“ PrintHeadings”和“ SetCenterHeaderText”),但Spreadsheet Light似乎完全缺少一件事,即“ PrintArea”。

Also, what should the "Zoom" value be? 另外,“缩放”值应该是什么? And what corresponds to "FitToPagesWide" and "FitToPagesTall"? 与“ FitToPagesWide”和“ FitToPagesTall”对应的是什么?

What is the analagous way to accomplish the same thing with Spreadsheet Light? 使用Spreadsheet Light可以完成相同任务的类似方法是什么? Or does Spreadsheet Light just automatically determine the range to print based on non-empty cells? 还是Spreadsheet Light会根据非空单元格自动确定要打印的范围?

I can help with some of these. 我可以为您提供一些帮助。 First up, Print Area. 首先,打印区域。

As Vincent says : Rule 1: Everything begins and ends with SLDocument 正如Vincent 所说 :规则1:一切以SLDocument开始和结束

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

Next: Fit to Pages: 下一页:适合页面:

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); 

Zoom is a view (not print) thing AFAIK and can be changed between 10 and 400 to set the Zoom percentage - equivalent to Ctrl-scrolling when viewing a spreadsheet. 缩放是一种视图(而非打印)功能,可以在10到400之间更改以设置缩放百分比-相当于在查看电子表格时按Ctrl滚动。

PrintHeadings displays the row (1, 2, 3, ...) and column headings (A, B, C, ...) when you print, so you can see the value in say, D25 easier. PrintHeadings在打印时显示行标题(1、2、3,...)和列标题(A,B,C,...),因此您可以很容易地看到D25中的值。

For printing titles, you use the Set<position>HeaderText in SLPageSettings: 对于打印标题,请使用SLPageSettings中的Set <position> HeaderText:

settings.SetCenterHeaderText("My Workbook Title");

Similarly SetLeftHeaderText and SetRightHeaderText 同样,SetLeftHeaderText和SetRightHeaderText

I don't know how to set 'RowsToRepeatAtTop' and 'ColumnsToRepeatAtLeft' which would match Interop's PrintTitleRows. 我不知道如何设置与Interop的PrintTitleRows相匹配的'RowsToRepeatAtTop'和'ColumnsToRepeatAtLeft'。

ProTip: The chm help file that comes with SpreadsheetLight is very useful. ProTip:SpreadsheetLight随附的chm帮助文件非常有用。

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

相关问题 如何通过链接而不是图像文件通过Spreadsheet Light将图片插入Excel电子表格? - How can I insert a picture into an Excel spreadsheet with Spreadsheet Light from a link rather than an image file? 如何使用此自定义“打印”类获取标签进行打印? - How can I get tabs to print using this custom Printing class? 如何在Spreadsheet Light中为已定义名称(范围)设置行高? - How can I set the row height for a defined name (range) in Spreadsheet Light? 如何使用C#清除Google Spreadsheet中指定工作表的所有格式? - How do I clear all formatting for a specified sheet within a Google Spreadsheet using C#? 使用Open XML读取Excel电子表格时,如何确定表格所在的工作表? - Using Open XML to read an Excel spreadsheet, how do I determine the sheet that a Table is on? 如何通过自定义打印窗口打印整个gridview区域? - How can I print a full gridview area via a custom print window? 如何使用Linq写入Excel电子表格? - How can I write to an Excel spreadsheet using Linq? 如何使用MVVM Light访问WPF中的模型属性 - How to acces Model properties in WPF using MVVM Light 在MVVM Light中访问其他ViewModel中的属性 - Accessing Properties in other ViewModels in MVVM Light 如何通过标签找到Light组件? - How can i find the Light component by tag?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM