SpreadJS Documentation
Printing Sheets

You can print a single sheet or all the sheets in SpreadJS.

The following content is printed when you print in SpreadJS:

The following information is not printed:

Use the print method to print a sheet or sheets. Use an index to specify a specific sheet or no index for all visible sheets. You can specify many print options with the PrintInfo class such as whether to print headers, borders, grid lines, and so on.

The following table displays the options that can be used when creating a print header or footer:

Control Character Description Example Result
& Escape character    
P Current page 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 Page count 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 Current date sheet.printInfo().headerLeft("It is &D."); It is 2015/6/19. (If today is June 19, 2015.)
T Current time sheet.printInfo().headerLeft("It is &T." It is 16:30:36. (If 16:30:36 is now.)
G Image var printInfo = sheet.printInfo();
printInfo.headerLeft("&G");
printInfo.headerLeftImage("logo.jpg");
Displays an image.
S Strikethrough sheet.printInfo().headerLeft("&SThis is text."); This is text.
U Underline sheet.printInfo().headerLeft("&UThis is text."); This is text.
B Bold sheet.printInfo().headerLeft("&BThis is text."); This is text.
I Italic sheet.printInfo().headerLeft("&IThis is text."); This is text.
" Font prefix sheet.printInfo().headerLeft("&\"Lucida Console\"This is text."); This is text.
K Color prefix sheet.printInfo().headerLeft("&KFF0000This is text."); This is text.
F Spread name sheet.printInfo().headerLeft("spead name: &F"); spread name: testSpread (If printed spread's name is "testSpread".)
A Sheet name sheet.printInfo().headerLeft("sheet name: &A"); sheet name: Sheet1 (If printed sheet's name is "Sheet1".)

The orientation method is only supported when importing or exporting to Excel. The paperSize method only applies to the paging result, not the printer. Print preview is not supported. The printing result may be different between browsers.

Printing requires that you add the printing module to the page (gcspread.sheets.print.xxx.js).

Using Code

This example prints a sheet.

JavaScript
Copy Code

<script type="text/javascript" src="./scripts/pluggable/gcspread.sheets.print.9.40.20153.0.min.js"></script>

...

var spread = new GcSpread.Sheets.Spread($("#spreadContainer")[0],{sheetCount:3});
// Get active sheet in spread instance
 var activeSheet = spread.getActiveSheet();
activeSheet.isPaintSuspended(true);
            //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.isPaintSuspended(false);

//Add button for printing
$("#button1").click(function () {
spread.print(0);
   });

See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Send comments on this topic.