你可以打印 Spread.Sheets 中单个或多个工作表。
当打印 Spread.Sheets 时,以下内容将会被打印:
- 可见的行和列,行标题,列标题和视口(ViewPort)。
- 单元格文字
- 单元格样式
- 合并的单元格
- 溢出
以下信息将不会被打印
- 隐藏的列和行
- 浮动对象
- 批注
- 标签栏
- 滚动条
- 分组信息
- 筛选按钮
- 数据验证按钮和数据验证标记
- 被激活的效果
- 选择
- 冻结线
使用 print 方法来打印一个工作表或者多个工作表。使用 index 来指定打印哪一个工作表,或者不指定 index 来打印所有可见的工作表。
你可以使用 PrintInfo 类来指定打印时的选项,比如是否打印表头,边框,表格线等。
下表说明了打印表头和表尾的时候的选项
Control Character | Description | Example | Result |
& | 脱出字符 | ||
P | 当前页 | sheet.printInfo().headerLeft("This is page &P of &N pages."); | This is page 1 of 10 pages. (If there are 10 pages and this is first page.) |
N | 页总数 | sheet.printInfo().headerLeft("This is page &P of &N pages."); | This is page 1 of 10 pages. (If there are 10 pages and this is first page.) |
D | 当前日期 | sheet.printInfo().headerLeft("It is &D."); | It is 2015/6/19. (If today is June 19, 2015.) |
T | 当前时间 | sheet.printInfo().headerLeft( "It is &T." | It is 16:30:36. (If 16:30:36 is now.) |
G | 图片 | var printInfo = new GC.Spread.Sheets.Print.PrintInfo(); | Displays an image. |
S | 删除线 | sheet.printInfo().headerLeft("&SThis is text."); | This is text. |
U | 下划线 | sheet.printInfo().headerLeft("&UThis is text."); | This is text. |
B | 黑体 | sheet.printInfo().headerLeft("&BThis is text."); | This is text. |
I | 斜体 | sheet.printInfo().headerLeft("&IThis is text."); | This is text. |
" | 字体前缀 | sheet.printInfo().headerLeft("&\"Lucida Console\"This is text."); | This is text. |
K | 颜色前缀 | sheet.printInfo().headerLeft("&KFF0000This is text."); | This is text. |
F | 工作簿名称 | sheet.printInfo().headerLeft("spead name: &F"); | spread name: testSpread (If printed spread's name is "testSpread".) |
A | 工作表名称 | sheet.printInfo().headerLeft("sheet name: &A"); | sheet name: Sheet1 (If printed sheet's name is "Sheet1".) |
orientation 方法只支持导入 Excel 和导出 Excel 文件。
paperSize 方法只对分页起作用,不会影响打印机。
控件不支持打印预览。
打印结果可能和浏览器预览的结果不同。
要想打印,请在页面中引入:(gc.spread.sheets.print.xxx.js. |
示例代码
以下代码打印了一个工作表
JavaScript
<script src="./scripts/pluggable/gc.spread.sheets.print.10.x.x.min.js" type="application/javascript"></script> ... var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3}); var activeSheet = spread.getActiveSheet(); activeSheet.suspendPaint(); //set value for (var r = 0, rc = activeSheet.getRowCount() - 5; r < rc; r++) { for (var c = 0, cc = activeSheet.getColumnCount() - 5; c < cc; c++) { activeSheet.setValue(r, c, r + c); } } activeSheet.resumePaint(); $("#button1").click(function () { spread.print(0); });