Skip to content

Commit 9cf17e8

Browse files
Merge branch 'dev'
2 parents 6b481b2 + 7b936e6 commit 9cf17e8

File tree

8 files changed

+210
-12
lines changed

8 files changed

+210
-12
lines changed

Changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Change Log
22

3+
## v3.2.0
4+
5+
---
6+
Release Date: **07.09.2023**
7+
8+
- Added worksheet option for zoom factors
9+
- Added worksheet option for view types (e.g. page break preview)
10+
- Added worksheet option to show or hide grid lines
11+
- Added worksheet option to show or hide columns and row headers
12+
- Added worksheet option to show or hide rulers in page layout view type
13+
14+
315
## v3.1.1
416

517
---

Demo .NET Standard/Demo .NET Standard.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<Copyright>Copyright Raphael Stoeckli © 2023</Copyright>
99
<RepositoryUrl>https://github.com/rabanti-github/PicoXLSX.git</RepositoryUrl>
1010
<PackageProjectUrl>https://github.com/rabanti-github/PicoXLSX</PackageProjectUrl>
11-
<AssemblyVersion>3.1.1.0</AssemblyVersion>
12-
<FileVersion>3.1.1.0</FileVersion>
13-
<Version>3.1.1</Version>
11+
<AssemblyVersion>3.2.0.0</AssemblyVersion>
12+
<FileVersion>3.2.0.0</FileVersion>
13+
<Version>3.2.0</Version>
1414
<Description>Demo Library showing the use of PicoXLSX, a library to generate Microsoft Excel files (XLSX) in an easy and native way</Description>
1515
<StartupObject>Demo.Program</StartupObject>
1616
<PackageLicenseExpression>MIT</PackageLicenseExpression>

Demo/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("3.1.1.0")]
36-
[assembly: AssemblyFileVersion("3.1.1.0")]
35+
[assembly: AssemblyVersion("3.2.0.0")]
36+
[assembly: AssemblyFileVersion("3.2.0.0")]

PicoXLSX .NET Standard/PicoXLSX .NET Standard.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
55
<RootNamespace>PicoXLSX</RootNamespace>
66
<PackageId>PicoXLSX</PackageId>
7-
<Version>3.1.1</Version>
7+
<Version>3.2.0</Version>
88
<Authors>Raphael Stoeckli</Authors>
99
<Company></Company>
1010
<Product>PicoXLSX</Product>
@@ -17,8 +17,8 @@
1717
<PackageTags>Excel Office XLSX</PackageTags>
1818
<PackageReleaseNotes>Please see https://github.com/rabanti-github/PicoXLSX/blob/master/Changelog.md for the release notes</PackageReleaseNotes>
1919
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
20-
<AssemblyVersion>3.1.1.0</AssemblyVersion>
21-
<FileVersion>3.1.1.0</FileVersion>
20+
<AssemblyVersion>3.2.0.0</AssemblyVersion>
21+
<FileVersion>3.2.0.0</FileVersion>
2222
<AssemblyName>PicoXLSX</AssemblyName>
2323
<ApplicationIcon>favicon.ico</ApplicationIcon>
2424
</PropertyGroup>

PicoXLSX/LowLevel.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ private string CreateWorksheetPart(Worksheet worksheet)
386386
{
387387
sb.Append("<dimension ref=\"").Append(new Cell.Range(worksheet.GetFirstCellAddress().Value, worksheet.GetLastCellAddress().Value)).Append("\"/>");
388388
}
389-
if (worksheet.SelectedCellRanges.Count > 0 || worksheet.PaneSplitTopHeight != null || worksheet.PaneSplitLeftWidth != null || worksheet.PaneSplitAddress != null || worksheet.Hidden)
389+
if (worksheet.SelectedCellRanges.Count > 0 || worksheet.PaneSplitTopHeight != null || worksheet.PaneSplitLeftWidth != null || worksheet.PaneSplitAddress != null ||
390+
worksheet.Hidden || worksheet.ZoomFactor != 100 || worksheet.ZoomFactors.Count > 1 || !worksheet.ShowGridLines || !worksheet.ShowRuler || !worksheet.ShowRowColumnHeaders || worksheet.ViewType != Worksheet.SheetViewType.normal)
390391
{
391392
CreateSheetViewString(worksheet, sb);
392393
}
@@ -467,6 +468,54 @@ private void CreateSheetViewString(Worksheet worksheet, StringBuilder sb)
467468
{
468469
sb.Append(" tabSelected=\"1\"");
469470
}
471+
if (worksheet.ViewType != Worksheet.SheetViewType.normal)
472+
{
473+
if (worksheet.ViewType == Worksheet.SheetViewType.pageLayout)
474+
{
475+
if (worksheet.ShowRuler)
476+
{
477+
sb.Append(" showRuler=\"1\"");
478+
}
479+
else
480+
{
481+
sb.Append(" showRuler=\"0\"");
482+
}
483+
sb.Append(" view=\"pageLayout\"");
484+
485+
}
486+
else if (worksheet.ViewType == Worksheet.SheetViewType.pageBreakPreview)
487+
{
488+
sb.Append(" view=\"pageBreakPreview\"");
489+
}
490+
}
491+
if (!worksheet.ShowGridLines)
492+
{
493+
sb.Append(" showGridLines=\"0\"");
494+
}
495+
if (!worksheet.ShowRowColumnHeaders)
496+
{
497+
sb.Append(" showRowColHeaders=\"0\"");
498+
}
499+
sb.Append(" zoomScale=\"").Append(worksheet.ZoomFactor.ToString("G", culture)).Append("\"");
500+
foreach(KeyValuePair<Worksheet.SheetViewType, int> scaleFactor in worksheet.ZoomFactors)
501+
{
502+
if (scaleFactor.Key == worksheet.ViewType)
503+
{
504+
continue;
505+
}
506+
if (scaleFactor.Key == Worksheet.SheetViewType.normal)
507+
{
508+
sb.Append(" zoomScaleNormal=\"").Append(scaleFactor.Value.ToString("G", culture)).Append("\"");
509+
}
510+
else if (scaleFactor.Key == Worksheet.SheetViewType.pageBreakPreview)
511+
{
512+
sb.Append(" zoomScaleSheetLayoutView=\"").Append(scaleFactor.Value.ToString("G", culture)).Append("\"");
513+
}
514+
else if (scaleFactor.Key == Worksheet.SheetViewType.pageLayout)
515+
{
516+
sb.Append(" zoomScalePageLayoutView=\"").Append(scaleFactor.Value.ToString("G", culture)).Append("\"");
517+
}
518+
}
470519
sb.Append(">");
471520
CreatePaneString(worksheet, sb);
472521
if (worksheet.SelectedCells != null)

PicoXLSX/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@
3030
// You can specify all the values or you can default the Build and Revision Numbers
3131
// by using the '*' as shown below:
3232
// [assembly: AssemblyVersion("1.0.*")]
33-
[assembly: AssemblyVersion("3.1.1")]
34-
[assembly: AssemblyFileVersion("3.1.1")]
33+
[assembly: AssemblyVersion("3.2.0")]
34+
[assembly: AssemblyFileVersion("3.2.0")]

PicoXLSX/Workbook.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,8 @@ public void Up()
983983
/// Moves the cursor the number of defined rows up
984984
/// </summary>
985985
/// <param name="numberOfRows">Number of rows to move.</param>
986-
/// <param name="keepColumnPosition">If true, the column position is preserved, otherwise set to 0.</param>
986+
/// <param name="keepColumnPosition">If true, the column position is preserved, otherwise set to 0</param>
987+
/// <remarks>An exception will be thrown if the row number is below 0. Values (number of rows) can be also negative. However, this is the equivalent of the function <see cref="Down(int, bool)"/></remarks>
987988
public void Up(int numberOfRows, bool keepColumnPosition = false)
988989
{
989990
NullCheck();

PicoXLSX/Worksheet.cs

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ public class Worksheet
8080
/// </summary>
8181
public const float MAX_ROW_HEIGHT = 409.5f;
8282

83+
/// <summary>
84+
/// Automatic zoom factor of a worksheet
85+
/// </summary>
86+
public const int AUTO_ZOOM_FACTOR = 0;
87+
88+
/// <summary>
89+
/// Minimum zoom factor of a worksheet
90+
/// </summary>
91+
public const int MIN_ZOOM_FACTOR = 10;
92+
93+
/// <summary>
94+
/// Maximum zoom factor of a worksheet
95+
/// </summary>
96+
public const int MAX_ZOOM_FACTOR = 400;
97+
8398
/// <summary>
8499
/// Enum to define the direction when using AddNextCell method
85100
/// </summary>
@@ -146,6 +161,19 @@ public enum WorksheetPane
146161
topLeft
147162
}
148163

164+
/// <summary>
165+
/// Enum to define how a worksheet is displayed in the spreadsheet application (Excel)
166+
/// </summary>
167+
public enum SheetViewType
168+
{
169+
/// <summary>The worksheet is displayed without pagination (default)</summary>
170+
normal,
171+
/// <summary>The worksheet is displayed with indicators where the page would break if it were printed</summary>
172+
pageBreakPreview,
173+
/// <summary>The worksheet is displayed like it would be printed</summary>
174+
pageLayout
175+
}
176+
149177
/// <summary>
150178
/// Defines the activeStyle
151179
/// </summary>
@@ -276,6 +304,16 @@ public enum WorksheetPane
276304
/// </summary>
277305
private int sheetID;
278306

307+
/// <summary>
308+
/// Defines how the current worksheet is displayed in the spreadsheet application (Excel)
309+
/// </summary>
310+
private SheetViewType viewType;
311+
312+
/// <summary>
313+
/// Defines the zoom factors of the current worksheet for each view type
314+
/// </summary>
315+
private Dictionary<SheetViewType, int> zoomFactor;
316+
279317
/// <summary>
280318
/// Gets the range of the auto-filter. Wrapped to Nullable to provide null as value. If null, no auto-filter is applied
281319
/// </summary>
@@ -548,6 +586,66 @@ public Style ActiveStyle
548586
get { return activeStyle; }
549587
}
550588

589+
/// <summary>
590+
/// Gets or sets whether grid lines are visible on the current worksheet. Default is true
591+
/// </summary>
592+
public bool ShowGridLines { get; set; }
593+
594+
/// <summary>
595+
/// Gets or sets whether the column and row headers are visible on the current worksheet. Default is true
596+
/// </summary>
597+
public bool ShowRowColumnHeaders { get; set; }
598+
599+
/// <summary>
600+
/// Gets or sets whether a ruler is displayed over the column headers. This value only applies if <see cref="ViewType"/> is set to <see cref="SheetViewType.pageLayout"/>. Default is true
601+
/// </summary>
602+
public bool ShowRuler { get; set; }
603+
604+
/// <summary>
605+
/// Gets or sets how the current worksheet is displayed in the spreadsheet application (Excel)
606+
/// </summary>
607+
public SheetViewType ViewType
608+
{
609+
get
610+
{
611+
return viewType;
612+
}
613+
set
614+
{
615+
viewType = value;
616+
SetZoomFactor(value, 100);
617+
}
618+
}
619+
620+
/// <summary>
621+
/// Gets or sets the zoom factor of the <see cref="ViewType"/> of the current worksheet. If <see cref="AUTO_ZOOM_FACTOR"/>, the zoom factor is set to automatic
622+
/// </summary>
623+
/// <remarks>It is possible to add further zoom factors for inactive view types, using the function <see cref="SetZoomFactor(SheetViewType, int)"/> </remarks>
624+
/// <exception cref="WorksheetException">Throws a WorksheetException if the zoom factor is not <see cref="AUTO_ZOOM_FACTOR"/> or below <see cref="MIN_ZOOM_FACTOR"/> or above <see cref="MAX_ZOOM_FACTOR"/></exception>
625+
public int ZoomFactor
626+
{
627+
set
628+
{
629+
SetZoomFactor(viewType, value);
630+
}
631+
get
632+
{
633+
return zoomFactor[viewType];
634+
}
635+
}
636+
637+
/// <summary>
638+
/// Gets all defined zoom factors per <see cref="SheetViewType"/> of the current worksheet. Use <see cref="SetZoomFactor(SheetViewType, int)"/> to define the values
639+
/// </summary>
640+
public Dictionary<SheetViewType, int> ZoomFactors
641+
{
642+
get
643+
{
644+
return zoomFactor;
645+
}
646+
}
647+
648+
551649
/// <summary>
552650
/// Initializes a new instance of the <see cref="Worksheet"/> class
553651
/// </summary>
@@ -567,6 +665,12 @@ public Worksheet()
567665
selectedCells = new List<Range>();
568666
activeStyle = null;
569667
workbookReference = null;
668+
viewType = SheetViewType.normal;
669+
zoomFactor = new Dictionary<SheetViewType, int>();
670+
zoomFactor.Add(viewType, 100);
671+
ShowGridLines = true;
672+
ShowRowColumnHeaders = true;
673+
ShowRuler = true;
570674
}
571675

572676
/// <summary>
@@ -2210,6 +2314,15 @@ public Worksheet Copy()
22102314
}
22112315
copy.useActiveStyle = this.useActiveStyle;
22122316
copy.UseSheetProtection = this.UseSheetProtection;
2317+
copy.ShowGridLines = this.ShowGridLines;
2318+
copy.ShowRowColumnHeaders = this.ShowRowColumnHeaders;
2319+
copy.ShowRuler = this.ShowRuler;
2320+
copy.ViewType = this.ViewType;
2321+
copy.zoomFactor.Clear();
2322+
foreach(KeyValuePair<SheetViewType, int> zoomFactor in this.zoomFactor)
2323+
{
2324+
copy.SetZoomFactor(zoomFactor.Key, zoomFactor.Value);
2325+
}
22132326
return copy;
22142327
}
22152328

@@ -2241,6 +2354,29 @@ public static string SanitizeWorksheetName(string input, Workbook workbook)
22412354
return GetUnusedWorksheetName(sb.ToString(), workbook);
22422355
}
22432356

2357+
/// <summary>
2358+
/// Sets a zoom factor for a given <see cref="SheetViewType"/>. If <see cref="AUTO_ZOOM_FACTOR"/>, the zoom factor is set to automatic
2359+
/// </summary>
2360+
/// <param name="sheetViewType">Sheet view type to apply the zoom factor on</param>
2361+
/// <param name="zoomFactor">Zoom factor in percent</param>
2362+
/// <remarks>This factor is not the currently set factor. use the property <see cref="ZoomFactor"/> to set the factor for the current <see cref="ViewType"/></remarks>
2363+
/// <exception cref="WorksheetException">Throws a WorksheetException if the zoom factor is not <see cref="AUTO_ZOOM_FACTOR"/> or below <see cref="MIN_ZOOM_FACTOR"/> or above <see cref="MAX_ZOOM_FACTOR"/></exception>
2364+
public void SetZoomFactor(SheetViewType sheetViewType, int zoomFactor)
2365+
{
2366+
if (zoomFactor != AUTO_ZOOM_FACTOR && (zoomFactor < MIN_ZOOM_FACTOR || MAX_ZOOM_FACTOR > 400))
2367+
{
2368+
throw new WorksheetException("The zoom factor " + zoomFactor + " is not valid. Valid are values between " + MIN_ZOOM_FACTOR + " and " + MAX_ZOOM_FACTOR + ", or " + AUTO_ZOOM_FACTOR + " (automatic)");
2369+
}
2370+
if (this.zoomFactor.ContainsKey(sheetViewType))
2371+
{
2372+
this.zoomFactor[sheetViewType] = zoomFactor;
2373+
}
2374+
else
2375+
{
2376+
this.zoomFactor.Add(sheetViewType, zoomFactor);
2377+
}
2378+
}
2379+
22442380
/// <summary>
22452381
/// Determines the next unused worksheet name in the passed workbook
22462382
/// </summary>

0 commit comments

Comments
 (0)