Skip to content

Commit dee7037

Browse files
Merge branch 'dev'
2 parents 1a4ceb4 + 3b75de8 commit dee7037

File tree

9 files changed

+153
-25
lines changed

9 files changed

+153
-25
lines changed

Changelog.md

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

3+
## v3.3.0
4+
5+
---
6+
Release Date: **23.07.2024**
7+
8+
- Adapted handling of the font scheme in styles. The scheme is now determined automatically
9+
- Added column option to define a default column style
10+
311
## v3.2.1
412

513
---

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 © 2024</Copyright>
99
<RepositoryUrl>https://github.com/rabanti-github/PicoXLSX.git</RepositoryUrl>
1010
<PackageProjectUrl>https://github.com/rabanti-github/PicoXLSX</PackageProjectUrl>
11-
<AssemblyVersion>3.2.1.0</AssemblyVersion>
12-
<FileVersion>3.2.1.0</FileVersion>
13-
<Version>3.2.1</Version>
11+
<AssemblyVersion>3.3.0.0</AssemblyVersion>
12+
<FileVersion>3.2.0.0</FileVersion>
13+
<Version>3.3.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.2.1.0")]
36-
[assembly: AssemblyFileVersion("3.2.1.0")]
35+
[assembly: AssemblyVersion("3.3.0.0")]
36+
[assembly: AssemblyFileVersion("3.3.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.2.1</Version>
7+
<Version>3.3.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.2.1.0</AssemblyVersion>
21-
<FileVersion>3.2.1.0</FileVersion>
20+
<AssemblyVersion>3.3.0.0</AssemblyVersion>
21+
<FileVersion>3.3.0.0</FileVersion>
2222
<AssemblyName>PicoXLSX</AssemblyName>
2323
<ApplicationIcon>favicon.ico</ApplicationIcon>
2424
</PropertyGroup>

PicoXLSX/LowLevel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,12 @@ private string CreateColsString(Worksheet worksheet)
923923
}
924924
col = (column.Key + 1).ToString("G", culture); // Add 1 for Address
925925
float width = GetInternalColumnWidth(column.Value.Width);
926-
sb.Append("<col customWidth=\"1\" width=\"").Append(width.ToString("G", culture)).Append("\" max=\"").Append(col).Append("\" min=\"").Append(col).Append("\"").Append(hidden).Append("/>");
926+
sb.Append("<col customWidth=\"1\" width=\"").Append(width.ToString("G", culture)).Append("\" max=\"").Append(col).Append("\" min=\"").Append(col).Append("\"");
927+
if (column.Value.DefaultColumnStyle != null)
928+
{
929+
sb.Append(" style=\"").Append(column.Value.DefaultColumnStyle.InternalID.Value.ToString("G", culture)).Append("\"");
930+
}
931+
sb.Append(hidden).Append("/>");
927932
}
928933
string value = sb.ToString();
929934
if (value.Length > 0)

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.2.1")]
34-
[assembly: AssemblyFileVersion("3.2.1")]
33+
[assembly: AssemblyVersion("3.3.0")]
34+
[assembly: AssemblyFileVersion("3.3.0")]

PicoXLSX/Style.cs

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,10 +1188,25 @@ public static void ValidateColor(string hexCode, bool useAlpha, bool allowEmpty
11881188
/// </summary>
11891189
public class Font : AbstractStyle
11901190
{
1191+
/// <summary>
1192+
/// The default font name that is declared as Major Font (See <see cref="Font.SchemeValue"/>)
1193+
/// </summary>
1194+
public static readonly string DEFAULT_MAJOR_FONT = "Calibri Light";
1195+
1196+
/// <summary>
1197+
/// The default font name that is declared as Minor Font (See <see cref="Font.SchemeValue"/>)
1198+
/// </summary>
1199+
public static readonly string DEFAULT_MINOR_FONT = "Calibri";
1200+
11911201
/// <summary>
11921202
/// Default font family as constant
11931203
/// </summary>
1194-
public static readonly string DEFAULT_FONT_NAME = "Calibri";
1204+
public static readonly string DEFAULT_FONT_NAME = DEFAULT_MINOR_FONT;
1205+
1206+
/// <summary>
1207+
/// Default font scheme
1208+
/// </summary>
1209+
public static readonly SchemeValue DEFAULT_FONT_SCHEME = SchemeValue.minor;
11951210

11961211
/// <summary>
11971212
/// Maximum possible font size
@@ -1213,11 +1228,6 @@ public class Font : AbstractStyle
12131228
/// </summary>
12141229
public static readonly string DEFAULT_FONT_FAMILY = "2";
12151230

1216-
/// <summary>
1217-
/// Default font scheme
1218-
/// </summary>
1219-
public static readonly SchemeValue DEFAULT_FONT_SCHEME = SchemeValue.minor;
1220-
12211231
/// <summary>
12221232
/// Default vertical alignment
12231233
/// </summary>
@@ -1375,11 +1385,8 @@ public string Name
13751385
get { return name; }
13761386
set
13771387
{
1378-
if (string.IsNullOrEmpty(name))
1379-
{
1380-
throw new StyleException("A general style exception occurred", "The font name was null or empty");
1381-
}
13821388
name = value;
1389+
ValidateFontScheme();
13831390
}
13841391
}
13851392

@@ -1434,6 +1441,30 @@ public Font()
14341441
VerticalAlign = DEFAULT_VERTICAL_ALIGN;
14351442
}
14361443

1444+
/// <summary>
1445+
/// Validates the font name and sets the scheme automatically
1446+
/// </summary>
1447+
private void ValidateFontScheme()
1448+
{
1449+
if (string.IsNullOrEmpty(name))
1450+
{
1451+
throw new StyleException("A general style exception occurred", "The font name was null or empty");
1452+
}
1453+
if (name.Equals(DEFAULT_MINOR_FONT))
1454+
{
1455+
Scheme = SchemeValue.minor;
1456+
}
1457+
else if (name.Equals(DEFAULT_MAJOR_FONT))
1458+
{
1459+
Scheme = SchemeValue.major;
1460+
}
1461+
else
1462+
{
1463+
Scheme = SchemeValue.none;
1464+
}
1465+
}
1466+
1467+
14371468
/// <summary>
14381469
/// Override toString method
14391470
/// </summary>

PicoXLSX/StyleManager.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ namespace PicoXLSX
1010
using System;
1111
using System.Collections.Generic;
1212
using static PicoXLSX.Style;
13+
using static PicoXLSX.Worksheet;
1314

14-
/// <summary>
15-
/// Class representing a style manager to maintain all styles and its components of a workbook
16-
/// </summary>
17-
public class StyleManager
15+
/// <summary>
16+
/// Class representing a style manager to maintain all styles and its components of a workbook
17+
/// </summary>
18+
public class StyleManager
1819
{
1920
/// <summary>
2021
/// Defines the borders
@@ -433,6 +434,14 @@ internal static StyleManager GetManagedStyles(Workbook workbook)
433434
workbook.Worksheets[i].Cells[cell.Key].SetStyle(resolvedStyle, true);
434435
}
435436
}
437+
foreach (KeyValuePair<int, Column> column in workbook.Worksheets[i].Columns)
438+
{
439+
if (column.Value.DefaultColumnStyle != null)
440+
{
441+
Style resolvedStyle = styleManager.AddStyle(column.Value.DefaultColumnStyle);
442+
workbook.Worksheets[i].Columns[column.Key].SetDefaultColumnStyle(resolvedStyle, true);
443+
}
444+
}
436445
}
437446
return styleManager;
438447
}

PicoXLSX/Worksheet.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,42 @@ public void SetColumnWidth(int columnNumber, float width)
19181918
}
19191919
}
19201920

1921+
/// <summary>
1922+
/// Sets the default column style of the passed column address
1923+
/// </summary>
1924+
/// <param name="columnAddress">Column address (A - XFD)</param>
1925+
/// <param name="style">Style to set as default. If null, the style is cleared</param>
1926+
/// <returns>Assigned style or null if cleared</returns>
1927+
/// <exception cref="RangeException">Throws a RangeException:<br></br>a) If the passed column address is out of range<br></br>b) if the column width is out of range (0 - 255.0)</exception>
1928+
public Style SetColumnDefaultStyle(string columnAddress, Style style)
1929+
{
1930+
int columnNumber = Cell.ResolveColumn(columnAddress);
1931+
return SetColumnDefaultStyle(columnNumber, style);
1932+
}
1933+
1934+
/// <summary>
1935+
/// Sets the default column style of the passed column number (zero-based)
1936+
/// </summary>
1937+
/// <param name="columnNumber">Column number (zero-based, from 0 to 16383)</param>
1938+
/// <param name="style">Style to set as default. If null, the style is cleared</param>
1939+
/// <returns>Assigned style or null if cleared</returns>
1940+
/// <exception cref="RangeException">Throws a RangeException:<br></br>a) If the passed column number is out of range<br></br>b) if the column width is out of range (0 - 255.0)</exception>
1941+
public Style SetColumnDefaultStyle(int columnNumber, Style style)
1942+
{
1943+
Cell.ValidateColumnNumber(columnNumber);
1944+
if (this.columns.ContainsKey(columnNumber))
1945+
{
1946+
return this.columns[columnNumber].SetDefaultColumnStyle(style);
1947+
}
1948+
else
1949+
{
1950+
Column c = new Column(columnNumber);
1951+
Style returnStyle = c.SetDefaultColumnStyle(style);
1952+
this.columns.Add(columnNumber, c);
1953+
return returnStyle;
1954+
}
1955+
}
1956+
19211957
/// <summary>
19221958
/// Set the current cell address
19231959
/// </summary>
@@ -2459,6 +2495,11 @@ public class Column
24592495
/// </summary>
24602496
private float width;
24612497

2498+
/// <summary>
2499+
/// Defines the default column style
2500+
/// </summary>
2501+
private Style defaultColumnStyle;
2502+
24622503
/// <summary>
24632504
/// Gets or sets the ColumnAddress
24642505
/// Column address (A to XFD)
@@ -2520,12 +2561,45 @@ public float Width
25202561
}
25212562
}
25222563

2564+
/// <summary>
2565+
/// Gets the default style of the column
2566+
/// </summary>
2567+
public Style DefaultColumnStyle
2568+
{
2569+
get { return this.defaultColumnStyle; }
2570+
}
2571+
2572+
/// <summary>
2573+
/// Sets the default style of the column
2574+
/// </summary>
2575+
/// <param name="defaultColumnStyle">Style to assign as default column style. Can be null (to clear)</param>
2576+
/// <param name="unmanaged">Internally used: If true, the style repository is not invoked and only the style object of the cell is updated. Do not use!</param>
2577+
/// <returns>If the passed style already exists in the repository, the existing one will be returned, otherwise the passed one</returns>
2578+
public Style SetDefaultColumnStyle(Style defaultColumnStyle, bool unmanaged = false)
2579+
{
2580+
if (defaultColumnStyle == null)
2581+
{
2582+
this.defaultColumnStyle = null;
2583+
return null;
2584+
}
2585+
if (unmanaged)
2586+
{
2587+
this.defaultColumnStyle = defaultColumnStyle;
2588+
}
2589+
else
2590+
{
2591+
this.defaultColumnStyle = StyleRepository.Instance.AddStyle(defaultColumnStyle);
2592+
}
2593+
return this.defaultColumnStyle;
2594+
}
2595+
25232596
/// <summary>
25242597
/// Prevents a default instance of the <see cref="Column"/> class from being created
25252598
/// </summary>
25262599
private Column()
25272600
{
25282601
Width = DEFAULT_COLUMN_WIDTH;
2602+
defaultColumnStyle = null;
25292603
}
25302604

25312605
/// <summary>
@@ -2558,6 +2632,7 @@ internal Column Copy()
25582632
copy.HasAutoFilter = this.HasAutoFilter;
25592633
copy.columnAddress = this.columnAddress;
25602634
copy.number = this.number;
2635+
copy.defaultColumnStyle = this.defaultColumnStyle;
25612636
return copy;
25622637
}
25632638
}

0 commit comments

Comments
 (0)