I am using NPOI library to read in an existing workbook, and create a new one. When creating an HSSFSheet. I see that there is a method called SetZoom. What I don't see is a GetZoom method, or a Zoom property, in order to tell what that Zoom level is on the existing Worksheet. Any ideas?
NPOI GetZoom of Worksheet
525 Views Asked by David P At
2
There are 2 best solutions below
1

Thanks to C. Helling, I was able to deduce that the Zoom was stored in the Window2. It, however, is stored as integer (eg - 65 for 65%, 150 for 150%). Setting the zoom of the new worksheet based off the zoom of the old sheet, is pretty easy:
destWS.SetZoom(sourceWS.Sheet.WindowTwo.NormalZoom, 100)
This isn't going to be a satisfying answer, because I'm not sure there is one. I looked through the NPOI source code (SetZoom() in line 1161) as well as the original java source code from which is was ported (SetZoom() in line 1083). As you can see, the
SetZoom()
method simply creates anSCLRecord
:And digging further (in the original java):
Where we can see that it saves this information into a private field of
ISheet
(InternalSheet
in java):Thus, this information is not publicly accessible. If the Zoom is not set, it defaults to 100%, but I'm not aware of any way to access the Zoom of an existing sheet, as there doesn't seem to be any way to do this in NPOI short of modifying the internal source code yourself. Even so, this would only give you the zoom level that you set, as opposed to the existing one already on the worksheet.
It might be possible in EPPlus if you access the
worksheet.View.ZoomScale
, but I am currently unable to test this at the moment.