The print settings mainly include orientation settings, scaling, paper settings, margins, and so on. Npoi 1.2 supports most print properties, allowing you to easily meet your customers ' printing needs.
First, direction setting
Excel supports two page orientations, portrait and landscape.
How do I set it up in Npoi? You can set it by HSSFSheet.PrintSetup.Landscape, landscape is a Boolean type and is horizontal in English. If landscape equals true, the page orientation is horizontal; otherwise portrait.
Second, zoom and page width height
The scaling ratio here corresponds to the HSSFSheet.PrintSetup.Scale property, and the page width and page height correspond to HSSFSheet.PrintSetup.FitWidth and HSSFSheet.PrintSetup.FitHeight respectively. Note that the printsetup.scale here should be set to a value between 0-100 and not a decimal.
Three, the paper set
Set by the HSSFSheet.PrintSetup.PaperSize property, but the papersize here is not set randomly, but is determined by some fixed value, the specific value and corresponding paper as shown in the following table:
| Value |
Paper |
| 1 |
US Letter 8 X one in |
| 2 |
US Letter Small 8 x one in |
| 3 |
US Tabloid x + in |
| 4 |
US Ledger x in |
| 5 |
US Legal 8 x in |
| 6 |
US Statement 5 x 8 in |
| 7 |
US Executive 7 x Ten in |
| 8 |
A3 297 x 420 mm |
| 9 |
A4 x 297 mm |
| 10 |
A4 Small x 297 mm |
| 11 |
A5 148 x mm |
| 12 |
B4 (JIS) x 354 |
| 13 |
B5 (JIS) 182 x 257 mm |
| 14 |
Folio 8 x in |
| 15 |
Quarto 215 x 275 mm |
| 16 |
Ten x in |
| 17 |
One x in |
| 18 |
US Note 8 x in |
| 19 |
US Envelope #9 3 7/8 x 8 7/8 |
| 20 |
US Envelope #10 4 1/8 x 9 1/2 |
| 21st |
US Envelope #11 4 x 10 3/8 |
| 22 |
US Envelope #12 4 \276 x 11 |
| 23 |
US Envelope #14 5 x 11 1/2 |
| 24 |
C size Sheet |
| 25 |
D size Sheet |
| 26 |
E size Sheet |
| 27 |
Envelope DL x 220mm |
| 28 |
Envelope C5 162 x 229 mm |
| 29 |
Envelope C3 324 x 458 mm |
| 30 |
Envelope C4 229 x 324 mm |
| 31 |
Envelope C6 x 162 mm |
| 32 |
Envelope C65 x 229 mm |
| 33 |
Envelope B4 x 353 mm |
| 34 |
Envelope B5 176 x mm |
| 35 |
Envelope B6 176 x mm |
| 36 |
Envelope x mm |
| 37 |
US Envelope Monarch 3.875 x 7.5 in |
| 38 |
6 3/4 US Envelope 3 5/8 x 6 in |
| 39 |
US Std fanfold 7/8 x one in |
| 40 |
German STD fanfold 8 x in |
| 41 |
German Legal fanfold 8 x in |
| 42 |
B4 (ISO) x 353 mm |
| 43 |
Japanese postcard x 148 mm |
| 44 |
9 x in |
| 45 |
Ten x in |
| 46 |
X in |
| 47 |
Envelope Invite x mm |
| 48 |
Reserved–do not use |
| 49 |
Reserved–do not use |
| 50 |
US Letter Extra 9 \275 x |
| 51 |
US Legal Extra 9 \275 x in |
| 52 |
US Tabloid Extra 11.69 x in |
| 53 |
A4 Extra 9.27 x 12.69 in |
| 54 |
Letter Transverse 8 \275 x one in |
| 55 |
A4 Transverse x 297 mm |
| 56 |
Letter Extra Transverse 9\275 x |
| 57 |
SUPERA/SUPERA/A4 227 x 356 mm |
| 58 |
SUPERB/SUPERB/A3 305 x 487 mm |
| 59 |
US Letter Plus 8.5 x 12.69 in |
| 60 |
A4 Plus x mm |
| 61 |
A5 Transverse 148 x mm |
| 62 |
B5 (JIS) transverse 182 x 257 mm |
| 63 |
A3 Extra 322 x 445 mm |
| 64 |
A5 Extra 174 x 235 mm |
| 65 |
B5 (ISO) Extra 201 x 276 mm |
| 66 |
A2 420 x 594 mm |
| 67 |
A3 transverse 297 x 420 mm |
| 68 |
A3 Extra Transverse 322 x 445 mm |
| 69 |
Japanese Double postcard x 148 mm |
| 70 |
A6 x 148 mm |
| 71 |
Japanese Envelope Kaku #2 |
| 72 |
Japanese Envelope Kaku #3 |
| 73 |
Japanese Envelope Chou #3 |
| 74 |
Japanese Envelope Chou #4 |
| 75 |
Letter Rotated x 8 each in |
| 76 |
A3 rotated 420 x 297 mm |
| 77 |
A4 rotated 297 x mm |
| 78 |
A5 rotated x 148 mm |
| 79 |
B4 (JIS) rotated 364 x 257 mm |
| 80 |
B5 (JIS) rotated 257 x 182 mm |
| 81 |
Japanese postcard rotated 148 x mm |
| 82 |
Double Japanese Postcard rotated 148 x mm |
| 83 |
A6 rotated 148 x mm |
| 84 |
Japanese Envelope Kaku #2 rotated |
| 85 |
Japanese Envelope Kaku #3 rotated |
| 86 |
Japanese Envelope Chou #3 rotated |
| 87 |
Japanese Envelope Chou #4 rotated |
| 88 |
B6 (JIS) x 182 mm |
| 89 |
B6 (JIS) rotated 182 x mm |
| 90 |
X one in |
| 91 |
Japanese Envelope you #4 |
| 92 |
Japanese Envelope you #4 rotated |
| 93 |
PRC 16K 146 x 215 mm |
| 94 |
PRC 32K x 151 mm |
| 95 |
PRC 32K (Big) x 151 mm |
| 96 |
PRC Envelope #1 102 x 165 mm |
| 97 |
PRC Envelope #2 102 x 176 mm |
| 98 |
PRC Envelope #3 x 176 mm |
| 99 |
PRC Envelope #4 x 208 mm |
| 100 |
PRC Envelope #5 x mm |
| 101 |
PRC Envelope #6 x mm |
| 102 |
PRC Envelope #7 x mm |
| 103 |
PRC Envelope #8 x 309 mm |
| 104 |
PRC Envelope #9 229 x 324 mm |
| 105 |
PRC Envelope #10 324 x 458 mm |
| 106 |
PRC 16K Rotated |
| 107 |
PRC 32K Rotated |
| 108 |
PRC 32K (Big) rotated |
| 109 |
PRC Envelope #1 Rotated 165 x 102 mm |
| 110 |
PRC Envelope #2 Rotated 176 x 102 mm |
| 111 |
PRC Envelope #3 rotated 176 x mm |
| 112 |
PRC Envelope #4 rotated 208 x mm |
| 113 |
PRC Envelope #5 Rotated x mm |
| 114 |
PRC Envelope #6 Rotated x mm |
| 115 |
PRC Envelope #7 Rotated x mm |
| 116 |
PRC Envelope #8 Rotated 309 x mm |
| 117 |
PRC Envelope #9 Rotated 324 x 229 mm |
| 118 |
PRC Envelope #10 Rotated 458 x 324 mm |
(This table was excerpted from Excel Binary File Format (. xls) Structure specification.pdf)
Npoi 1.2.4 In the paper constants are represented by PaperSize, such as papersize.a4, but are very common paper size, if you do not meet your needs, you can assign the PaperSize property according to the table above. So, if you want to set the paper size you can use this code:
Hssfsheet.printsetup.papersize= (short) papersize.a5;
Or
hssfsheet.printsetup.papersize=9; (A4 210*297mm)
Four, print the starting page number
It corresponds to HSSFSheet.PrintSetup.PageStart and HSSFSheet.PrintSetup.UsePage, if usepage=false, then the equivalent of "automatic", then Pagestart does not work ; if Usepage=true,pagestart will work. Therefore, you must set the Usepage to true before setting the Pagestart.
Five, grid lines
Set by Hssfsheet.isprintgridlines. But be aware that this is not hssfsheet.printsetup below, so don't confuse it. The reason why this is not subordinate to Printsetup is determined by the record of the underlying storage of this information, and the bottom layer is to put isgridsprinted in Gridsetrecord, not printsetuprecord inside, although the interface is put together.
Six, monochrome printing
It corresponds to the HSSFSheet.PrintSetup.NoColors property, a Boolean type, and a value of true when it represents monochrome printing.
Vii. Quality of drafts
It corresponds to the HSSFSheet.PrintSetup.IsDraft property, Boolean type, when True, that represents the print with draft quality.
Eight, printing order
The Boolean type, when True, is controlled by the HSSFSheet.PrintSetup.LeftToRight property, which means "column first" and, if False, "row by column".
Nine, "Error cell printing as" setting
Controlled by the HSSFSheet.PrintSetup.CellError property, Displaycellerrortype enum type, defined below
| 1234567 |
public enum DisplayCellErrorType{ ErrorDisplayOnSheet, //dispayed ErrorAsBlank, //<blank> ErrorAsDashes, //-- ErrorAsNA, //#N/A}</blank> |
The Errorasna here is the meaning of #n/a.
X. annotations
Set by HSSFSheet.PrintSetup.Notes and HSSFSheet.PrintSetup.EndNote, HSSFSheet.PrintSetup.Notes whether to set a Boolean type that requires no print annotations, and Hssfsheet.printse Tup. Endnote is responsible for setting whether it appears at the end of the worksheet, or "as shown in the worksheet."
For an example of printing, refer to the Setprintsettingsinxls project in Npoi.examples.
Area printing: Workbook.setprintarea (Sheet page index, start column number, end column number, start line number, end line number)
Print Title:
Top header row: Sheet.repeatingrows = New cellrangeaddress (start line number, end line number, start column number, end column number)
Left End header row: Sheet.repeatingcolumns = New cellrangeaddress (start line number, end line number, start column number, ending column number)
Npoi Print Settings