使用 Excel 互操作,我可以使用如下代码配置用于打印的工作表:
_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);
我想我几乎可以用这段代码用电子表格光来模拟它:
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 完成相同任务的类似方法是什么?还是电子表格灯只是根据非空单元格自动确定要打印的范围?