![](/img/trans.png)
[英]How can I insert a picture into an Excel spreadsheet with Spreadsheet Light from a link rather than an image file?
[英]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.