[NWD] Fix EPPlus loading issue with certain spreadsheets.
ExcelPackage.Workbook was being accessed before it was initialized; this
change just passes the workbook to the constructor of the classes that
need it.
Change-Id: I7ebd4dfe02011ab117ecffc35168f0b2066ccfdf
Reviewed-on: https://gnocchi-internal-review.git.corp.google.com/c/third_party/epplus/+/207700
Reviewed-by: Hughes Hilton <hugheshilton@google.com>
diff --git a/EPPlus/CellStore.cs b/EPPlus/CellStore.cs
index c767a82..71aece7 100644
--- a/EPPlus/CellStore.cs
+++ b/EPPlus/CellStore.cs
@@ -1583,15 +1583,15 @@
}
internal class CellsStoreEnumerator<T> : IEnumerable<T>, IEnumerator<T> {
- private CellStore<T> _cellStore;
+ private readonly CellStore<T> _cellStore;
private int row,
colPos;
private int[] pagePos,
cellPos;
- private int _startRow,
- _startCol,
- _endRow,
- _endCol;
+ private readonly int _startRow;
+ private readonly int _startCol;
+ private readonly int _endRow;
+ private readonly int _endCol;
private int minRow,
minColPos,
maxRow,
diff --git a/EPPlus/ConditionalFormatting/ExcelConditionalFormattingCollection.cs b/EPPlus/ConditionalFormatting/ExcelConditionalFormattingCollection.cs
index 4fe42f4..3c19a93 100644
--- a/EPPlus/ConditionalFormatting/ExcelConditionalFormattingCollection.cs
+++ b/EPPlus/ConditionalFormatting/ExcelConditionalFormattingCollection.cs
@@ -70,8 +70,8 @@
/****************************************************************************************/
- private List<IExcelConditionalFormattingRule> _rules = new();
- private ExcelWorksheet _worksheet;
+ private readonly List<IExcelConditionalFormattingRule> _rules = new();
+ private readonly ExcelWorksheet _worksheet;
/****************************************************************************************/
diff --git a/EPPlus/ConditionalFormatting/ExcelConditionalFormattingColorScaleValue.cs b/EPPlus/ConditionalFormatting/ExcelConditionalFormattingColorScaleValue.cs
index 3331b3e..1f1bda6 100644
--- a/EPPlus/ConditionalFormatting/ExcelConditionalFormattingColorScaleValue.cs
+++ b/EPPlus/ConditionalFormatting/ExcelConditionalFormattingColorScaleValue.cs
@@ -46,7 +46,7 @@
private eExcelConditionalFormattingValueObjectPosition _position;
private eExcelConditionalFormattingRuleType _ruleType;
- private ExcelWorksheet _worksheet;
+ private readonly ExcelWorksheet _worksheet;
/****************************************************************************************/
diff --git a/EPPlus/ConditionalFormatting/ExcelConditionalFormattingIconDatabarValue.cs b/EPPlus/ConditionalFormatting/ExcelConditionalFormattingIconDatabarValue.cs
index 3c7a98b..2e080d2 100644
--- a/EPPlus/ConditionalFormatting/ExcelConditionalFormattingIconDatabarValue.cs
+++ b/EPPlus/ConditionalFormatting/ExcelConditionalFormattingIconDatabarValue.cs
@@ -46,7 +46,7 @@
private eExcelConditionalFormattingRuleType _ruleType;
- private ExcelWorksheet _worksheet;
+ private readonly ExcelWorksheet _worksheet;
/****************************************************************************************/
diff --git a/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingRule.cs b/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingRule.cs
index a9a12ae..a85ebaa 100644
--- a/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingRule.cs
+++ b/EPPlus/ConditionalFormatting/Rules/ExcelConditionalFormattingRule.cs
@@ -42,7 +42,7 @@
/// </summary>
public abstract class ExcelConditionalFormattingRule : XmlHelper, IExcelConditionalFormattingRule {
private eExcelConditionalFormattingRuleType? _type;
- private ExcelWorksheet _worksheet;
+ private readonly ExcelWorksheet _worksheet;
/// <summary>
/// Sinalize that we are in a Cnaging Priorities opeartion so that we won't enter
diff --git a/EPPlus/DataValidation/ExcelDataValidationCollection.cs b/EPPlus/DataValidation/ExcelDataValidationCollection.cs
index 6692f9d..76c07a3 100644
--- a/EPPlus/DataValidation/ExcelDataValidationCollection.cs
+++ b/EPPlus/DataValidation/ExcelDataValidationCollection.cs
@@ -67,8 +67,8 @@
/// </code>
/// </summary>
public class ExcelDataValidationCollection : XmlHelper, IEnumerable<IExcelDataValidation> {
- private List<IExcelDataValidation> _validations = new();
- private ExcelWorksheet _worksheet;
+ private readonly List<IExcelDataValidation> _validations = new();
+ private readonly ExcelWorksheet _worksheet;
private const string _dataValidationPath = "//d:dataValidations";
private readonly string DataValidationItemsPath = string.Format(
diff --git a/EPPlus/DataValidation/Formulas/ExcelDataValidationFormulaList.cs b/EPPlus/DataValidation/Formulas/ExcelDataValidationFormulaList.cs
index bfe5301..55e554b 100644
--- a/EPPlus/DataValidation/Formulas/ExcelDataValidationFormulaList.cs
+++ b/EPPlus/DataValidation/Formulas/ExcelDataValidationFormulaList.cs
@@ -44,7 +44,7 @@
: ExcelDataValidationFormula,
IExcelDataValidationFormulaList {
private class DataValidationList : IList<string>, ICollection {
- private IList<string> _items = new List<string>();
+ private readonly IList<string> _items = new List<string>();
private EventHandler<EventArgs> _listChanged;
public event EventHandler<EventArgs> ListChanged {
@@ -140,7 +140,7 @@
SetInitialValues();
}
- private string _formulaPath;
+ private readonly string _formulaPath;
private void SetInitialValues() {
var value = GetXmlNodeString(_formulaPath);
diff --git a/EPPlus/DataValidation/RangeDataValidation.cs b/EPPlus/DataValidation/RangeDataValidation.cs
index 82bf95d..b09d219 100644
--- a/EPPlus/DataValidation/RangeDataValidation.cs
+++ b/EPPlus/DataValidation/RangeDataValidation.cs
@@ -43,8 +43,8 @@
_address = address;
}
- private ExcelWorksheet _worksheet;
- private string _address;
+ private readonly ExcelWorksheet _worksheet;
+ private readonly string _address;
public IExcelDataValidationAny AddAnyDataValidation() {
return _worksheet.DataValidations.AddAnyValidation(_address);
diff --git a/EPPlus/Drawing/Vml/ExcelVmlDrawingPosition.cs b/EPPlus/Drawing/Vml/ExcelVmlDrawingPosition.cs
index 755fad0..3d02863 100644
--- a/EPPlus/Drawing/Vml/ExcelVmlDrawingPosition.cs
+++ b/EPPlus/Drawing/Vml/ExcelVmlDrawingPosition.cs
@@ -39,7 +39,7 @@
/// The position of a VML drawing. Used for comments
/// </summary>
public class ExcelVmlDrawingPosition : XmlHelper {
- private int _startPos;
+ private readonly int _startPos;
internal ExcelVmlDrawingPosition(XmlNamespaceManager ns, XmlNode topNode, int startPos)
: base(ns, topNode) {
diff --git a/EPPlus/ExcelAddress.cs b/EPPlus/ExcelAddress.cs
index 54e5460..22fcf59 100644
--- a/EPPlus/ExcelAddress.cs
+++ b/EPPlus/ExcelAddress.cs
@@ -162,14 +162,17 @@
/// <param name="address">The Excel Address</param>
/// <param name="pck">Reference to the package to find information about tables and names</param>
/// <param name="referenceAddress">The address</param>
- public ExcelAddressBase(string address, ExcelPackage pck, ExcelAddressBase referenceAddress) {
+ protected ExcelAddressBase(
+ string address,
+ ExcelWorkbook workbook,
+ ExcelAddressBase referenceAddress) {
SetAddress(address);
- SetRcFromTable(pck, referenceAddress);
+ SetRcFromTable(workbook, referenceAddress);
}
- internal void SetRcFromTable(ExcelPackage pck, ExcelAddressBase referenceAddress) {
+ internal void SetRcFromTable(ExcelWorkbook workbook, ExcelAddressBase referenceAddress) {
if (string.IsNullOrEmpty(_wb) && Table != null) {
- foreach (var ws in pck.Workbook.Worksheets) {
+ foreach (var ws in workbook.Worksheets) {
foreach (var t in ws.Tables) {
if (t.Name.Equals(Table.Name, StringComparison.InvariantCultureIgnoreCase)) {
_ws = ws.Name;
@@ -1188,8 +1191,8 @@
}
}
- public ExcelAddress(string address, ExcelPackage package, ExcelAddressBase referenceAddress)
- : base(address, package, referenceAddress) {}
+ public ExcelAddress(string address, ExcelWorkbook workbook, ExcelAddressBase referenceAddress)
+ : base(address, workbook, referenceAddress) {}
/// <summary>
/// The address for the range
diff --git a/EPPlus/ExcelColumn.cs b/EPPlus/ExcelColumn.cs
index bb26958..31bd864 100644
--- a/EPPlus/ExcelColumn.cs
+++ b/EPPlus/ExcelColumn.cs
@@ -40,8 +40,8 @@
/// Represents one or more columns within the worksheet
/// </summary>
public class ExcelColumn : IRangeId {
- private ExcelWorksheet _worksheet;
- private XmlElement _colElement = null;
+ private readonly ExcelWorksheet _worksheet;
+ private readonly XmlElement _colElement = null;
/// <summary>
/// Creates a new instance of the ExcelColumn class.
diff --git a/EPPlus/ExcelComment.cs b/EPPlus/ExcelComment.cs
index acd42ad..9e7409a 100644
--- a/EPPlus/ExcelComment.cs
+++ b/EPPlus/ExcelComment.cs
@@ -41,7 +41,7 @@
/// </summary>
public class ExcelComment : ExcelVmlDrawingComment {
internal XmlHelper _commentHelper;
- private string _text;
+ private readonly string _text;
internal ExcelComment(XmlNamespaceManager ns, XmlNode commentTopNode, ExcelRangeBase cell)
: base(null, cell, cell.Worksheet.VmlDrawingsComments.NameSpaceManager) {
diff --git a/EPPlus/ExcelHeaderFooter.cs b/EPPlus/ExcelHeaderFooter.cs
index 9a53f92..c4a3eeb 100644
--- a/EPPlus/ExcelHeaderFooter.cs
+++ b/EPPlus/ExcelHeaderFooter.cs
@@ -160,7 +160,7 @@
internal ExcelHeaderFooterText _evenFooter;
internal ExcelHeaderFooterText _firstHeader;
internal ExcelHeaderFooterText _firstFooter;
- private ExcelWorksheet _ws;
+ private readonly ExcelWorksheet _ws;
/// <summary>
/// ExcelHeaderFooter Constructor
diff --git a/EPPlus/ExcelNamedRange.cs b/EPPlus/ExcelNamedRange.cs
index da86830..96337ae 100644
--- a/EPPlus/ExcelNamedRange.cs
+++ b/EPPlus/ExcelNamedRange.cs
@@ -36,7 +36,7 @@
/// A named range.
/// </summary>
public sealed class ExcelNamedRange : ExcelRangeBase {
- private ExcelWorksheet _sheet;
+ private readonly ExcelWorksheet _sheet;
/// <summary>
/// A named range
diff --git a/EPPlus/ExcelNamedRangeCollection.cs b/EPPlus/ExcelNamedRangeCollection.cs
index ab281f9..748b7e7 100644
--- a/EPPlus/ExcelNamedRangeCollection.cs
+++ b/EPPlus/ExcelNamedRangeCollection.cs
@@ -53,8 +53,8 @@
_ws = ws;
}
- private List<ExcelNamedRange> _list = new();
- private Dictionary<string, int> _dic = new(StringComparer.InvariantCultureIgnoreCase);
+ private readonly List<ExcelNamedRange> _list = new();
+ private readonly Dictionary<string, int> _dic = new(StringComparer.InvariantCultureIgnoreCase);
/// <summary>
/// Add a new named range
diff --git a/EPPlus/ExcelPackage.cs b/EPPlus/ExcelPackage.cs
index 5bd9395..be8f56e 100644
--- a/EPPlus/ExcelPackage.cs
+++ b/EPPlus/ExcelPackage.cs
@@ -62,102 +62,8 @@
}
/// <summary>
-/// Represents an Excel 2007/2010 XLSX file package.
-/// This is the top-level object to access all parts of the document.
-/// <code>
-/// FileInfo newFile = new FileInfo(outputDir.FullName + @"\sample1.xlsx");
-/// if (newFile.Exists)
-/// {
-/// newFile.Delete(); // ensures we create a new workbook
-/// newFile = new FileInfo(outputDir.FullName + @"\sample1.xlsx");
-/// }
-/// using (ExcelPackage package = new ExcelPackage(newFile))
-/// {
-/// // add a new worksheet to the empty workbook
-/// ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Inventory");
-/// //Add the headers
-/// worksheet.Cells[1, 1].Value = "ID";
-/// worksheet.Cells[1, 2].Value = "Product";
-/// worksheet.Cells[1, 3].Value = "Quantity";
-/// worksheet.Cells[1, 4].Value = "Price";
-/// worksheet.Cells[1, 5].Value = "Value";
-///
-/// //Add some items...
-/// worksheet.Cells["A2"].Value = "12001";
-/// worksheet.Cells["B2"].Value = "Nails";
-/// worksheet.Cells["C2"].Value = 37;
-/// worksheet.Cells["D2"].Value = 3.99;
-///
-/// worksheet.Cells["A3"].Value = "12002";
-/// worksheet.Cells["B3"].Value = "Hammer";
-/// worksheet.Cells["C3"].Value = 5;
-/// worksheet.Cells["D3"].Value = 12.10;
-///
-/// worksheet.Cells["A4"].Value = "12003";
-/// worksheet.Cells["B4"].Value = "Saw";
-/// worksheet.Cells["C4"].Value = 12;
-/// worksheet.Cells["D4"].Value = 15.37;
-///
-/// //Add a formula for the value-column
-/// worksheet.Cells["E2:E4"].Formula = "C2*D2";
-///
-/// //Ok now format the values;
-/// using (var range = worksheet.Cells[1, 1, 1, 5])
-/// {
-/// range.Style.Font.Bold = true;
-/// range.Style.Fill.PatternType = ExcelFillStyle.Solid;
-/// range.Style.Fill.BackgroundColor.SetColor(Color.DarkBlue);
-/// range.Style.Font.Color.SetColor(Color.White);
-/// }
-///
-/// worksheet.Cells["A5:E5"].Style.Border.Top.Style = ExcelBorderStyle.Thin;
-/// worksheet.Cells["A5:E5"].Style.Font.Bold = true;
-///
-/// worksheet.Cells[5, 3, 5, 5].Formula = string.Format("SUBTOTAL(9,{0})", new ExcelAddress(2,3,4,3).Address);
-/// worksheet.Cells["C2:C5"].Style.Numberformat.Format = "#,##0";
-/// worksheet.Cells["D2:E5"].Style.Numberformat.Format = "#,##0.00";
-///
-/// //Create an autofilter for the range
-/// worksheet.Cells["A1:E4"].AutoFilter = true;
-///
-/// worksheet.Cells["A1:E5"].AutoFitColumns(0);
-///
-/// // lets set the header text
-/// worksheet.HeaderFooter.oddHeader.CenteredText = "&24&U&\"Arial,Regular Bold\" Inventory";
-/// // add the page number to the footer plus the total number of pages
-/// worksheet.HeaderFooter.oddFooter.RightAlignedText =
-/// string.Format("Page {0} of {1}", ExcelHeaderFooter.PageNumber, ExcelHeaderFooter.NumberOfPages);
-/// // add the sheet name to the footer
-/// worksheet.HeaderFooter.oddFooter.CenteredText = ExcelHeaderFooter.SheetName;
-/// // add the file path to the footer
-/// worksheet.HeaderFooter.oddFooter.LeftAlignedText = ExcelHeaderFooter.FilePath + ExcelHeaderFooter.FileName;
-///
-/// worksheet.PrinterSettings.RepeatRows = worksheet.Cells["1:2"];
-/// worksheet.PrinterSettings.RepeatColumns = worksheet.Cells["A:G"];
-///
-/// // Change the sheet view to show it in page layout mode
-/// worksheet.View.PageLayoutView = true;
-///
-/// // set some document properties
-/// package.Workbook.Properties.Title = "Invertory";
-/// package.Workbook.Properties.Author = "Jan K�llman";
-/// package.Workbook.Properties.Comments = "This sample demonstrates how to create an Excel 2007 workbook using EPPlus";
-///
-/// // set some extended property values
-/// package.Workbook.Properties.Company = "AdventureWorks Inc.";
-///
-/// // set some custom property values
-/// package.Workbook.Properties.SetCustomPropertyValue("Checked by", "Jan K�llman");
-/// package.Workbook.Properties.SetCustomPropertyValue("AssemblyName", "EPPlus");
-///
-/// // save our new workbook and we are done!
-/// package.Save();
-///
-/// }
-///
-/// return newFile.FullName;
-/// </code>
-/// More samples can be found at <a href="http://epplus.codeplex.com/">http://epplus.codeplex.com/</a>
+/// Represents an Excel XLSX file package.
+/// This is the top-level object to access all parts of the document.\
/// </summary>
public sealed class ExcelPackage {
internal const bool _preserveWhitespace = false;
@@ -232,7 +138,7 @@
public const int MaxRows = 1048576;
/// <summary>
- /// Create a new instance of the ExcelPackage. Output is accessed through the Stream property.
+ /// Create a new, empty package.
/// </summary>
public ExcelPackage() {
Package = new();
@@ -240,15 +146,14 @@
_ = Workbook.WorkbookXml;
// create the relationship to the main part
Package.CreateRelationship(
- UriHelper.GetRelativeUri(new("/xl", UriKind.Relative), Workbook.WorkbookUri),
+ UriHelper.GetRelativeUri(new("/xl", UriKind.Relative), ExcelWorkbook.WorkbookUri),
TargetMode.Internal,
_schemaRelationships + "/officeDocument");
}
/// <summary>
- /// Create a new instance of the ExcelPackage class based on a existing file or creates a new file.
+ /// Create a new instance of the ExcelPackage class based on an existing file.
/// </summary>
- /// <param name="newFile">If newFile exists, it is opened. Otherwise it is created from scratch.</param>
public ExcelPackage(FileInfo newFile) {
using var inputStream = newFile.OpenRead();
Package = new(inputStream);
@@ -256,9 +161,8 @@
}
/// <summary>
- /// Create a new instance of the ExcelPackage class based on a stream
+ /// Create a new instance of the ExcelPackage class based on a stream.
/// </summary>
- /// <param name="newStream">The stream object can be empty or contain a package. The stream must be Read/Write</param>
public ExcelPackage(Stream newStream) {
Package = new(newStream);
Workbook = CreateWorkbook();
@@ -271,9 +175,6 @@
return workbook;
}
- /// <summary>
- /// Returns a reference to the package
- /// </summary>
internal ZipPackage Package { get; }
/// <summary>
diff --git a/EPPlus/ExcelPrinterSettings.cs b/EPPlus/ExcelPrinterSettings.cs
index 17ed052..dcdb541 100644
--- a/EPPlus/ExcelPrinterSettings.cs
+++ b/EPPlus/ExcelPrinterSettings.cs
@@ -405,7 +405,7 @@
/// Printer settings
/// </summary>
public sealed class ExcelPrinterSettings : XmlHelper {
- private ExcelWorksheet _ws;
+ private readonly ExcelWorksheet _ws;
private bool _marginsCreated;
internal ExcelPrinterSettings(XmlNamespaceManager ns, XmlNode topNode, ExcelWorksheet ws)
diff --git a/EPPlus/ExcelProtectedRangeCollection.cs b/EPPlus/ExcelProtectedRangeCollection.cs
index 72afcc3..728a3e4 100644
--- a/EPPlus/ExcelProtectedRangeCollection.cs
+++ b/EPPlus/ExcelProtectedRangeCollection.cs
@@ -26,7 +26,7 @@
}
}
- private List<ExcelProtectedRange> _baseList = new();
+ private readonly List<ExcelProtectedRange> _baseList = new();
public ExcelProtectedRange Add(string name, ExcelAddress address) {
if (!ExistNode("d:protectedRanges")) {
diff --git a/EPPlus/ExcelRangeBase.cs b/EPPlus/ExcelRangeBase.cs
index fd753d6..b94a638 100644
--- a/EPPlus/ExcelRangeBase.cs
+++ b/EPPlus/ExcelRangeBase.cs
@@ -104,8 +104,8 @@
//}
- internal ExcelRangeBase(ExcelWorksheet xlWorksheet) {
- _worksheet = xlWorksheet;
+ internal ExcelRangeBase(ExcelWorksheet worksheet) {
+ _worksheet = worksheet;
_ws = _worksheet.Name;
_workbook = _worksheet.Workbook;
AddressChange += ExcelRangeBase_AddressChange;
@@ -114,16 +114,16 @@
private void ExcelRangeBase_AddressChange(object sender, EventArgs e) {
if (Table != null) {
- SetRcFromTable(_workbook._package, null);
+ SetRcFromTable(_workbook, null);
}
SetDelegate();
}
- internal ExcelRangeBase(ExcelWorksheet xlWorksheet, string address)
- : base(xlWorksheet == null ? "" : xlWorksheet.Name, address) {
- _worksheet = xlWorksheet;
- _workbook = _worksheet.Workbook;
- SetRcFromTable(_worksheet._package, null);
+ internal ExcelRangeBase(ExcelWorksheet worksheet, string address)
+ : base(worksheet == null ? "" : worksheet.Name, address) {
+ _worksheet = worksheet;
+ _workbook = worksheet.Workbook;
+ SetRcFromTable(_workbook, null);
if (string.IsNullOrEmpty(_ws)) {
_ws = _worksheet == null ? "" : _worksheet.Name;
}
@@ -133,7 +133,7 @@
internal ExcelRangeBase(ExcelWorkbook wb, ExcelWorksheet xlWorksheet, string address, bool isName)
: base(xlWorksheet == null ? "" : xlWorksheet.Name, address, isName) {
- SetRcFromTable(wb._package, null);
+ SetRcFromTable(wb, null);
_worksheet = xlWorksheet;
_workbook = wb;
if (string.IsNullOrEmpty(_ws)) {
diff --git a/EPPlus/ExcelRow.cs b/EPPlus/ExcelRow.cs
index fbb0db3..3dfd422 100644
--- a/EPPlus/ExcelRow.cs
+++ b/EPPlus/ExcelRow.cs
@@ -64,8 +64,8 @@
/// Represents an individual row in the spreadsheet.
/// </summary>
public class ExcelRow : IRangeId {
- private ExcelWorksheet _worksheet;
- private XmlElement _rowElement = null;
+ private readonly ExcelWorksheet _worksheet;
+ private readonly XmlElement _rowElement = null;
/// <summary>
/// Internal RowID.
diff --git a/EPPlus/ExcelStyleCollection.cs b/EPPlus/ExcelStyleCollection.cs
index 6ca76f9..2e2d203 100644
--- a/EPPlus/ExcelStyleCollection.cs
+++ b/EPPlus/ExcelStyleCollection.cs
@@ -47,7 +47,7 @@
_setNextIdManual = false;
}
- private bool _setNextIdManual;
+ private readonly bool _setNextIdManual;
public ExcelStyleCollection(bool setNextIdManual) {
_setNextIdManual = setNextIdManual;
@@ -56,7 +56,7 @@
public XmlNode TopNode { get; set; }
internal List<T> _list = new();
- private Dictionary<string, int> _dic = new(StringComparer.InvariantCultureIgnoreCase);
+ private readonly Dictionary<string, int> _dic = new(StringComparer.InvariantCultureIgnoreCase);
internal int NextId;
public IEnumerator<T> GetEnumerator() {
diff --git a/EPPlus/ExcelStyles.cs b/EPPlus/ExcelStyles.cs
index 086189d..8c786e0 100644
--- a/EPPlus/ExcelStyles.cs
+++ b/EPPlus/ExcelStyles.cs
@@ -55,9 +55,9 @@
private const string _dxfsPath = "d:styleSheet/d:dxfs";
//internal Dictionary<int, ExcelXfs> Styles = new Dictionary<int, ExcelXfs>();
- private XmlDocument _styleXml;
- private ExcelWorkbook _wb;
- private XmlNamespaceManager _nameSpaceManager;
+ private readonly XmlDocument _styleXml;
+ private readonly ExcelWorkbook _wb;
+ private readonly XmlNamespaceManager _nameSpaceManager;
internal int _nextDfxNumFmtID = 164;
internal ExcelStyles(XmlNamespaceManager nameSpaceManager, XmlDocument xml, ExcelWorkbook wb)
diff --git a/EPPlus/ExcelWorkbook.cs b/EPPlus/ExcelWorkbook.cs
index ada35ea..3bc05dd 100644
--- a/EPPlus/ExcelWorkbook.cs
+++ b/EPPlus/ExcelWorkbook.cs
@@ -91,9 +91,6 @@
internal ExcelWorkbook(ExcelPackage package, XmlNamespaceManager namespaceManager)
: base(namespaceManager) {
_package = package;
- WorkbookUri = new("/xl/workbook.xml", UriKind.Relative);
- SharedStringsUri = new("/xl/sharedStrings.xml", UriKind.Relative);
- StylesUri = new("/xl/styles.xml", UriKind.Relative);
_names = new(this);
_namespaceManager = namespaceManager;
@@ -247,7 +244,7 @@
//}
}
} else {
- ExcelAddress addr = new ExcelAddress(fullAddress, _package, null);
+ ExcelAddress addr = new ExcelAddress(fullAddress, this, null);
if (localSheetId > -1) {
if (string.IsNullOrEmpty(addr._ws)) {
namedRange = Worksheets[localSheetId + 1].Names.Add(
@@ -286,7 +283,7 @@
sheetsNode = CreateNode("d:sheets");
}
- _worksheets = new(_package, _namespaceManager, sheetsNode);
+ _worksheets = new(_package, this, _namespaceManager, sheetsNode);
}
return (_worksheets);
}
@@ -300,7 +297,7 @@
internal FormulaParser FormulaParser {
get {
if (_formulaParser == null) {
- _formulaParser = new(new EpplusExcelDataProvider(_package));
+ _formulaParser = new(new EpplusExcelDataProvider(this));
}
return _formulaParser;
}
@@ -347,24 +344,22 @@
/// <summary>
/// URI to the workbook inside the package
/// </summary>
- internal Uri WorkbookUri { get; private set; }
+ internal static Uri WorkbookUri { get; } = new("/xl/workbook.xml", UriKind.Relative);
/// <summary>
/// URI to the styles inside the package
/// </summary>
- internal Uri StylesUri { get; private set; }
+ internal static Uri StylesUri { get; } = new("/xl/styles.xml", UriKind.Relative);
/// <summary>
/// URI to the shared strings inside the package
/// </summary>
- internal Uri SharedStringsUri { get; private set; }
+ internal static Uri SharedStringsUri { get; } = new("/xl/sharedStrings.xml", UriKind.Relative);
/// <summary>
/// Returns a reference to the workbook's part within the package
/// </summary>
- internal ZipPackagePart Part {
- get { return (_package.Package.GetPart(WorkbookUri)); }
- }
+ internal ZipPackagePart Part => (_package.Package.GetPart(WorkbookUri));
private XmlDocument _workbookXml;
@@ -499,7 +494,7 @@
//stream.Close();
// create the relationship between the workbook and the new shared strings part
- _package.Workbook.Part.CreateRelationship(
+ Part.CreateRelationship(
UriHelper.GetRelativeUri(WorkbookUri, StylesUri),
TargetMode.Internal,
ExcelPackage._schemaRelationships + "/styles");
@@ -536,7 +531,7 @@
}
}
- private string CALC_MODE_PATH = "d:calcPr/@calcMode";
+ private readonly string CALC_MODE_PATH = "d:calcPr/@calcMode";
/// <summary>
/// Calculation mode for the workbook.
@@ -648,9 +643,9 @@
Uri uriCalcChain = new Uri("/xl/calcChain.xml", UriKind.Relative);
if (_package.Package.PartExists(uriCalcChain)) {
Uri calcChain = new Uri("calcChain.xml", UriKind.Relative);
- foreach (var relationship in _package.Workbook.Part.GetRelationships()) {
+ foreach (var relationship in Part.GetRelationships()) {
if (relationship.TargetUri == calcChain) {
- _package.Workbook.Part.DeleteRelationship(relationship.Id);
+ Part.DeleteRelationship(relationship.Id);
break;
}
}
@@ -660,7 +655,7 @@
}
private void ValidateDataValidations() {
- foreach (var sheet in _package.Workbook.Worksheets) {
+ foreach (var sheet in Worksheets) {
if (!(sheet is ExcelChartsheet)) {
sheet.DataValidations.ValidateAll();
}
diff --git a/EPPlus/ExcelWorksheet.cs b/EPPlus/ExcelWorksheet.cs
index 2579a7e..85a6ccd 100644
--- a/EPPlus/ExcelWorksheet.cs
+++ b/EPPlus/ExcelWorksheet.cs
@@ -88,13 +88,14 @@
public ExcelChartsheet(
XmlNamespaceManager ns,
ExcelPackage pck,
+ ExcelWorkbook workbook,
string relId,
Uri uriWorksheet,
string sheetName,
int sheetId,
int positionId,
eWorkSheetHidden hidden)
- : base(ns, pck, relId, uriWorksheet, sheetName, sheetId, positionId, hidden) {}
+ : base(ns, pck, workbook, relId, uriWorksheet, sheetName, sheetId, positionId, hidden) {}
}
/// <summary>
@@ -145,7 +146,7 @@
return formula;
}
- private ISourceCodeTokenizer _tokenizer;
+ private readonly ISourceCodeTokenizer _tokenizer;
internal int Index { get; set; }
@@ -190,7 +191,7 @@
internal MergeCellsCollection() {}
internal CellStore<int> _cells = new();
- private List<string> _list = new();
+ private readonly List<string> _list = new();
internal List<string> List => _list;
@@ -342,30 +343,21 @@
internal int _minCol = ExcelPackage.MaxColumns;
internal int _maxCol = 0;
- internal ExcelPackage _package;
- private Uri _worksheetUri;
+ internal readonly ExcelPackage _package;
+ private readonly ExcelWorkbook _workbook;
+ private readonly Uri _worksheetUri;
private string _name;
- private int _sheetID;
+ private readonly int _sheetID;
private int _positionID;
- private string _relationshipID;
+ private readonly string _relationshipID;
private XmlDocument _worksheetXml;
- internal ExcelWorksheetView _sheetView;
- internal ExcelHeaderFooter _headerFooter;
+ private ExcelWorksheetView _sheetView;
+ private ExcelHeaderFooter _headerFooter;
- /// <summary>
- /// A worksheet
- /// </summary>
- /// <param name="ns">Namespacemanager</param>
- /// <param name="excelPackage">Package</param>
- /// <param name="relId">Relationship ID</param>
- /// <param name="uriWorksheet">URI</param>
- /// <param name="sheetName">Name of the sheet</param>
- /// <param name="sheetId">Sheet id</param>
- /// <param name="positionId">Position</param>
- /// <param name="hide">hide</param>
- public ExcelWorksheet(
+ internal ExcelWorksheet(
XmlNamespaceManager ns,
ExcelPackage excelPackage,
+ ExcelWorkbook workbook,
string relId,
Uri uriWorksheet,
string sheetName,
@@ -373,6 +365,7 @@
int positionId,
eWorkSheetHidden hide)
: base(ns, null) {
+ _workbook = workbook;
SchemaNodeOrder = new[] {
"sheetPr",
"tabColor",
@@ -418,6 +411,7 @@
"extLst",
};
_package = excelPackage;
+ _workbook = workbook;
_relationshipID = relId;
_worksheetUri = uriWorksheet;
_name = sheetName;
@@ -525,14 +519,14 @@
if (value == _name) {
return;
}
- value = _package.Workbook.Worksheets.ValidateFixSheetName(value);
+ value = _workbook.Worksheets.ValidateFixSheetName(value);
foreach (var ws in Workbook.Worksheets) {
if (ws.PositionID != PositionID
&& ws.Name.Equals(value, StringComparison.InvariantCultureIgnoreCase)) {
throw (new ArgumentException("Worksheet name must be unique"));
}
}
- _package.Workbook.SetXmlNodeString(
+ _workbook.SetXmlNodeString(
string.Format("d:sheets/d:sheet[@sheetId={0}]/@name", _sheetID),
value);
ChangeNames(value);
@@ -576,7 +570,7 @@
/// </summary>
public eWorkSheetHidden Hidden {
get {
- string state = _package.Workbook.GetXmlNodeString(
+ string state = _workbook.GetXmlNodeString(
string.Format("d:sheets/d:sheet[@sheetId={0}]/@state", _sheetID));
if (state == "hidden") {
return eWorkSheetHidden.Hidden;
@@ -588,13 +582,12 @@
}
set {
if (value == eWorkSheetHidden.Visible) {
- _package.Workbook.DeleteNode(
- string.Format("d:sheets/d:sheet[@sheetId={0}]/@state", _sheetID));
+ _workbook.DeleteNode(string.Format("d:sheets/d:sheet[@sheetId={0}]/@state", _sheetID));
} else {
string v;
v = value.ToString();
v = v.Substring(0, 1).ToLower(CultureInfo.InvariantCulture) + v.Substring(1);
- _package.Workbook.SetXmlNodeString(
+ _workbook.SetXmlNodeString(
string.Format("d:sheets/d:sheet[@sheetId={0}]/@state", _sheetID),
v);
}
@@ -1410,16 +1403,16 @@
"ReadElementContentAsInt returned value '{0}' which is less than zero.",
ix));
}
- if (ix >= _package.Workbook._sharedStringsList.Count) {
+ if (ix >= _workbook._sharedStringsList.Count) {
throw new(
string.Format(
"ReadElementContentAsInt returned index value '{0}' which is greater than _sharedStringsList count of {1}.",
ix,
- _package.Workbook._sharedStringsList.Count));
+ _workbook._sharedStringsList.Count));
}
- _values.SetValue(row, col, _package.Workbook._sharedStringsList[ix].Text);
- if (_package.Workbook._sharedStringsList[ix].isRichText) {
+ _values.SetValue(row, col, _workbook._sharedStringsList[ix].Text);
+ if (_workbook._sharedStringsList[ix].isRichText) {
_flags.SetFlagValue(row, col, true, CellFlags.RichText);
}
} else if (type == "str") {
@@ -1521,8 +1514,6 @@
// return (retValue);
//}
-
-
/// <summary>
/// A reference to the header and footer class which allows you to
/// set the header and footer for all odd, even and first pages of the worksheet
@@ -1593,7 +1584,7 @@
}
}
- private MergeCellsCollection _mergedCells = new();
+ private readonly MergeCellsCollection _mergedCells = new();
/// <summary>
/// Addresses to merged ranges
@@ -3179,7 +3170,7 @@
first = false;
}
var col = cse.Value as ExcelColumn;
- ExcelStyleCollection<ExcelXfs> cellXfs = _package.Workbook.Styles.CellXfs;
+ ExcelStyleCollection<ExcelXfs> cellXfs = _workbook.Styles.CellXfs;
sw.Write("<col min=\"{0}\" max=\"{1}\"", col.ColumnMin, col.ColumnMax);
if (col.Hidden) {
@@ -3227,13 +3218,13 @@
/// Insert row and cells into the XML document
/// </summary>
private void UpdateRowCellData(StreamWriter sw) {
- ExcelStyleCollection<ExcelXfs> cellXfs = _package.Workbook.Styles.CellXfs;
+ ExcelStyleCollection<ExcelXfs> cellXfs = _workbook.Styles.CellXfs;
int row = -1;
StringBuilder sbXml = new StringBuilder();
- var ss = _package.Workbook._sharedStrings;
- var styles = _package.Workbook.Styles;
+ var ss = _workbook._sharedStrings;
+ var styles = _workbook.Styles;
var cache = new StringBuilder();
cache.Append("<sheetData>");
@@ -3401,7 +3392,7 @@
}
private object GetFormulaValue(object v) {
- //if (_package.Workbook._isCalculated)
+ //if (_workbook._isCalculated)
//{
if (v != null && v.ToString() != "") {
return "<v>" + SecurityElement.Escape(GetValueForXml(v)) + "</v>"; //Fixes issue 15071
@@ -3772,7 +3763,7 @@
/// <summary>
/// The workbook object
/// </summary>
- public ExcelWorkbook Workbook => _package.Workbook;
+ public ExcelWorkbook Workbook => _workbook;
/// <summary>
/// Get the next ID from a shared formula or an Array formula
diff --git a/EPPlus/ExcelWorksheetView.cs b/EPPlus/ExcelWorksheetView.cs
index c3047a2..03303b8 100644
--- a/EPPlus/ExcelWorksheetView.cs
+++ b/EPPlus/ExcelWorksheetView.cs
@@ -119,7 +119,7 @@
}
}
- private ExcelWorksheet _worksheet;
+ private readonly ExcelWorksheet _worksheet;
/// <summary>
/// Creates a new ExcelWorksheetView which provides access to all the view states of the worksheet.
@@ -193,7 +193,7 @@
set {
if (value) {
// // ensure no other worksheet has its tabSelected attribute set to 1
- foreach (ExcelWorksheet sheet in _worksheet._package.Workbook.Worksheets) {
+ foreach (ExcelWorksheet sheet in _worksheet.Workbook.Worksheets) {
sheet.View.TabSelected = false;
}
@@ -286,8 +286,8 @@
/// </summary>
public ExcelWorksheetPanes[] Panes { get; internal set; }
- private string _paneNodePath = "d:pane";
- private string _selectionNodePath = "d:selection";
+ private readonly string _paneNodePath = "d:pane";
+ private readonly string _selectionNodePath = "d:selection";
/// <summary>
/// Freeze the columns/rows to left and above the cell
diff --git a/EPPlus/ExcelWorksheets.cs b/EPPlus/ExcelWorksheets.cs
index 91e3cdb..dd56dab 100644
--- a/EPPlus/ExcelWorksheets.cs
+++ b/EPPlus/ExcelWorksheets.cs
@@ -45,13 +45,19 @@
/// The collection of worksheets for the workbook
/// </summary>
public class ExcelWorksheets : XmlHelper, IEnumerable<ExcelWorksheet> {
- private ExcelPackage _pck;
+ private readonly ExcelPackage _pck;
+ private readonly ExcelWorkbook _workbook;
private Dictionary<int, ExcelWorksheet> _worksheets;
- private XmlNamespaceManager _namespaceManager;
+ private readonly XmlNamespaceManager _namespaceManager;
- internal ExcelWorksheets(ExcelPackage pck, XmlNamespaceManager nsm, XmlNode topNode)
+ internal ExcelWorksheets(
+ ExcelPackage pck,
+ ExcelWorkbook workbook,
+ XmlNamespaceManager nsm,
+ XmlNode topNode)
: base(nsm, topNode) {
_pck = pck;
+ _workbook = workbook;
_namespaceManager = nsm;
_worksheets = new();
int positionId = 1;
@@ -70,9 +76,9 @@
hidden = TranslateHidden(attr.Value);
}
- var sheetRelation = pck.Workbook.Part.GetRelationship(relId);
+ var sheetRelation = _workbook.Part.GetRelationship(relId);
Uri uriWorksheet = UriHelper.ResolvePartUri(
- pck.Workbook.WorkbookUri,
+ ExcelWorkbook.WorkbookUri,
sheetRelation.TargetUri);
//add the worksheet
@@ -81,7 +87,8 @@
positionId,
new ExcelChartsheet(
_namespaceManager,
- _pck,
+ pck,
+ _workbook,
relId,
uriWorksheet,
name,
@@ -91,7 +98,16 @@
} else {
_worksheets.Add(
positionId,
- new(_namespaceManager, _pck, relId, uriWorksheet, name, sheetId, positionId, hidden));
+ new(
+ _namespaceManager,
+ pck,
+ _workbook,
+ relId,
+ uriWorksheet,
+ name,
+ sheetId,
+ positionId,
+ hidden));
}
positionId++;
}
@@ -116,10 +132,8 @@
private const string _errDupWorksheet =
"A worksheet with this name already exists in the workbook";
- internal const string _worksheetContenttype =
+ internal const string _worksheetContentType =
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
- internal const string _chartsheetContenttype =
- "application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml";
/// <summary>
/// Foreach support
@@ -148,7 +162,7 @@
GetSheetUri(ref name, out sheetId, out uriWorksheet, false);
ZipPackagePart worksheetPart = _pck.Package.CreatePart(
uriWorksheet,
- _worksheetContenttype,
+ _worksheetContentType,
_pck.Compression);
//Create the new, empty worksheet and save it to the package
@@ -166,6 +180,7 @@
worksheet = new(
_namespaceManager,
_pck,
+ _workbook,
rel,
uriWorksheet,
name,
@@ -181,13 +196,13 @@
private string CreateWorkbookRel(string name, int sheetId, Uri uriWorksheet, bool isChart) {
//Create the relationship between the workbook and the new worksheet
- var rel = _pck.Workbook.Part.CreateRelationship(
- UriHelper.GetRelativeUri(_pck.Workbook.WorkbookUri, uriWorksheet),
+ var rel = _workbook.Part.CreateRelationship(
+ UriHelper.GetRelativeUri(ExcelWorkbook.WorkbookUri, uriWorksheet),
TargetMode.Internal,
ExcelPackage._schemaRelationships + "/" + (isChart ? "chartsheet" : "worksheet"));
//Create the new sheet node
- XmlElement worksheetNode = _pck.Workbook.WorkbookXml.CreateElement(
+ XmlElement worksheetNode = _workbook.WorkbookXml.CreateElement(
"sheet",
ExcelPackage._schemaMain);
worksheetNode.SetAttribute("name", name);
diff --git a/EPPlus/FormulaParsing/DependencyChain/DependenyChainFactory.cs b/EPPlus/FormulaParsing/DependencyChain/DependenyChainFactory.cs
index bd3bbd9..009a8e5 100644
--- a/EPPlus/FormulaParsing/DependencyChain/DependenyChainFactory.cs
+++ b/EPPlus/FormulaParsing/DependencyChain/DependenyChainFactory.cs
@@ -203,7 +203,7 @@
if (t.TokenType == TokenType.ExcelAddress) {
var adr = new ExcelFormulaAddress(t.Value);
if (adr.Table != null) {
- adr.SetRcFromTable(ws._package, new(f.Row, f.Column, f.Row, f.Column));
+ adr.SetRcFromTable(ws.Workbook, new(f.Row, f.Column, f.Row, f.Column));
}
if (adr.WorkSheet == null
diff --git a/EPPlus/FormulaParsing/EpplusExcelDataProvider.cs b/EPPlus/FormulaParsing/EpplusExcelDataProvider.cs
index 85d297a..0783dcc 100644
--- a/EPPlus/FormulaParsing/EpplusExcelDataProvider.cs
+++ b/EPPlus/FormulaParsing/EpplusExcelDataProvider.cs
@@ -11,14 +11,14 @@
public class EpplusExcelDataProvider : ExcelDataProvider {
public class RangeInfo : IRangeInfo {
internal ExcelWorksheet _ws;
- private CellsStoreEnumerator<object> _values;
- private int _fromRow,
- _toRow,
- _fromCol,
- _toCol;
+ private readonly CellsStoreEnumerator<object> _values;
+ private readonly int _fromRow;
+ private readonly int _toRow;
+ private readonly int _fromCol;
+ private readonly int _toCol;
private int _cellCount;
- private ExcelAddressBase _address;
- private ICellInfo _cell;
+ private readonly ExcelAddressBase _address;
+ private readonly ICellInfo _cell;
public RangeInfo(ExcelWorksheet ws, int fromRow, int fromCol, int toRow, int toCol) {
_ws = ws;
@@ -118,8 +118,8 @@
}
public class CellInfo : ICellInfo {
- private ExcelWorksheet _ws;
- private CellsStoreEnumerator<object> _values;
+ private readonly ExcelWorksheet _ws;
+ private readonly CellsStoreEnumerator<object> _values;
internal CellInfo(ExcelWorksheet ws, CellsStoreEnumerator<object> values) {
_ws = ws;
@@ -169,19 +169,16 @@
public object Value { get; set; }
}
- private readonly ExcelPackage _package;
+ private readonly ExcelWorkbook _workbook;
private ExcelWorksheet _currentWorksheet;
- private RangeAddressFactory _rangeAddressFactory;
private Dictionary<ulong, INameInfo> _names = new();
- public EpplusExcelDataProvider(ExcelPackage package) {
- _package = package;
-
- _rangeAddressFactory = new(this);
+ public EpplusExcelDataProvider(ExcelWorkbook workbook) {
+ _workbook = workbook;
}
public override ExcelNamedRangeCollection GetWorksheetNames(string worksheet) {
- var ws = _package.Workbook.Worksheets[worksheet];
+ var ws = _workbook.Worksheets[worksheet];
if (ws != null) {
return ws.Names;
}
@@ -189,7 +186,7 @@
}
public override ExcelNamedRangeCollection GetWorkbookNameValues() {
- return _package.Workbook.Names;
+ return _workbook.Names;
}
public override IRangeInfo GetRange(
@@ -200,18 +197,18 @@
int toCol) {
SetCurrentWorksheet(worksheet);
var wsName = string.IsNullOrEmpty(worksheet) ? _currentWorksheet.Name : worksheet;
- var ws = _package.Workbook.Worksheets[wsName];
+ var ws = _workbook.Worksheets[wsName];
return new RangeInfo(ws, fromRow, fromCol, toRow, toCol);
}
public override IRangeInfo GetRange(string worksheet, int row, int column, string address) {
var addr = new ExcelAddress(worksheet, address);
if (addr.Table != null) {
- addr.SetRcFromTable(_package, new(row, column, row, column));
+ addr.SetRcFromTable(_workbook, new(row, column, row, column));
}
//SetCurrentWorksheet(addr.WorkSheet);
var wsName = string.IsNullOrEmpty(addr.WorkSheet) ? _currentWorksheet.Name : addr.WorkSheet;
- var ws = _package.Workbook.Worksheets[wsName];
+ var ws = _workbook.Worksheets[wsName];
//return new CellsStoreEnumerator<object>(ws._values, addr._fromRow, addr._fromCol, addr._toRow, addr._toCol);
return new RangeInfo(ws, addr._fromRow, addr._fromCol, addr._toRow, addr._toCol);
}
@@ -221,18 +218,18 @@
ulong id;
ExcelWorksheet ws;
if (string.IsNullOrEmpty(worksheet)) {
- if (_package.Workbook.Names.ContainsKey(name)) {
- nameItem = _package.Workbook.Names[name];
+ if (_workbook.Names.ContainsKey(name)) {
+ nameItem = _workbook.Names[name];
} else {
return null;
}
ws = null;
} else {
- ws = _package.Workbook.Worksheets[worksheet];
+ ws = _workbook.Worksheets[worksheet];
if (ws != null && ws.Names.ContainsKey(name)) {
nameItem = ws.Names[name];
- } else if (_package.Workbook.Names.ContainsKey(name)) {
- nameItem = _package.Workbook.Names[name];
+ } else if (_workbook.Names.ContainsKey(name)) {
+ nameItem = _workbook.Names[name];
} else {
return null;
}
@@ -266,7 +263,7 @@
SetCurrentWorksheet(ExcelAddressInfo.Parse(address));
var addr = new ExcelAddress(address);
var wsName = string.IsNullOrEmpty(addr.WorkSheet) ? _currentWorksheet.Name : addr.WorkSheet;
- var ws = _package.Workbook.Worksheets[wsName];
+ var ws = _workbook.Worksheets[wsName];
return (new CellsStoreEnumerator<object>(
ws._values,
addr._fromRow,
@@ -299,7 +296,7 @@
public override ExcelCellAddress GetDimensionEnd(string worksheet) {
ExcelCellAddress address = null;
try {
- address = _package.Workbook.Worksheets[worksheet].Dimension.End;
+ address = _workbook.Worksheets[worksheet].Dimension.End;
} catch {}
return address;
@@ -307,17 +304,17 @@
private void SetCurrentWorksheet(ExcelAddressInfo addressInfo) {
if (addressInfo.WorksheetIsSpecified) {
- _currentWorksheet = _package.Workbook.Worksheets[addressInfo.Worksheet];
+ _currentWorksheet = _workbook.Worksheets[addressInfo.Worksheet];
} else if (_currentWorksheet == null) {
- _currentWorksheet = _package.Workbook.Worksheets.First();
+ _currentWorksheet = _workbook.Worksheets.First();
}
}
private void SetCurrentWorksheet(string worksheetName) {
if (!string.IsNullOrEmpty(worksheetName)) {
- _currentWorksheet = _package.Workbook.Worksheets[worksheetName];
+ _currentWorksheet = _workbook.Worksheets[worksheetName];
} else {
- _currentWorksheet = _package.Workbook.Worksheets.First();
+ _currentWorksheet = _workbook.Worksheets.First();
}
}
@@ -336,7 +333,7 @@
}
public override string GetFormat(object value, string format) {
- var styles = _package.Workbook.Styles;
+ var styles = _workbook.Styles;
ExcelNumberFormatXml.ExcelFormatTranslator ft = null;
foreach (var f in styles.NumberFormats) {
if (f.Format == format) {
@@ -351,13 +348,13 @@
}
public override List<Token> GetRangeFormulaTokens(string worksheetName, int row, int column) {
- return _package.Workbook.Worksheets[worksheetName]._formulaTokens.GetValue(row, column);
+ return _workbook.Worksheets[worksheetName]._formulaTokens.GetValue(row, column);
}
public override bool IsRowHidden(string worksheetName, int row) {
var b =
- _package.Workbook.Worksheets[worksheetName].Row(row).Height == 0
- || _package.Workbook.Worksheets[worksheetName].Row(row).Hidden;
+ _workbook.Worksheets[worksheetName].Row(row).Height == 0
+ || _workbook.Worksheets[worksheetName].Row(row).Hidden;
return b;
}
diff --git a/EPPlus/FormulaParsing/EpplusNameValueProvider.cs b/EPPlus/FormulaParsing/EpplusNameValueProvider.cs
index 60becec..65b9db3 100644
--- a/EPPlus/FormulaParsing/EpplusNameValueProvider.cs
+++ b/EPPlus/FormulaParsing/EpplusNameValueProvider.cs
@@ -1,7 +1,7 @@
namespace OfficeOpenXml.FormulaParsing;
public class EpplusNameValueProvider : INameValueProvider {
- private ExcelDataProvider _excelDataProvider;
+ private readonly ExcelDataProvider _excelDataProvider;
private ExcelNamedRangeCollection _values;
public EpplusNameValueProvider(ExcelDataProvider excelDataProvider) {
diff --git a/EPPlus/FormulaParsing/Excel/Functions/ArgumentParsers.cs b/EPPlus/FormulaParsing/Excel/Functions/ArgumentParsers.cs
index 1c4d10e..86f9d5c 100644
--- a/EPPlus/FormulaParsing/Excel/Functions/ArgumentParsers.cs
+++ b/EPPlus/FormulaParsing/Excel/Functions/ArgumentParsers.cs
@@ -30,7 +30,7 @@
namespace OfficeOpenXml.FormulaParsing.Excel.Functions;
public class ArgumentParsers {
- private static object _syncRoot = new();
+ private static readonly object _syncRoot = new();
private readonly Dictionary<DataType, ArgumentParser> _parsers = new();
private readonly ArgumentParserFactory _parserFactory;
diff --git a/EPPlus/FormulaParsing/Excel/Functions/Database/ExcelDatabaseRow.cs b/EPPlus/FormulaParsing/Excel/Functions/Database/ExcelDatabaseRow.cs
index 7b694cf..e3c9a12 100644
--- a/EPPlus/FormulaParsing/Excel/Functions/Database/ExcelDatabaseRow.cs
+++ b/EPPlus/FormulaParsing/Excel/Functions/Database/ExcelDatabaseRow.cs
@@ -28,7 +28,7 @@
namespace OfficeOpenXml.FormulaParsing.Excel.Functions.Database;
public class ExcelDatabaseRow {
- private Dictionary<int, string> _fieldIndexes = new();
+ private readonly Dictionary<int, string> _fieldIndexes = new();
private readonly Dictionary<string, object> _items = new();
private int _colIndex = 1;
diff --git a/EPPlus/FormulaParsing/Excel/Functions/DateTime/Weekday.cs b/EPPlus/FormulaParsing/Excel/Functions/DateTime/Weekday.cs
index 533ce2a..cf1af33 100644
--- a/EPPlus/FormulaParsing/Excel/Functions/DateTime/Weekday.cs
+++ b/EPPlus/FormulaParsing/Excel/Functions/DateTime/Weekday.cs
@@ -42,9 +42,9 @@
DataType.Integer);
}
- private static List<int> _oneBasedStartOnSunday = new() { 1, 2, 3, 4, 5, 6, 7 };
- private static List<int> _oneBasedStartOnMonday = new() { 7, 1, 2, 3, 4, 5, 6 };
- private static List<int> _zeroBasedStartOnSunday = new() { 6, 0, 1, 2, 3, 4, 5 };
+ private static readonly List<int> _oneBasedStartOnSunday = new() { 1, 2, 3, 4, 5, 6, 7 };
+ private static readonly List<int> _oneBasedStartOnMonday = new() { 7, 1, 2, 3, 4, 5, 6 };
+ private static readonly List<int> _zeroBasedStartOnSunday = new() { 6, 0, 1, 2, 3, 4, 5 };
private int CalculateDayOfWeek(System.DateTime dateTime, int returnType) {
var dayIx = (int)dateTime.DayOfWeek;
diff --git a/EPPlus/FormulaParsing/Excel/Functions/FunctionRepository.cs b/EPPlus/FormulaParsing/Excel/Functions/FunctionRepository.cs
index 42d7f0b..fe09617 100644
--- a/EPPlus/FormulaParsing/Excel/Functions/FunctionRepository.cs
+++ b/EPPlus/FormulaParsing/Excel/Functions/FunctionRepository.cs
@@ -52,7 +52,8 @@
/// This class provides methods for accessing/modifying VBA Functions.
/// </summary>
public class FunctionRepository : IFunctionNameProvider {
- private Dictionary<string, ExcelFunction> _functions = new(StringComparer.InvariantCulture);
+ private readonly Dictionary<string, ExcelFunction> _functions = new(
+ StringComparer.InvariantCulture);
private FunctionRepository() {}
diff --git a/EPPlus/FormulaParsing/Excel/Functions/Math/Subtotal.cs b/EPPlus/FormulaParsing/Excel/Functions/Math/Subtotal.cs
index 45e11e6..cc82beb 100644
--- a/EPPlus/FormulaParsing/Excel/Functions/Math/Subtotal.cs
+++ b/EPPlus/FormulaParsing/Excel/Functions/Math/Subtotal.cs
@@ -30,7 +30,7 @@
namespace OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
public class Subtotal : ExcelFunction {
- private Dictionary<int, HiddenValuesHandlingFunction> _functions = new();
+ private readonly Dictionary<int, HiddenValuesHandlingFunction> _functions = new();
public Subtotal() {
Initialize();
diff --git a/EPPlus/FormulaParsing/ExcelUtilities/ExcelAddressUtil.cs b/EPPlus/FormulaParsing/ExcelUtilities/ExcelAddressUtil.cs
index 75ad665..03373ce 100644
--- a/EPPlus/FormulaParsing/ExcelUtilities/ExcelAddressUtil.cs
+++ b/EPPlus/FormulaParsing/ExcelUtilities/ExcelAddressUtil.cs
@@ -32,7 +32,7 @@
namespace OfficeOpenXml.FormulaParsing.ExcelUtilities;
public static class ExcelAddressUtil {
- private static char[] SheetNameInvalidChars = { '?', ':', '*', '/', '\\' };
+ private static readonly char[] SheetNameInvalidChars = { '?', ':', '*', '/', '\\' };
public static bool IsValidAddress(string token) {
int ix;
diff --git a/EPPlus/FormulaParsing/ExcelUtilities/FormulaDependency.cs b/EPPlus/FormulaParsing/ExcelUtilities/FormulaDependency.cs
index c337019..d46fca9 100644
--- a/EPPlus/FormulaParsing/ExcelUtilities/FormulaDependency.cs
+++ b/EPPlus/FormulaParsing/ExcelUtilities/FormulaDependency.cs
@@ -45,9 +45,9 @@
public RangeAddress Address { get; private set; }
- private List<RangeAddress> _referencedBy = new();
+ private readonly List<RangeAddress> _referencedBy = new();
- private List<RangeAddress> _references = new();
+ private readonly List<RangeAddress> _references = new();
public virtual void AddReferenceFrom(RangeAddress rangeAddress) {
if (Address.CollidesWith(rangeAddress)
diff --git a/EPPlus/FormulaParsing/ExcelUtilities/NumericExpressionEvaluator.cs b/EPPlus/FormulaParsing/ExcelUtilities/NumericExpressionEvaluator.cs
index 31b6f2a..6e326a7 100644
--- a/EPPlus/FormulaParsing/ExcelUtilities/NumericExpressionEvaluator.cs
+++ b/EPPlus/FormulaParsing/ExcelUtilities/NumericExpressionEvaluator.cs
@@ -37,8 +37,8 @@
namespace OfficeOpenXml.FormulaParsing.ExcelUtilities;
public class NumericExpressionEvaluator {
- private ValueMatcher _valueMatcher;
- private CompileResultFactory _compileResultFactory;
+ private readonly ValueMatcher _valueMatcher;
+ private readonly CompileResultFactory _compileResultFactory;
public NumericExpressionEvaluator()
: this(new(), new()) {}
diff --git a/EPPlus/FormulaParsing/ExcelUtilities/RangeAddress.cs b/EPPlus/FormulaParsing/ExcelUtilities/RangeAddress.cs
index 5a19ff9..cf62744 100644
--- a/EPPlus/FormulaParsing/ExcelUtilities/RangeAddress.cs
+++ b/EPPlus/FormulaParsing/ExcelUtilities/RangeAddress.cs
@@ -52,7 +52,7 @@
return Address;
}
- private static RangeAddress _empty = new();
+ private static readonly RangeAddress _empty = new();
public static RangeAddress Empty => _empty;
diff --git a/EPPlus/FormulaParsing/ExcelValues.cs b/EPPlus/FormulaParsing/ExcelValues.cs
index d8fceeb..e4d860b 100644
--- a/EPPlus/FormulaParsing/ExcelValues.cs
+++ b/EPPlus/FormulaParsing/ExcelValues.cs
@@ -75,7 +75,7 @@
public const string Error = "#ERROR!"; // Bug G0004
public const string ErrorValueIsNullOrEmpty = "#ERRORVALUEISNULLOREMPTY!"; // Bug G0005
- private static Dictionary<string, eErrorType> _values = new() {
+ private static readonly Dictionary<string, eErrorType> _values = new() {
{ Div0, eErrorType.Div0 },
{ Na, eErrorType.Na },
{ Name, eErrorType.Name },
diff --git a/EPPlus/FormulaParsing/ExpressionGraph/BooleanExpression.cs b/EPPlus/FormulaParsing/ExpressionGraph/BooleanExpression.cs
index dce6b0f..e61bdf6 100644
--- a/EPPlus/FormulaParsing/ExpressionGraph/BooleanExpression.cs
+++ b/EPPlus/FormulaParsing/ExpressionGraph/BooleanExpression.cs
@@ -32,7 +32,7 @@
namespace OfficeOpenXml.FormulaParsing.ExpressionGraph;
public class BooleanExpression : AtomicExpression {
- private bool? _precompiledValue;
+ private readonly bool? _precompiledValue;
public BooleanExpression(string expression)
: base(expression) {}
diff --git a/EPPlus/FormulaParsing/ExpressionGraph/CompileResult.cs b/EPPlus/FormulaParsing/ExpressionGraph/CompileResult.cs
index 1014610..9535d05 100644
--- a/EPPlus/FormulaParsing/ExpressionGraph/CompileResult.cs
+++ b/EPPlus/FormulaParsing/ExpressionGraph/CompileResult.cs
@@ -37,7 +37,7 @@
namespace OfficeOpenXml.FormulaParsing.ExpressionGraph;
public class CompileResult {
- private static CompileResult _empty = new(null, DataType.Empty);
+ private static readonly CompileResult _empty = new(null, DataType.Empty);
public static CompileResult Empty => _empty;
diff --git a/EPPlus/FormulaParsing/ExpressionGraph/ExcelErrorExpression.cs b/EPPlus/FormulaParsing/ExpressionGraph/ExcelErrorExpression.cs
index fcf4ddd..44770f8 100644
--- a/EPPlus/FormulaParsing/ExpressionGraph/ExcelErrorExpression.cs
+++ b/EPPlus/FormulaParsing/ExpressionGraph/ExcelErrorExpression.cs
@@ -32,7 +32,7 @@
namespace OfficeOpenXml.FormulaParsing.ExpressionGraph;
public class ExcelErrorExpression : Expression {
- private ExcelErrorValue _error;
+ private readonly ExcelErrorValue _error;
public ExcelErrorExpression(string expression, ExcelErrorValue error)
: base(expression) {
diff --git a/EPPlus/FormulaParsing/ExpressionGraph/ExpressionCompiler.cs b/EPPlus/FormulaParsing/ExpressionGraph/ExpressionCompiler.cs
index 49a4ecf..e29c4f2 100644
--- a/EPPlus/FormulaParsing/ExpressionGraph/ExpressionCompiler.cs
+++ b/EPPlus/FormulaParsing/ExpressionGraph/ExpressionCompiler.cs
@@ -37,8 +37,8 @@
public class ExpressionCompiler : IExpressionCompiler {
private IEnumerable<Expression> _expressions;
- private IExpressionConverter _expressionConverter;
- private ICompileStrategyFactory _compileStrategyFactory;
+ private readonly IExpressionConverter _expressionConverter;
+ private readonly ICompileStrategyFactory _compileStrategyFactory;
public ExpressionCompiler()
: this(new ExpressionConverter(), new CompileStrategyFactory()) {}
diff --git a/EPPlus/FormulaParsing/ExpressionGraph/ExpressionGraph.cs b/EPPlus/FormulaParsing/ExpressionGraph/ExpressionGraph.cs
index d9388aa..98fe430 100644
--- a/EPPlus/FormulaParsing/ExpressionGraph/ExpressionGraph.cs
+++ b/EPPlus/FormulaParsing/ExpressionGraph/ExpressionGraph.cs
@@ -34,7 +34,7 @@
namespace OfficeOpenXml.FormulaParsing.ExpressionGraph;
public class ExpressionGraph {
- private List<Expression> _expressions = new();
+ private readonly List<Expression> _expressions = new();
public IEnumerable<Expression> Expressions => _expressions;
diff --git a/EPPlus/FormulaParsing/LexicalAnalysis/TokenizerContext.cs b/EPPlus/FormulaParsing/LexicalAnalysis/TokenizerContext.cs
index e87ac14..34fc6f2 100644
--- a/EPPlus/FormulaParsing/LexicalAnalysis/TokenizerContext.cs
+++ b/EPPlus/FormulaParsing/LexicalAnalysis/TokenizerContext.cs
@@ -44,8 +44,8 @@
_currentToken = new();
}
- private char[] _chars;
- private List<Token> _result;
+ private readonly char[] _chars;
+ private readonly List<Token> _result;
private StringBuilder _currentToken;
public char[] FormulaChars => _chars;
diff --git a/EPPlus/FormulaParsing/ParsingScopes.cs b/EPPlus/FormulaParsing/ParsingScopes.cs
index 51d7bad..66ef836 100644
--- a/EPPlus/FormulaParsing/ParsingScopes.cs
+++ b/EPPlus/FormulaParsing/ParsingScopes.cs
@@ -15,7 +15,7 @@
_lifetimeEventHandler = lifetimeEventHandler;
}
- private Stack<ParsingScope> _scopes = new();
+ private readonly Stack<ParsingScope> _scopes = new();
/// <summary>
/// Creates a new <see cref="ParsingScope"/> and puts it on top of the stack.
diff --git a/EPPlus/OfficeProperties.cs b/EPPlus/OfficeProperties.cs
index 62df7e5..d18b047 100644
--- a/EPPlus/OfficeProperties.cs
+++ b/EPPlus/OfficeProperties.cs
@@ -49,14 +49,14 @@
private XmlDocument _xmlPropertiesExtended;
private XmlDocument _xmlPropertiesCustom;
- private Uri _uriPropertiesCore = new("/docProps/core.xml", UriKind.Relative);
- private Uri _uriPropertiesExtended = new("/docProps/app.xml", UriKind.Relative);
- private Uri _uriPropertiesCustom = new("/docProps/custom.xml", UriKind.Relative);
+ private readonly Uri _uriPropertiesCore = new("/docProps/core.xml", UriKind.Relative);
+ private readonly Uri _uriPropertiesExtended = new("/docProps/app.xml", UriKind.Relative);
+ private readonly Uri _uriPropertiesCustom = new("/docProps/custom.xml", UriKind.Relative);
- private XmlHelper _coreHelper;
- private XmlHelper _extendedHelper;
+ private readonly XmlHelper _coreHelper;
+ private readonly XmlHelper _extendedHelper;
private XmlHelper _customHelper;
- private ExcelPackage _package;
+ private readonly ExcelPackage _package;
/// <summary>
/// Provides access to all the office document properties.
diff --git a/EPPlus/Packaging/ZipPackage.cs b/EPPlus/Packaging/ZipPackage.cs
index 4dbed56..843d105 100644
--- a/EPPlus/Packaging/ZipPackage.cs
+++ b/EPPlus/Packaging/ZipPackage.cs
@@ -72,7 +72,8 @@
}
}
- private Dictionary<string, ZipPackagePart> Parts = new(StringComparer.InvariantCultureIgnoreCase);
+ private readonly Dictionary<string, ZipPackagePart> Parts = new(
+ StringComparer.InvariantCultureIgnoreCase);
internal Dictionary<string, ContentType> _contentTypes = new(
StringComparer.InvariantCultureIgnoreCase);
diff --git a/EPPlus/Style/Dxf/ExcelDxfStyle.cs b/EPPlus/Style/Dxf/ExcelDxfStyle.cs
index 4cb8bba..7180b21 100644
--- a/EPPlus/Style/Dxf/ExcelDxfStyle.cs
+++ b/EPPlus/Style/Dxf/ExcelDxfStyle.cs
@@ -6,7 +6,7 @@
namespace OfficeOpenXml.Style.Dxf;
public class ExcelDxfStyleConditionalFormatting : DxfStyleBase<ExcelDxfStyleConditionalFormatting> {
- private XmlHelperInstance _helper;
+ private readonly XmlHelperInstance _helper;
internal ExcelDxfStyleConditionalFormatting(
XmlNamespaceManager nameSpaceManager,
diff --git a/EPPlus/Style/ExcelBorderItem.cs b/EPPlus/Style/ExcelBorderItem.cs
index f46f55a..7708ab9 100644
--- a/EPPlus/Style/ExcelBorderItem.cs
+++ b/EPPlus/Style/ExcelBorderItem.cs
@@ -39,8 +39,8 @@
/// Cell border style
/// </summary>
public sealed class ExcelBorderItem : StyleBase {
- private eStyleClass _cls;
- private StyleBase _parent;
+ private readonly eStyleClass _cls;
+ private readonly StyleBase _parent;
internal ExcelBorderItem(
ExcelStyles styles,
diff --git a/EPPlus/Style/ExcelColor.cs b/EPPlus/Style/ExcelColor.cs
index 935f78e..e673510 100644
--- a/EPPlus/Style/ExcelColor.cs
+++ b/EPPlus/Style/ExcelColor.cs
@@ -40,8 +40,8 @@
/// Color for cellstyling
/// </summary>
public sealed class ExcelColor : StyleBase {
- private eStyleClass _cls;
- private StyleBase _parent;
+ private readonly eStyleClass _cls;
+ private readonly StyleBase _parent;
internal ExcelColor(
ExcelStyles styles,
diff --git a/EPPlus/Style/ExcelParagraphCollection.cs b/EPPlus/Style/ExcelParagraphCollection.cs
index 8c96724..784c4cc 100644
--- a/EPPlus/Style/ExcelParagraphCollection.cs
+++ b/EPPlus/Style/ExcelParagraphCollection.cs
@@ -41,8 +41,8 @@
/// A collection of Paragraph objects
/// </summary>
public class ExcelParagraphCollection : XmlHelper, IEnumerable<ExcelParagraph> {
- private List<ExcelParagraph> _list = new();
- private string _path;
+ private readonly List<ExcelParagraph> _list = new();
+ private readonly string _path;
internal ExcelParagraphCollection(
XmlNamespaceManager ns,
diff --git a/EPPlus/Style/ExcelRichTextCollection.cs b/EPPlus/Style/ExcelRichTextCollection.cs
index 496431d..0f4e29d 100644
--- a/EPPlus/Style/ExcelRichTextCollection.cs
+++ b/EPPlus/Style/ExcelRichTextCollection.cs
@@ -44,8 +44,8 @@
/// Collection of Richtext objects
/// </summary>
public class ExcelRichTextCollection : XmlHelper, IEnumerable<ExcelRichText> {
- private List<ExcelRichText> _list = new();
- private ExcelRangeBase _cells;
+ private readonly List<ExcelRichText> _list = new();
+ private readonly ExcelRangeBase _cells;
internal ExcelRichTextCollection(XmlNamespaceManager ns, XmlNode topNode)
: base(ns, topNode) {
diff --git a/EPPlus/Style/ExcelTextFont.cs b/EPPlus/Style/ExcelTextFont.cs
index 13b7ae1..f098072 100644
--- a/EPPlus/Style/ExcelTextFont.cs
+++ b/EPPlus/Style/ExcelTextFont.cs
@@ -74,8 +74,8 @@
/// Used by Rich-text and Paragraphs.
/// </summary>
public class ExcelTextFont : XmlHelper {
- private string _path;
- private XmlNode _rootNode;
+ private readonly string _path;
+ private readonly XmlNode _rootNode;
internal ExcelTextFont(
XmlNamespaceManager namespaceManager,
@@ -94,7 +94,7 @@
_path = path;
}
- private string _fontLatinPath = "a:latin/@typeface";
+ private readonly string _fontLatinPath = "a:latin/@typeface";
public string LatinFont {
get => GetXmlNodeString(_fontLatinPath);
@@ -111,7 +111,7 @@
}
}
- private string _fontCsPath = "a:cs/@typeface";
+ private readonly string _fontCsPath = "a:cs/@typeface";
public string ComplexFont {
get => GetXmlNodeString(_fontCsPath);
@@ -121,7 +121,7 @@
}
}
- private string _boldPath = "@b";
+ private readonly string _boldPath = "@b";
public bool Bold {
get => GetXmlNodeBool(_boldPath);
@@ -131,7 +131,7 @@
}
}
- private string _underLinePath = "@u";
+ private readonly string _underLinePath = "@u";
public eUnderLineType UnderLine {
get => TranslateUnderline(GetXmlNodeString(_underLinePath));
@@ -141,7 +141,7 @@
}
}
- private string _underLineColorPath = "a:uFill/a:solidFill/a:srgbClr/@val";
+ private readonly string _underLineColorPath = "a:uFill/a:solidFill/a:srgbClr/@val";
public Color UnderLineColor {
get {
@@ -157,7 +157,7 @@
}
}
- private string _italicPath = "@i";
+ private readonly string _italicPath = "@i";
public bool Italic {
get => GetXmlNodeBool(_italicPath);
@@ -167,7 +167,7 @@
}
}
- private string _strikePath = "@strike";
+ private readonly string _strikePath = "@strike";
public eStrikeType Strike {
get => TranslateStrike(GetXmlNodeString(_strikePath));
@@ -177,7 +177,7 @@
}
}
- private string _sizePath = "@sz";
+ private readonly string _sizePath = "@sz";
public float Size {
get => GetXmlNodeInt(_sizePath) / 100;
@@ -187,7 +187,7 @@
}
}
- private string _colorPath = "a:solidFill/a:srgbClr/@val";
+ private readonly string _colorPath = "a:solidFill/a:srgbClr/@val";
public Color Color {
get {
diff --git a/EPPlus/Style/XmlAccess/ExcelNamedStyleXml.cs b/EPPlus/Style/XmlAccess/ExcelNamedStyleXml.cs
index 599052c..8004056 100644
--- a/EPPlus/Style/XmlAccess/ExcelNamedStyleXml.cs
+++ b/EPPlus/Style/XmlAccess/ExcelNamedStyleXml.cs
@@ -38,7 +38,7 @@
/// Xml access class for named styles
/// </summary>
public sealed class ExcelNamedStyleXml : StyleXmlHelper {
- private ExcelStyles _styles;
+ private readonly ExcelStyles _styles;
internal ExcelNamedStyleXml(XmlNamespaceManager nameSpaceManager, ExcelStyles styles)
: base(nameSpaceManager) {
diff --git a/EPPlus/Style/XmlAccess/ExcelXfsXml.cs b/EPPlus/Style/XmlAccess/ExcelXfsXml.cs
index 3b6f823..d00ed0e 100644
--- a/EPPlus/Style/XmlAccess/ExcelXfsXml.cs
+++ b/EPPlus/Style/XmlAccess/ExcelXfsXml.cs
@@ -41,7 +41,7 @@
/// Xml access class xfs records. This is the top level style object.
/// </summary>
public sealed class ExcelXfs : StyleXmlHelper {
- private ExcelStyles _styles;
+ private readonly ExcelStyles _styles;
internal ExcelXfs(XmlNamespaceManager nameSpaceManager, ExcelStyles styles)
: base(nameSpaceManager) {
@@ -232,7 +232,7 @@
set => _wrapText = value;
}
- private string textRotationPath = "d:alignment/@textRotation";
+ private readonly string textRotationPath = "d:alignment/@textRotation";
private int _textRotation;
/// <summary>
diff --git a/EPPlus/Table/ExcelTableCollection.cs b/EPPlus/Table/ExcelTableCollection.cs
index 08576e4..75c255d 100644
--- a/EPPlus/Table/ExcelTableCollection.cs
+++ b/EPPlus/Table/ExcelTableCollection.cs
@@ -41,9 +41,9 @@
/// A collection of table objects
/// </summary>
public class ExcelTableCollection : IEnumerable<ExcelTable> {
- private List<ExcelTable> _tables = new();
+ private readonly List<ExcelTable> _tables = new();
internal Dictionary<string, int> _tableNames = new(StringComparer.InvariantCultureIgnoreCase);
- private ExcelWorksheet _ws;
+ private readonly ExcelWorksheet _ws;
internal ExcelTableCollection(ExcelWorksheet ws) {
var pck = ws._package.Package;
diff --git a/EPPlus/Table/ExcelTableColumnCollection.cs b/EPPlus/Table/ExcelTableColumnCollection.cs
index 864e026..57d59d8 100644
--- a/EPPlus/Table/ExcelTableColumnCollection.cs
+++ b/EPPlus/Table/ExcelTableColumnCollection.cs
@@ -42,8 +42,9 @@
/// A collection of table columns
/// </summary>
public class ExcelTableColumnCollection : IEnumerable<ExcelTableColumn> {
- private List<ExcelTableColumn> _cols = new();
- private Dictionary<string, int> _colNames = new(StringComparer.InvariantCultureIgnoreCase);
+ private readonly List<ExcelTableColumn> _cols = new();
+ private readonly Dictionary<string, int> _colNames = new(
+ StringComparer.InvariantCultureIgnoreCase);
public ExcelTableColumnCollection(ExcelTable table) {
Table = table;
diff --git a/EPPlus/Table/PivotTable/ExcelPivotTableCollection.cs b/EPPlus/Table/PivotTable/ExcelPivotTableCollection.cs
index bde8c36..c6c918f 100644
--- a/EPPlus/Table/PivotTable/ExcelPivotTableCollection.cs
+++ b/EPPlus/Table/PivotTable/ExcelPivotTableCollection.cs
@@ -40,9 +40,9 @@
/// A collection of pivottable objects
/// </summary>
public class ExcelPivotTableCollection : IEnumerable<ExcelPivotTable> {
- private List<ExcelPivotTable> _pivotTables = new();
+ private readonly List<ExcelPivotTable> _pivotTables = new();
internal Dictionary<string, int> _pivotTableNames = new();
- private ExcelWorksheet _ws;
+ private readonly ExcelWorksheet _ws;
internal ExcelPivotTableCollection(ExcelWorksheet ws) {
var pck = ws._package.Package;
diff --git a/EPPlus/Table/PivotTable/ExcelPivotTableFieldItem.cs b/EPPlus/Table/PivotTable/ExcelPivotTableFieldItem.cs
index d4dce2d..b300b73 100644
--- a/EPPlus/Table/PivotTable/ExcelPivotTableFieldItem.cs
+++ b/EPPlus/Table/PivotTable/ExcelPivotTableFieldItem.cs
@@ -39,7 +39,7 @@
/// A field Item. Used for grouping
/// </summary>
public class ExcelPivotTableFieldItem : XmlHelper {
- private ExcelPivotTableField _field;
+ private readonly ExcelPivotTableField _field;
internal ExcelPivotTableFieldItem(
XmlNamespaceManager ns,
diff --git a/EPPlus/Utils/Argument.cs b/EPPlus/Utils/Argument.cs
index e95c92b..8519db1 100644
--- a/EPPlus/Utils/Argument.cs
+++ b/EPPlus/Utils/Argument.cs
@@ -37,7 +37,7 @@
_value = value;
}
- private T _value;
+ private readonly T _value;
T IArgument<T>.Value => _value;
}
diff --git a/EPPlus/Utils/ValidationResult.cs b/EPPlus/Utils/ValidationResult.cs
index 2985491..9985fa5 100644
--- a/EPPlus/Utils/ValidationResult.cs
+++ b/EPPlus/Utils/ValidationResult.cs
@@ -11,8 +11,8 @@
_errorMessage = errorMessage;
}
- private bool _result;
- private string _errorMessage;
+ private readonly bool _result;
+ private readonly string _errorMessage;
private void Throw() {
if (string.IsNullOrEmpty(_errorMessage)) {
diff --git a/NetCoreTests/ExcelPackageTest.cs b/NetCoreTests/ExcelPackageTest.cs
index 975fadc..8785d5d 100644
--- a/NetCoreTests/ExcelPackageTest.cs
+++ b/NetCoreTests/ExcelPackageTest.cs
@@ -20,6 +20,18 @@
worksheet.Name.Should().Be("Times_csv");
}
+ [TestMethod]
+ public void TestGetAsByteArray_PublicLibrary() {
+ var package = new ExcelPackage(new FileInfo(GetTestWorkbookPath("PublicLibrary.xlsx")));
+ var data = package.GetAsByteArray();
+
+ // Verify that we can reload
+ var newPackage = new ExcelPackage(new MemoryStream(data, false));
+ newPackage.Workbook.Worksheets.Count.Should().Be(1);
+ var worksheet = newPackage.Workbook.Worksheets.First();
+ worksheet.Name.Should().Be("pusum11a");
+ }
+
private static string GetTestWorkbookPath(string filename) {
var assemblyPath = Path.GetDirectoryName(typeof(ExcelPackageTest).Assembly.Location)!;
return Path.Combine(assemblyPath, "TestWorkbooks", filename);
diff --git a/NetCoreTests/TestWorkbooks/PublicLibrary.xlsx b/NetCoreTests/TestWorkbooks/PublicLibrary.xlsx
new file mode 100644
index 0000000..5c51d4c
--- /dev/null
+++ b/NetCoreTests/TestWorkbooks/PublicLibrary.xlsx
Binary files differ