diff --git a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj index c11e341..79b7ed2 100644 --- a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj +++ b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj @@ -48,8 +48,15 @@ - + + + + + + + + @@ -58,8 +65,11 @@ - + + + + @@ -80,6 +90,7 @@ + diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/IXLCell.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/IXLCell.cs index 8151246..0396c26 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/IXLCell.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/IXLCell.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using ClosedXML.Excel.Style; + namespace ClosedXML.Excel { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/IXLPrintOptions.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/IXLPrintOptions.cs deleted file mode 100644 index 370b455..0000000 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/IXLPrintOptions.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace ClosedXML.Excel -{ - public enum XLPageOrientation { Default, Portrait, Landscape } - public interface IXLPrintOptions - { - IXLRange PrintArea { get; set; } - XLPageOrientation PageOrientation { get; set; } - Int32 PagesWide { get; set; } - Int32 PagesTall { get; set; } - } -} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/IXLRange.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/IXLRange.cs index 6c4b78d..c5f3b50 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/IXLRange.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/IXLRange.cs @@ -2,24 +2,19 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using ClosedXML.Excel.Style; + namespace ClosedXML.Excel { public interface IXLRange: IXLStylized { - Dictionary CellsCollection { get; } - List MergedCells { get; } - - IXLAddress FirstCellAddress { get; } - IXLAddress LastCellAddress { get; } IXLRange Row(Int32 row); IXLRange Column(Int32 column); IXLRange Column(String column); Int32 RowNumber { get; } Int32 ColumnNumber { get; } String ColumnLetter { get; } - IXLRange PrintArea { get; set; } + IXLRangeInternals Internals { get; } } public static class IXLRangeMethods @@ -35,15 +30,15 @@ public static IXLCell Cell(this IXLRange range, IXLAddress cellAddressInRange) { - IXLAddress absoluteAddress = (XLAddress)cellAddressInRange + (XLAddress)range.FirstCellAddress - 1; - if (range.CellsCollection.ContainsKey(absoluteAddress)) + IXLAddress absoluteAddress = (XLAddress)cellAddressInRange + (XLAddress)range.Internals.FirstCellAddress - 1; + if (range.Internals.Worksheet.Internals.CellsCollection.ContainsKey(absoluteAddress)) { - return range.CellsCollection[absoluteAddress]; + return range.Internals.Worksheet.Internals.CellsCollection[absoluteAddress]; } else { var newCell = new XLCell(absoluteAddress, range.Style); - range.CellsCollection.Add(absoluteAddress, newCell); + range.Internals.Worksheet.Internals.CellsCollection.Add(absoluteAddress, newCell); return newCell; } } @@ -62,11 +57,11 @@ public static Int32 RowCount(this IXLRange range) { - return range.LastCellAddress.Row - range.FirstCellAddress.Row + 1; + return range.Internals.LastCellAddress.Row - range.Internals.FirstCellAddress.Row + 1; } public static Int32 ColumnCount(this IXLRange range) { - return range.LastCellAddress.Column - range.FirstCellAddress.Column + 1; + return range.Internals.LastCellAddress.Column - range.Internals.FirstCellAddress.Column + 1; } public static IXLRange Range(this IXLRange range, Int32 firstCellRow, Int32 firstCellColumn, Int32 lastCellRow, Int32 lastCellColumn) @@ -84,26 +79,20 @@ } public static IXLRange Range(this IXLRange range, IXLAddress firstCellAddress, IXLAddress lastCellAddress) { - var newFirstCellAddress = (XLAddress)firstCellAddress + (XLAddress)range.FirstCellAddress - 1; - var newLastCellAddress = (XLAddress)lastCellAddress + (XLAddress)range.FirstCellAddress - 1; - var xlRangeParameters = new XLRangeParameters() - { - CellsCollection = range.CellsCollection, - MergedCells = range.MergedCells, - DefaultStyle = range.Style, - PrintArea = range.PrintArea - }; + var newFirstCellAddress = (XLAddress)firstCellAddress + (XLAddress)range.Internals.FirstCellAddress - 1; + var newLastCellAddress = (XLAddress)lastCellAddress + (XLAddress)range.Internals.FirstCellAddress - 1; + var xlRangeParameters = new XLRangeParameters(newFirstCellAddress, newLastCellAddress, range.Internals.Worksheet, range.Style); if ( - newFirstCellAddress.Row < range.FirstCellAddress.Row - || newFirstCellAddress.Row > range.LastCellAddress.Row - || newLastCellAddress.Row > range.LastCellAddress.Row - || newFirstCellAddress.Column < range.FirstCellAddress.Column - || newFirstCellAddress.Column > range.LastCellAddress.Column - || newLastCellAddress.Column > range.LastCellAddress.Column + newFirstCellAddress.Row < range.Internals.FirstCellAddress.Row + || newFirstCellAddress.Row > range.Internals.LastCellAddress.Row + || newLastCellAddress.Row > range.Internals.LastCellAddress.Row + || newFirstCellAddress.Column < range.Internals.FirstCellAddress.Column + || newFirstCellAddress.Column > range.Internals.LastCellAddress.Column + || newLastCellAddress.Column > range.Internals.LastCellAddress.Column ) throw new ArgumentOutOfRangeException(); - return new XLRange(newFirstCellAddress, newLastCellAddress, xlRangeParameters); + return new XLRange(xlRangeParameters); } public static IXLRange Range(this IXLRange range, IXLCell firstCell, IXLCell lastCell) { @@ -123,13 +112,13 @@ public static void Merge(this IXLRange range) { - var mergeRange = range.FirstCellAddress.ToString() + ":" + range.LastCellAddress.ToString(); - if (!range.MergedCells.Contains(mergeRange)) - range.MergedCells.Add(mergeRange); + var mergeRange = range.Internals.FirstCellAddress.ToString() + ":" + range.Internals.LastCellAddress.ToString(); + if (!range.Internals.Worksheet.Internals.MergedCells.Contains(mergeRange)) + range.Internals.Worksheet.Internals.MergedCells.Add(mergeRange); } public static void Unmerge(this IXLRange range) { - range.MergedCells.Remove(range.FirstCellAddress.ToString() + ":" + range.LastCellAddress.ToString()); + range.Internals.Worksheet.Internals.MergedCells.Remove(range.Internals.FirstCellAddress.ToString() + ":" + range.Internals.LastCellAddress.ToString()); } public static IXLRange FirstColumn(this IXLRange range) @@ -156,7 +145,7 @@ var lastRow = range.LastRow().RowNumber; var firstColumn = range.FirstColumn().ColumnNumber; var lastColumn = range.LastColumn().ColumnNumber; - foreach (var c in range.CellsCollection + foreach (var c in range.Internals.Worksheet.Internals.CellsCollection .Where(c => c.Key.Row > lastRow && c.Key.Column >= firstColumn @@ -170,8 +159,8 @@ cellsToInsert.Add(newKey, newCell); cellsToDelete.Add(c.Key); } - cellsToDelete.ForEach(c => range.CellsCollection.Remove(c)); - cellsToInsert.ForEach(c => range.CellsCollection.Add(c.Key, c.Value)); + cellsToDelete.ForEach(c => range.Internals.Worksheet.Internals.CellsCollection.Remove(c)); + cellsToInsert.ForEach(c => range.Internals.Worksheet.Internals.CellsCollection.Add(c.Key, c.Value)); } public static void InsertRowsAbove(this IXLRange range, Int32 numberOfRows) { @@ -180,7 +169,7 @@ var firstRow = range.FirstRow().RowNumber; var firstColumn = range.FirstColumn().ColumnNumber; var lastColumn = range.LastColumn().ColumnNumber; - foreach (var c in range.CellsCollection + foreach (var c in range.Internals.Worksheet.Internals.CellsCollection .Where(c => c.Key.Row >= firstRow && c.Key.Column >= firstColumn @@ -194,8 +183,8 @@ cellsToInsert.Add(newKey, newCell); cellsToDelete.Add(c.Key); } - cellsToDelete.ForEach(c => range.CellsCollection.Remove(c)); - cellsToInsert.ForEach(c => range.CellsCollection.Add(c.Key, c.Value)); + cellsToDelete.ForEach(c => range.Internals.Worksheet.Internals.CellsCollection.Remove(c)); + cellsToInsert.ForEach(c => range.Internals.Worksheet.Internals.CellsCollection.Add(c.Key, c.Value)); } public static void InsertColumnsAfter(this IXLRange range, Int32 numberOfColumns) @@ -205,7 +194,7 @@ var firstRow = range.FirstRow().RowNumber; var lastRow = range.LastRow().RowNumber; var lastColumn = range.LastColumn().ColumnNumber; - foreach (var c in range.CellsCollection + foreach (var c in range.Internals.Worksheet.Internals.CellsCollection .Where(c => c.Key.Column > lastColumn && c.Key.Row >= firstRow @@ -219,8 +208,8 @@ cellsToInsert.Add(newKey, newCell); cellsToDelete.Add(c.Key); } - cellsToDelete.ForEach(c => range.CellsCollection.Remove(c)); - cellsToInsert.ForEach(c => range.CellsCollection.Add(c.Key, c.Value)); + cellsToDelete.ForEach(c => range.Internals.Worksheet.Internals.CellsCollection.Remove(c)); + cellsToInsert.ForEach(c => range.Internals.Worksheet.Internals.CellsCollection.Add(c.Key, c.Value)); } public static void InsertColumnsBefore(this IXLRange range, Int32 numberOfColumns) { @@ -229,7 +218,7 @@ var firstRow = range.FirstRow().RowNumber; var lastRow = range.LastRow().RowNumber; var firstColumn = range.FirstColumn().ColumnNumber; - foreach (var c in range.CellsCollection + foreach (var c in range.Internals.Worksheet.Internals.CellsCollection .Where(c => c.Key.Column >= firstColumn && c.Key.Row >= firstRow @@ -243,23 +232,23 @@ cellsToInsert.Add(newKey, newCell); cellsToDelete.Add(c.Key); } - cellsToDelete.ForEach(c => range.CellsCollection.Remove(c)); - cellsToInsert.ForEach(c => range.CellsCollection.Add(c.Key, c.Value)); + cellsToDelete.ForEach(c => range.Internals.Worksheet.Internals.CellsCollection.Remove(c)); + cellsToInsert.ForEach(c => range.Internals.Worksheet.Internals.CellsCollection.Add(c.Key, c.Value)); } public static List Columns(this IXLRange range) { var retVal = new List(); - foreach (var r in Enumerable.Range(1, range.RowCount())) + foreach (var c in Enumerable.Range(1, range.ColumnCount())) { - retVal.Add(range.Row(r)); + retVal.Add(range.Column(c)); } return retVal; } public static void SetAsPrintArea(this IXLRange range) { - range.PrintArea = range; + range.Internals.Worksheet.PrintOptions.PrintArea = range; } } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/IXLRangeInternals.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/IXLRangeInternals.cs new file mode 100644 index 0000000..e73d246 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/IXLRangeInternals.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public interface IXLRangeInternals + { + IXLAddress FirstCellAddress { get; } + IXLAddress LastCellAddress { get; } + IXLWorksheet Worksheet { get; } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/IXLWorkbook.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/IXLWorkbook.cs index 6d61534..62c6324 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/IXLWorkbook.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/IXLWorkbook.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using ClosedXML.Excel.Style; + namespace ClosedXML.Excel { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/IXLWorksheet.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/IXLWorksheet.cs index a54b5cc..61265d9 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/IXLWorksheet.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/IXLWorksheet.cs @@ -7,8 +7,6 @@ { public interface IXLWorksheet: IXLRange { - Dictionary ColumnsCollection { get; } - Dictionary RowsCollection { get; } new IXLRow Row(Int32 column); new IXLColumn Column(Int32 column); new IXLColumn Column(String column); @@ -16,5 +14,6 @@ List Columns(); IXLPrintOptions PrintOptions { get; } + new IXLWorksheetInternals Internals { get; } } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/IXLWorksheetInternals.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/IXLWorksheetInternals.cs new file mode 100644 index 0000000..f017348 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/IXLWorksheetInternals.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public interface IXLWorksheetInternals + { + IXLAddress FirstCellAddress { get; } + IXLAddress LastCellAddress { get; } + Dictionary CellsCollection { get; } + Dictionary ColumnsCollection { get; } + Dictionary RowsCollection { get; } + List MergedCells { get; } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/IXLHFItem.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/IXLHFItem.cs new file mode 100644 index 0000000..9b3dac9 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/IXLHFItem.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public enum XLHFPredefinedText + { + PageNumber, NumberOfPages, Date, Time, FullPath, Path, File, SheetName + } + public enum XLHFOccurrence + { + AllPages, OddPages, EvenPages, FirstPage + } + + public interface IXLHFItem + { + String GetText(XLHFOccurrence occurrence); + void AddText(String text, XLHFOccurrence occurrence = XLHFOccurrence.AllPages, IXLFont xlFont = null); + void AddText(XLHFPredefinedText predefinedText, XLHFOccurrence occurrence = XLHFOccurrence.AllPages, IXLFont xlFont = null); + void Clear(XLHFOccurrence occurrence = XLHFOccurrence.AllPages); + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/IXLHeaderFooter.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/IXLHeaderFooter.cs new file mode 100644 index 0000000..23bb3c4 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/IXLHeaderFooter.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public enum XLHFMode { OddPagesOnly, OddAndEvenPages, Odd } + public interface IXLHeaderFooter + { + IXLHFItem Left { get; } + IXLHFItem Center { get; } + IXLHFItem Right { get; } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/IXLPrintOptions.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/IXLPrintOptions.cs new file mode 100644 index 0000000..c1668f3 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/IXLPrintOptions.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public enum XLPageOrientation { Default, Portrait, Landscape } + public enum XLPaperSize + { + LetterPaper = 1, + LetterSmallPaper = 2, + TabloidPaper = 3, + LedgerPaper = 4, + LegalPaper = 5, + StatementPaper = 6, + ExecutivePaper = 7, + A3Paper = 8, + A4Paper = 9, + A4SmallPaper = 10, + A5Paper = 11, + B4Paper = 12, + B5Paper = 13, + FolioPaper = 14, + QuartoPaper = 15, + StandardPaper = 16, + StandardPaper1 = 17, + NotePaper = 18, + No9Envelope = 19, + No10Envelope = 20, + No11Envelope = 21, + No12Envelope = 22, + No14Envelope = 23, + CPaper = 24, + DPaper = 25, + EPaper = 26, + DlEnvelope = 27, + C5Envelope = 28, + C3Envelope = 29, + C4Envelope = 30, + C6Envelope = 31, + C65Envelope = 32, + B4Envelope = 33, + B5Envelope = 34, + B6Envelope = 35, + ItalyEnvelope = 36, + MonarchEnvelope = 37, + No634Envelope = 38, + UsStandardFanfold = 39, + GermanStandardFanfold = 40, + GermanLegalFanfold = 41, + IsoB4 = 42, + JapaneseDoublePostcard = 43, + StandardPaper2 = 44, + StandardPaper3 = 45, + StandardPaper4 = 46, + InviteEnvelope = 47, + LetterExtraPaper = 50, + LegalExtraPaper = 51, + TabloidExtraPaper = 52, + A4ExtraPaper = 53, + LetterTransversePaper = 54, + A4TransversePaper = 55, + LetterExtraTransversePaper = 56, + SuperaSuperaA4Paper = 57, + SuperbSuperbA3Paper = 58, + LetterPlusPaper = 59, + A4PlusPaper = 60, + A5TransversePaper = 61, + JisB5TransversePaper = 62, + A3ExtraPaper = 63, + A5ExtraPaper = 64, + IsoB5ExtraPaper = 65, + A2Paper = 66, + A3TransversePaper = 67, + A3ExtraTransversePaper = 68 + } + public interface IXLPrintOptions + { + IXLRange PrintArea { get; set; } + XLPageOrientation PageOrientation { get; set; } + Int32 PagesWide { get; set; } + Int32 PagesTall { get; set; } + Int32 Scale { get; set; } + Int32 HorizontalDpi { get; set; } + Int32 VerticalDpi { get; set; } + Int32 FirstPageNumber { get; set; } + Boolean CenterHorizontally { get; set; } + Boolean CenterVertically { get; set; } + void AdjustTo(Int32 pctOfNormalSize); + void FitTo(Int32 pagesWide, Int32 pagesTall); + XLPaperSize PaperSize { get; set; } + XLMargins Margins { get; } + + IXLHeaderFooter Header { get; } + IXLHeaderFooter Footer { get; } + Boolean ScaleHFWithDocument { get; set; } + Boolean AlignHFWithMargins { get; set; } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/XLHFItem.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/XLHFItem.cs new file mode 100644 index 0000000..b6e41d9 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/XLHFItem.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public class XLHFItem: IXLHFItem + { + private Dictionary texts = new Dictionary(); + public String GetText(XLHFOccurrence occurrence) + { + if(texts.ContainsKey(occurrence)) + return texts[occurrence]; + else + return String.Empty; + } + + public void AddText(String text, XLHFOccurrence occurrence = XLHFOccurrence.AllPages, IXLFont xlFont = null) + { + if (text.Length > 0) + { + var hfFont = GetHFFont(xlFont); + var newText = hfFont + text; + if (texts.ContainsKey(occurrence)) + texts[occurrence] = texts[occurrence] + newText; + else + texts.Add(occurrence, newText); + } + } + + public void AddText(XLHFPredefinedText predefinedText, XLHFOccurrence occurrence = XLHFOccurrence.AllPages, IXLFont xlFont = null) + { + String hfText; + switch (predefinedText) + { + case XLHFPredefinedText.PageNumber: hfText = "&P"; break; + case XLHFPredefinedText.NumberOfPages : hfText = "&N"; break; + case XLHFPredefinedText.Date : hfText = "&D"; break; + case XLHFPredefinedText.Time : hfText = "&T"; break; + case XLHFPredefinedText.Path : hfText = "&Z"; break; + case XLHFPredefinedText.File : hfText = "&F"; break; + case XLHFPredefinedText.SheetName : hfText = "&A"; break; + default: throw new NotImplementedException(); + } + AddText(hfText, occurrence, xlFont); + } + + public void Clear(XLHFOccurrence occurrence = XLHFOccurrence.AllPages) + { + if (texts.ContainsKey(occurrence)) + texts.Remove(occurrence); + } + + private String GetHFFont(IXLFont xlFont) + { + String retVal = String.Empty; + + retVal += xlFont.FontName != null ? "&\"" + xlFont.FontName : "\"-"; + retVal += GetHFFontBoldItalic(xlFont); + retVal += xlFont.FontSize > 0 ? "&" + xlFont.FontSize.ToString() : ""; + retVal += xlFont.Strikethrough ? "&S" : ""; + retVal += xlFont.VerticalAlignment == XLFontVerticalTextAlignmentValues.Subscript ? "&Y" : ""; + retVal += xlFont.VerticalAlignment == XLFontVerticalTextAlignmentValues.Superscript ? "&X" : ""; + retVal += xlFont.Underline== XLFontUnderlineValues.Single ? "&U" : ""; + retVal += xlFont.Underline == XLFontUnderlineValues.Double ? "&E" : ""; + retVal += "&K" + xlFont.FontColor.ToHex(); + return retVal; + } + + private String GetHFFontBoldItalic(IXLFont xlFont) + { + String retVal = String.Empty; + if (xlFont.Bold && xlFont.Italic) + { + retVal += ",Bold Italic\""; + } + else if (xlFont.Bold) + { + retVal += ",Bold\""; + } + else if (xlFont.Italic) + { + retVal += ",Italic\""; + } + else + { + retVal += ",Regular\""; + } + + return retVal; + } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/XLHeaderFooter.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/XLHeaderFooter.cs new file mode 100644 index 0000000..b0f91ee --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/XLHeaderFooter.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public class XLHeaderFooter: IXLHeaderFooter + { + + public bool ScaleWithDocument + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + + public bool AlignWithMargins + { + get + { + throw new NotImplementedException(); + } + set + { + throw new NotImplementedException(); + } + } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/XLMargins.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/XLMargins.cs new file mode 100644 index 0000000..0a784c0 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/XLMargins.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public class XLMargins + { + public Double Left { get; set; } + public Double Right { get; set; } + public Double Top { get; set; } + public Double Bottom { get; set; } + public Double Header { get; set; } + public Double Footer { get; set; } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/XLPrintOptions.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/XLPrintOptions.cs new file mode 100644 index 0000000..bb305f7 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/PrintOptions/XLPrintOptions.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public class XLPrintOptions : IXLPrintOptions + { + public XLPrintOptions(XLPrintOptions defaultPrintOptions) + { + if (defaultPrintOptions != null) + { + this.CenterHorizontally = defaultPrintOptions.CenterHorizontally; + this.CenterVertically = defaultPrintOptions.CenterVertically; + this.FirstPageNumber = defaultPrintOptions.FirstPageNumber; + this.HorizontalDpi = defaultPrintOptions.HorizontalDpi; + this.PageOrientation = defaultPrintOptions.PageOrientation; + this.VerticalDpi = defaultPrintOptions.VerticalDpi; + if (defaultPrintOptions.PrintArea != null) + { + this.PrintArea = new XLRange( + new XLRangeParameters( + defaultPrintOptions.PrintArea.Internals.FirstCellAddress, + defaultPrintOptions.PrintArea.Internals.LastCellAddress, + defaultPrintOptions.PrintArea.Internals.Worksheet, + defaultPrintOptions.PrintArea.Style) + ); + } + this.PaperSize = defaultPrintOptions.PaperSize; + this.pagesTall = defaultPrintOptions.pagesTall; + this.pagesWide = defaultPrintOptions.pagesWide; + this.scale = defaultPrintOptions.scale; + + if (defaultPrintOptions.Margins != null) + { + this.Margins = new XLMargins() + { + Top = defaultPrintOptions.Margins.Top, + Bottom = defaultPrintOptions.Margins.Bottom, + Left = defaultPrintOptions.Margins.Left, + Right = defaultPrintOptions.Margins.Right, + Header = defaultPrintOptions.Margins.Header, + Footer = defaultPrintOptions.Margins.Footer + }; + } + + if (defaultPrintOptions.HeaderFooters != null) + { + //HeaderFooters = new XLHeaderFooter(); + } + } + } + public IXLRange PrintArea { get; set; } + public XLPageOrientation PageOrientation { get; set; } + public XLPaperSize PaperSize { get; set; } + public Int32 HorizontalDpi { get; set; } + public Int32 VerticalDpi { get; set; } + public Int32 FirstPageNumber { get; set; } + public Boolean CenterHorizontally { get; set; } + public Boolean CenterVertically { get; set; } + + public XLMargins Margins { get; set; } + public IXLHeaderFooter HeaderFooters { get; private set; } + + private Int32 pagesWide; + public Int32 PagesWide + { + get + { + return pagesWide; + } + set + { + pagesWide = value; + scale = 0; + } + } + + private Int32 pagesTall; + public Int32 PagesTall + { + get + { + return pagesTall; + } + set + { + pagesTall = value; + scale = 0; + } + } + + private Int32 scale; + public Int32 Scale + { + get + { + return scale; + } + set + { + scale = value; + pagesTall = 0; + pagesWide = 0; + } + } + + public void AdjustTo(Int32 pctOfNormalSize) + { + Scale = pctOfNormalSize; + pagesWide = 0; + pagesTall = 0; + } + public void FitTo(Int32 pagesWide, Int32 pagesTall) + { + this.pagesWide = pagesWide; + this.pagesTall = pagesTall; + Scale = 0; + } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLAlignment.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLAlignment.cs index f45c633..f9aefeb 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLAlignment.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLAlignment.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -namespace ClosedXML.Excel.Style +namespace ClosedXML.Excel { public enum XLAlignmentReadingOrderValues { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLBorder.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLBorder.cs index fa8cb42..ce756d4 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLBorder.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLBorder.cs @@ -4,7 +4,7 @@ using System.Text; using System.Drawing; -namespace ClosedXML.Excel.Style +namespace ClosedXML.Excel { public enum XLBorderStyleValues { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFill.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFill.cs index 2e50c03..610280d 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFill.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFill.cs @@ -4,7 +4,7 @@ using System.Text; using System.Drawing; -namespace ClosedXML.Excel.Style +namespace ClosedXML.Excel { public enum XLFillPatternValues { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFont.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFont.cs index 8cd2e0c..f1326a8 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFont.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLFont.cs @@ -4,7 +4,7 @@ using System.Text; using System.Drawing; -namespace ClosedXML.Excel.Style +namespace ClosedXML.Excel { public enum XLFontUnderlineValues { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLNumberFormat.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLNumberFormat.cs index 256e92b..3572a6a 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLNumberFormat.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLNumberFormat.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -namespace ClosedXML.Excel.Style +namespace ClosedXML.Excel { public interface IXLNumberFormat { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLStyle.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLStyle.cs index 4a45c11..f00271c 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLStyle.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLStyle.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -namespace ClosedXML.Excel.Style +namespace ClosedXML.Excel { public interface IXLStyle { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLStylized.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLStylized.cs index c729e4c..2fdeb4f 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLStylized.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/IXLStylized.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -namespace ClosedXML.Excel.Style +namespace ClosedXML.Excel { public interface IXLStylized { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLAlignment.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLAlignment.cs index e074f3c..d02b690 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLAlignment.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLAlignment.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -namespace ClosedXML.Excel.Style +namespace ClosedXML.Excel { public class XLAlignment: IXLAlignment { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLBorder.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLBorder.cs index 01e7fe0..ce58280 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLBorder.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLBorder.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using System.Drawing; -namespace ClosedXML.Excel.Style +namespace ClosedXML.Excel { public class XLBorder: IXLBorder { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFill.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFill.cs index 6f29a53..95df52b 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFill.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFill.cs @@ -4,7 +4,7 @@ using System.Text; using System.Drawing; -namespace ClosedXML.Excel.Style +namespace ClosedXML.Excel { public class XLFill: IXLFill { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFont.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFont.cs index 2e39f4d..7256711 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFont.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLFont.cs @@ -4,12 +4,12 @@ using System.Text; using System.Drawing; -namespace ClosedXML.Excel.Style +namespace ClosedXML.Excel { public class XLFont: IXLFont { IXLStylized container; - public XLFont(IXLStylized container, IXLFont defaultFont = null) + public XLFont(IXLStylized container = null, IXLFont defaultFont = null) { this.container = container; if (defaultFont != null) diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLNumberFormat.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLNumberFormat.cs index 378a75a..711f0f5 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLNumberFormat.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLNumberFormat.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -namespace ClosedXML.Excel.Style +namespace ClosedXML.Excel { public class XLNumberFormat: IXLNumberFormat { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStyle.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStyle.cs index 8e3ac2e..59564d7 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStyle.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Style/XLStyle.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -namespace ClosedXML.Excel.Style +namespace ClosedXML.Excel { public class XLStyle: IXLStyle { diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLCell.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLCell.cs index 5a7eac6..a388442 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLCell.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLCell.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using ClosedXML.Excel.Style; + namespace ClosedXML.Excel { @@ -34,7 +34,7 @@ Double dTest; DateTime dtTest; Boolean bTest; - if (val.Substring(0, 1) == "'") + if (val.Length > 0 && val.Substring(0, 1) == "'") { val = val.Substring(1, val.Length - 1); dataType = XLCellValues.Text; diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLColumn.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLColumn.cs index 7ceadcd..705bcc3 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLColumn.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLColumn.cs @@ -2,22 +2,19 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using ClosedXML.Excel.Style; + namespace ClosedXML.Excel { public class XLColumn: IXLColumn { - public XLColumn(Int32 column, XLRangeParameters xlRangeParameters) + public XLColumn(Int32 column, XLColumnParameters xlColumnParameters) { - FirstCellAddress = new XLAddress(1, column); - LastCellAddress = new XLAddress(XLWorksheet.MaxNumberOfRows, column); + Internals = new XLRangeInternals(new XLAddress(1, column), new XLAddress(XLWorksheet.MaxNumberOfRows, column), xlColumnParameters.Worksheet); RowNumber = 1; ColumnNumber = column; ColumnLetter = XLAddress.GetColumnLetterFromNumber(column); - CellsCollection = xlRangeParameters.CellsCollection; - PrintArea = xlRangeParameters.PrintArea; - this.style = new XLStyle(this, xlRangeParameters.DefaultStyle); + this.style = new XLStyle(this, xlColumnParameters.DefaultStyle); this.Width = XLWorkbook.DefaultColumnWidth; } @@ -26,15 +23,6 @@ public Int32 ColumnNumber { get; private set; } public String ColumnLetter { get; private set; } - #region IXLRange Members - - public Dictionary CellsCollection { get; private set; } - public List MergedCells { get; private set; } - public IXLAddress FirstCellAddress { get; private set; } - public IXLAddress LastCellAddress { get; private set; } - - #endregion - #region IXLStylized Members private IXLStyle style; @@ -56,7 +44,7 @@ { UpdatingStyle = true; yield return style; - foreach (var c in CellsCollection.Values.Where(c => c.Address.Column == FirstCellAddress.Column)) + foreach (var c in Internals.Worksheet.Internals.CellsCollection.Values.Where(c => c.Address.Column == Internals.FirstCellAddress.Column)) { yield return c.Style; } @@ -88,6 +76,6 @@ #endregion - public IXLRange PrintArea { get; set; } + public IXLRangeInternals Internals { get; private set; } } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLColumnParameters.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLColumnParameters.cs new file mode 100644 index 0000000..967ad1a --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLColumnParameters.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + + +namespace ClosedXML.Excel +{ + public class XLColumnParameters + { + public XLColumnParameters(IXLWorksheet worksheet, IXLStyle defaultStyle) + { + Worksheet = worksheet; + DefaultStyle = defaultStyle; + } + public IXLStyle DefaultStyle { get; set; } + public IXLWorksheet Worksheet { get; private set; } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLPrintOptions.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLPrintOptions.cs deleted file mode 100644 index d16dd17..0000000 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLPrintOptions.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace ClosedXML.Excel -{ - public class XLPrintOptions : IXLPrintOptions - { - public XLPrintOptions() - { - PageOrientation = XLPageOrientation.Default; - } - public IXLRange PrintArea { get; set; } - public XLPageOrientation PageOrientation { get; set; } - public Int32 PagesWide { get; set; } - public Int32 PagesTall { get; set; } - } -} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLRange.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLRange.cs index c0696d3..77a2407 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLRange.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLRange.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using ClosedXML.Excel.Style; + namespace ClosedXML.Excel { @@ -10,28 +10,17 @@ { private IXLStyle defaultStyle; - public XLRange(IXLAddress firstCellAddress, IXLAddress lastCellAddress, XLRangeParameters xlRangeParameters) + public XLRange(XLRangeParameters xlRangeParameters) { - FirstCellAddress = firstCellAddress; - LastCellAddress = lastCellAddress; - CellsCollection = xlRangeParameters.CellsCollection; - MergedCells = xlRangeParameters.MergedCells; - RowNumber = FirstCellAddress.Row; - ColumnNumber = FirstCellAddress.Column; - ColumnLetter = FirstCellAddress.ColumnLetter; - PrintArea = xlRangeParameters.PrintArea; + Internals = new XLRangeInternals(xlRangeParameters.FirstCellAddress, xlRangeParameters.LastCellAddress, xlRangeParameters.Worksheet); + RowNumber = xlRangeParameters.FirstCellAddress.Row; + ColumnNumber = xlRangeParameters.FirstCellAddress.Column; + ColumnLetter = xlRangeParameters.FirstCellAddress.ColumnLetter; this.defaultStyle = new XLStyle(this, xlRangeParameters.DefaultStyle); } #region IXLRange Members - public Dictionary CellsCollection { get; private set; } - public List MergedCells { get; private set; } - - public IXLAddress FirstCellAddress { get; private set; } - - public IXLAddress LastCellAddress { get; private set; } - public IXLRange Row(Int32 row) { IXLAddress firstCellAddress = new XLAddress(row, 1); @@ -54,9 +43,9 @@ public Int32 RowNumber { get; private set; } public Int32 ColumnNumber { get; private set; } public String ColumnLetter { get; private set; } - - public IXLRange PrintArea { get; set; } + public IXLRangeInternals Internals { get; private set; } + #endregion #region IXLStylized Members diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLRangeInternals.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLRangeInternals.cs new file mode 100644 index 0000000..1bd9cc7 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLRangeInternals.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public class XLRangeInternals: IXLRangeInternals + { + public XLRangeInternals(IXLAddress firstCellAddress, IXLAddress lastCellAddress, IXLWorksheet worksheet) + { + FirstCellAddress = firstCellAddress; + LastCellAddress = lastCellAddress; + Worksheet = worksheet; + } + public IXLAddress FirstCellAddress { get; private set; } + public IXLAddress LastCellAddress { get; private set; } + public IXLWorksheet Worksheet { get; private set; } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLRangeParameters.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLRangeParameters.cs index ee29ae9..d399710 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLRangeParameters.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLRangeParameters.cs @@ -2,28 +2,26 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using ClosedXML.Excel.Style; + namespace ClosedXML.Excel { public class XLRangeParameters { - #region Variables - - // Public - - // Private - - - #endregion - + public XLRangeParameters(IXLAddress firstCellAddress, IXLAddress lastCellAddress, IXLWorksheet worksheet, IXLStyle defaultStyle) + { + FirstCellAddress = firstCellAddress; + LastCellAddress = lastCellAddress; + Worksheet = worksheet; + DefaultStyle = defaultStyle; + } #region Properties // Public - public Dictionary CellsCollection { get; set; } - public List MergedCells { get; set; } - public IXLStyle DefaultStyle { get; set; } - public IXLRange PrintArea { get; set; } + public IXLAddress FirstCellAddress { get; private set; } + public IXLAddress LastCellAddress { get; private set; } + public IXLWorksheet Worksheet { get; private set; } + public IXLStyle DefaultStyle { get; private set; } // Private @@ -32,40 +30,5 @@ #endregion - #region Constructors - - // Public - public XLRangeParameters() - { - - } - - - // Private - - - #endregion - - #region Events - - // Public - - // Private - - // Override - - - #endregion - - #region Methods - - // Public - - // Private - - // Override - - - #endregion } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLRow.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLRow.cs index 1dd52ea..b20514d 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLRow.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLRow.cs @@ -2,22 +2,19 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using ClosedXML.Excel.Style; + namespace ClosedXML.Excel { public class XLRow: IXLRow { - public XLRow(Int32 row, XLRangeParameters xlRangeParameters) + public XLRow(Int32 row, XLRowParameters xlRowParameters) { - FirstCellAddress = new XLAddress(row, 1); - LastCellAddress = new XLAddress(row, XLWorksheet.MaxNumberOfColumns); + Internals = new XLRangeInternals(new XLAddress(row, 1), new XLAddress(row, XLWorksheet.MaxNumberOfColumns), xlRowParameters.Worksheet); RowNumber = row; ColumnNumber = 1; ColumnLetter = "A"; - CellsCollection = xlRangeParameters.CellsCollection; - PrintArea = xlRangeParameters.PrintArea; - this.style = new XLStyle(this, xlRangeParameters.DefaultStyle); + this.style = new XLStyle(this, xlRowParameters.DefaultStyle); this.Height = XLWorkbook.DefaultRowHeight; } @@ -28,11 +25,7 @@ #region IXLRange Members - public Dictionary CellsCollection { get; private set; } - public List MergedCells { get; private set; } - public IXLAddress FirstCellAddress { get; private set; } - public IXLAddress LastCellAddress { get; private set; } - public IXLRange PrintArea { get; set; } + public IXLRangeInternals Internals { get; private set; } #endregion @@ -57,7 +50,7 @@ { UpdatingStyle = true; yield return style; - foreach (var c in CellsCollection.Values.Where(c => c.Address.Row == FirstCellAddress.Row)) + foreach (var c in Internals.Worksheet.Internals.CellsCollection.Values.Where(c => c.Address.Row == Internals.FirstCellAddress.Row)) { yield return c.Style; } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLRowParameters.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLRowParameters.cs new file mode 100644 index 0000000..787ffb6 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLRowParameters.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + + +namespace ClosedXML.Excel +{ + public class XLRowParameters + { + public XLRowParameters(IXLWorksheet worksheet, IXLStyle defaultStyle) + { + Worksheet = worksheet; + DefaultStyle = defaultStyle; + } + public IXLStyle DefaultStyle { get; set; } + public IXLWorksheet Worksheet { get; private set; } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook.cs index 2e90a8c..6990031 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using ClosedXML.Excel.Style; + using System.IO; using System.Drawing; @@ -43,11 +43,11 @@ #region Static - private static XLStyle defaultStyle; + private static IXLStyle defaultStyle; /// /// Gets the default style for new workbooks. /// - public static XLStyle DefaultStyle + public static IXLStyle DefaultStyle { get { @@ -112,6 +112,33 @@ public static Double DefaultRowHeight { get; set; } public static Double DefaultColumnWidth { get; set; } + public static XLPrintOptions defaultPrintOptions; + public static XLPrintOptions DefaultPrintOptions + { + get + { + if (defaultPrintOptions == null) + { + defaultPrintOptions = new XLPrintOptions(null) + { + PageOrientation = XLPageOrientation.Default, + Scale = 100, + PaperSize = XLPaperSize.LetterPaper, + Margins = new XLMargins() + { + Top = 0.75, + Bottom = 0.75, + Left = 0.75, + Right = 0.75, + Header = 0.75, + Footer = 0.75 + } + }; + } + return defaultPrintOptions; + } + } + #endregion } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs index 0c94552..a6beecd 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs @@ -12,7 +12,7 @@ using System.Linq; using System.Text; using System.IO; -using ClosedXML.Excel.Style; + namespace ClosedXML.Excel @@ -327,17 +327,18 @@ if (worksheet.PrintOptions.PrintArea == null) { - var minCell = worksheet.CellsCollection.Min(c => c.Key); - var maxCell = worksheet.CellsCollection.Max(c => c.Key); + var minCell = worksheet.Internals.CellsCollection.Min(c => c.Key); + var maxCell = worksheet.Internals.CellsCollection.Max(c => c.Key); if (minCell != null && maxCell != null) - { worksheet.PrintOptions.PrintArea = worksheet.Range(minCell, maxCell); - DefinedName definedName = new DefinedName() { Name = "_xlnm.Print_Area", LocalSheetId = (UInt32Value)sheetId - 1 }; - definedName.Text = "'" + worksheet.Name + "'!" - + worksheet.PrintOptions.PrintArea.FirstCellAddress.ToString() - + ":" + worksheet.PrintOptions.PrintArea.LastCellAddress.ToString(); - definedNames.Append(definedName); - } + } + if (worksheet.PrintOptions.PrintArea != null) + { + DefinedName definedName = new DefinedName() { Name = "_xlnm.Print_Area", LocalSheetId = (UInt32Value)sheetId - 1 }; + definedName.Text = "'" + worksheet.Name + "'!" + + worksheet.PrintOptions.PrintArea.Internals.FirstCellAddress.ToString() + + ":" + worksheet.PrintOptions.PrintArea.Internals.LastCellAddress.ToString(); + definedNames.Append(definedName); } } @@ -356,7 +357,7 @@ private void GenerateSharedStringTablePartContent(SharedStringTablePart sharedStringTablePart) { List combined = new List(); - Worksheets.ForEach(w => combined.AddRange(w.CellsCollection.Values.Where(c => c.DataType == XLCellValues.Text && c.Value != null).Select(c => c.Value).Distinct())); + Worksheets.ForEach(w => combined.AddRange(w.Internals.CellsCollection.Values.Where(c => c.DataType == XLCellValues.Text && c.Value != null).Select(c => c.Value).Distinct())); var distinctStrings = combined.Distinct(); UInt32 stringCount = (UInt32)distinctStrings.Count(); SharedStringTable sharedStringTable = new SharedStringTable() { Count = (UInt32Value)stringCount, UniqueCount = (UInt32Value)stringCount }; @@ -417,8 +418,8 @@ foreach (var worksheet in Worksheets) { xlStyles.AddRange(worksheet.Styles); - worksheet.ColumnsCollection.Values.ForEach(c => xlStyles.Add(c.Style)); - worksheet.RowsCollection.Values.ForEach(c => xlStyles.Add(c.Style)); + worksheet.Internals.ColumnsCollection.Values.ForEach(c => xlStyles.Add(c.Style)); + worksheet.Internals.RowsCollection.Values.ForEach(c => xlStyles.Add(c.Style)); } @@ -644,7 +645,10 @@ SheetProperties sheetProperties = new SheetProperties() { CodeName = xlWorksheet.Name.RemoveSpecialCharacters() }; if (xlWorksheet.PrintOptions.PagesTall >= 0 || xlWorksheet.PrintOptions.PagesWide >= 0) { - PageSetupProperties pageSetupProperties = new PageSetupProperties() { FitToPage = true }; + PageSetupProperties pageSetupProperties = new PageSetupProperties(); + if (xlWorksheet.PrintOptions.PagesWide > 0 || xlWorksheet.PrintOptions.PagesTall > 0) + pageSetupProperties.FitToPage = true; + sheetProperties.Append(pageSetupProperties); } @@ -652,22 +656,22 @@ UInt32 maxRow = 0; String sheetDimensionReference = "A1"; - if (xlWorksheet.CellsCollection.Count > 0) + if (xlWorksheet.Internals.CellsCollection.Count > 0) { - maxColumn = (UInt32)xlWorksheet.CellsCollection.Select(c => c.Key.Column).Max(); - maxRow = (UInt32)xlWorksheet.CellsCollection.Select(c => c.Key.Row).Max(); + maxColumn = (UInt32)xlWorksheet.Internals.CellsCollection.Select(c => c.Key.Column).Max(); + maxRow = (UInt32)xlWorksheet.Internals.CellsCollection.Select(c => c.Key.Row).Max(); sheetDimensionReference = "A1:" + new XLAddress((Int32)maxRow, (Int32)maxColumn).ToString(); } - if (xlWorksheet.ColumnsCollection.Count > 0) + if (xlWorksheet.Internals.ColumnsCollection.Count > 0) { - UInt32 maxColCollection = (UInt32)xlWorksheet.ColumnsCollection.Keys.Max(); + UInt32 maxColCollection = (UInt32)xlWorksheet.Internals.ColumnsCollection.Keys.Max(); if (maxColCollection > maxColumn) maxColumn = maxColCollection; } - if (xlWorksheet.RowsCollection.Count > 0) + if (xlWorksheet.Internals.RowsCollection.Count > 0) { - UInt32 maxRowCollection = (UInt32)xlWorksheet.RowsCollection.Keys.Max(); + UInt32 maxRowCollection = (UInt32)xlWorksheet.Internals.RowsCollection.Keys.Max(); if (maxRowCollection > maxRow) maxRow = maxRowCollection; } @@ -682,15 +686,15 @@ SheetFormatProperties sheetFormatProperties3 = new SheetFormatProperties() { DefaultRowHeight = 15D }; Columns columns = null; - if (xlWorksheet.ColumnsCollection.Count > 0) + if (xlWorksheet.Internals.ColumnsCollection.Count > 0) { columns = new Columns(); - foreach (var xlColumn in xlWorksheet.ColumnsCollection.Values) + foreach (var xlColumn in xlWorksheet.Internals.ColumnsCollection.Values) { Column column = new Column() { - Min = (UInt32Value)(UInt32)xlColumn.FirstCellAddress.Column, - Max = (UInt32Value)(UInt32)xlColumn.FirstCellAddress.Column, + Min = (UInt32Value)(UInt32)xlColumn.Internals.FirstCellAddress.Column, + Max = (UInt32Value)(UInt32)xlColumn.Internals.FirstCellAddress.Column, Style = sharedStyles[xlColumn.Style.ToString()].StyleId, Width = xlColumn.Width, CustomWidth = true @@ -702,23 +706,23 @@ SheetData sheetData = new SheetData(); - var rowsFromCells = xlWorksheet.CellsCollection.Where(c => c.Key.Column > 0 && c.Key.Row > 0).Select(c => c.Key.Row).Distinct(); - var rowsFromCollection = xlWorksheet.RowsCollection.Keys; + var rowsFromCells = xlWorksheet.Internals.CellsCollection.Where(c => c.Key.Column > 0 && c.Key.Row > 0).Select(c => c.Key.Row).Distinct(); + var rowsFromCollection = xlWorksheet.Internals.RowsCollection.Keys; var allRows = rowsFromCells.ToList(); allRows.AddRange(rowsFromCollection); var distinctRows = allRows.Distinct(); foreach (var distinctRow in distinctRows.OrderBy(r => r)) { Row row = new Row() { RowIndex = (UInt32Value)(UInt32)distinctRow, Spans = new ListValue() { InnerText = "1:" + maxRow.ToString() } }; - if (xlWorksheet.RowsCollection.ContainsKey(distinctRow)) + if (xlWorksheet.Internals.RowsCollection.ContainsKey(distinctRow)) { - var thisRow = xlWorksheet.RowsCollection[distinctRow]; + var thisRow = xlWorksheet.Internals.RowsCollection[distinctRow]; row.Height = thisRow.Height; row.CustomHeight = true; row.StyleIndex = sharedStyles[thisRow.Style.ToString()].StyleId; row.CustomFormat = true; } - foreach (var opCell in xlWorksheet.CellsCollection + foreach (var opCell in xlWorksheet.Internals.CellsCollection .Where(c => c.Key.Row == distinctRow) .OrderBy(c => c.Key) .Select(c => c)) @@ -769,24 +773,79 @@ } MergeCells mergeCells = null; - if (xlWorksheet.MergedCells.Count > 0) + if (xlWorksheet.Internals.MergedCells.Count > 0) { - mergeCells = new MergeCells() { Count = (UInt32Value)(UInt32)xlWorksheet.MergedCells.Count }; - foreach (var merged in xlWorksheet.MergedCells) + mergeCells = new MergeCells() { Count = (UInt32Value)(UInt32)xlWorksheet.Internals.MergedCells.Count }; + foreach (var merged in xlWorksheet.Internals.MergedCells) { MergeCell mergeCell = new MergeCell() { Reference = merged }; mergeCells.Append(mergeCell); } } - PageMargins pageMargins = new PageMargins() { Left = 0.7D, Right = 0.7D, Top = 0.75D, Bottom = 0.75D, Header = 0.3D, Footer = 0.3D }; + PageMargins pageMargins = new PageMargins() { + Left = xlWorksheet.PrintOptions.Margins.Left, + Right = xlWorksheet.PrintOptions.Margins.Right, + Top = xlWorksheet.PrintOptions.Margins.Top, + Bottom = xlWorksheet.PrintOptions.Margins.Bottom, + Header = xlWorksheet.PrintOptions.Margins.Header, + Footer = xlWorksheet.PrintOptions.Margins.Footer + }; //Drawing drawing1 = new Drawing() { Id = "rId1" }; - PageSetup pageSetup1 = new PageSetup() { Orientation = GetOrientationValue(xlWorksheet.PrintOptions.PageOrientation), HorizontalDpi = (UInt32Value)300U, VerticalDpi = (UInt32Value)300U, Id = "rId" + RelId.GetNext(RelType.Worksheet) }; - if (xlWorksheet.PrintOptions.PagesWide >= 0) - pageSetup1.FitToWidth = (UInt32Value)(UInt32)xlWorksheet.PrintOptions.PagesWide; - if (xlWorksheet.PrintOptions.PagesTall >= 0) - pageSetup1.FitToHeight = (UInt32Value)(UInt32)xlWorksheet.PrintOptions.PagesTall; + PageSetup pageSetup1 = new PageSetup() { + Orientation = GetOrientationValue(xlWorksheet.PrintOptions.PageOrientation), + Id = "rId" + RelId.GetNext(RelType.Worksheet), + PaperSize = (UInt32Value)(UInt32)xlWorksheet.PrintOptions.PaperSize + }; + + if (xlWorksheet.PrintOptions.FirstPageNumber > 0) + { + pageSetup1.FirstPageNumber = (UInt32Value)(UInt32)xlWorksheet.PrintOptions.FirstPageNumber; + pageSetup1.UseFirstPageNumber = true; + } + + if (xlWorksheet.PrintOptions.HorizontalDpi > 0) + pageSetup1.HorizontalDpi = (UInt32Value)(UInt32)xlWorksheet.PrintOptions.HorizontalDpi; + + if (xlWorksheet.PrintOptions.VerticalDpi > 0) + pageSetup1.VerticalDpi = (UInt32Value)(UInt32)xlWorksheet.PrintOptions.VerticalDpi; + + if (xlWorksheet.PrintOptions.Scale > 0) + { + pageSetup1.Scale = (UInt32Value)(UInt32)xlWorksheet.PrintOptions.Scale; + } + else + { + if (xlWorksheet.PrintOptions.PagesWide > 0) + pageSetup1.FitToWidth = (UInt32Value)(UInt32)xlWorksheet.PrintOptions.PagesWide; + if (xlWorksheet.PrintOptions.PagesTall > 0) + pageSetup1.FitToHeight = (UInt32Value)(UInt32)xlWorksheet.PrintOptions.PagesTall; + } + + PrintOptions printOptions = new PrintOptions() { + HorizontalCentered = xlWorksheet.PrintOptions.CenterHorizontally, + VerticalCentered = xlWorksheet.PrintOptions.CenterVertically }; + + HeaderFooter headerFooter = new HeaderFooter(); + headerFooter.ScaleWithDoc = xlWorksheet.PrintOptions.ScaleHFWithDocument; + headerFooter.AlignWithMargins = xlWorksheet.PrintOptions.AlignHFWithMargins; + + FirstHeader firstHeader = new FirstHeader("&L" + xlWorksheet.PrintOptions.Header.Left.GetText(XLHFOccurrence.FirstPage) + "&C" + xlWorksheet.PrintOptions.Header.Center.GetText(XLHFOccurrence.FirstPage) + "&R" + xlWorksheet.PrintOptions.Header.Right.GetText(XLHFOccurrence.FirstPage) + ""); + headerFooter.Append(firstHeader); + OddHeader oddHeader = new OddHeader("&L" + xlWorksheet.PrintOptions.Header.Left.GetText(XLHFOccurrence.OddPages) + "&C" + xlWorksheet.PrintOptions.Header.Center.GetText(XLHFOccurrence.OddPages) + "&R" + xlWorksheet.PrintOptions.Header.Right.GetText(XLHFOccurrence.OddPages) + ""); + headerFooter.Append(oddHeader); + EvenHeader evenHeader = new EvenHeader("&L" + xlWorksheet.PrintOptions.Header.Left.GetText(XLHFOccurrence.EvenPages) + "&C" + xlWorksheet.PrintOptions.Header.Center.GetText(XLHFOccurrence.EvenPages) + "&R" + xlWorksheet.PrintOptions.Header.Right.GetText(XLHFOccurrence.EvenPages) + ""); + headerFooter.Append(evenHeader); + + FirstFooter firstFooter = new FirstFooter("&L" + xlWorksheet.PrintOptions.Footer.Left.GetText(XLHFOccurrence.FirstPage) + "&C" + xlWorksheet.PrintOptions.Footer.Center.GetText(XLHFOccurrence.FirstPage) + "&R" + xlWorksheet.PrintOptions.Footer.Right.GetText(XLHFOccurrence.FirstPage) + ""); + headerFooter.Append(firstFooter); + OddFooter oddFooter = new OddFooter("&L" + xlWorksheet.PrintOptions.Footer.Left.GetText(XLHFOccurrence.OddPages) + "&C" + xlWorksheet.PrintOptions.Footer.Center.GetText(XLHFOccurrence.OddPages) + "&R" + xlWorksheet.PrintOptions.Footer.Right.GetText(XLHFOccurrence.OddPages) + ""); + headerFooter.Append(oddFooter); + EvenFooter evenFooter = new EvenFooter("&L" + xlWorksheet.PrintOptions.Footer.Left.GetText(XLHFOccurrence.EvenPages) + "&C" + xlWorksheet.PrintOptions.Footer.Center.GetText(XLHFOccurrence.EvenPages) + "&R" + xlWorksheet.PrintOptions.Footer.Right.GetText(XLHFOccurrence.EvenPages) + ""); + headerFooter.Append(evenFooter); + + worksheet.Append(sheetProperties); worksheet.Append(sheetDimension); @@ -795,8 +854,10 @@ if (columns != null) worksheet.Append(columns); worksheet.Append(sheetData); if (mergeCells != null) worksheet.Append(mergeCells); + worksheet.Append(printOptions); worksheet.Append(pageMargins); worksheet.Append(pageSetup1); + worksheet.Append(headerFooter); //worksheet.Append(drawing1); worksheetPart.Worksheet = worksheet; diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs index c160f1b..743af71 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheet.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using ClosedXML.Excel.Style; + namespace ClosedXML.Excel { @@ -15,47 +15,20 @@ #endregion - Dictionary cellsCollection = new Dictionary(); - Dictionary rowsCollection = new Dictionary(); - Dictionary columnsCollection = new Dictionary(); - public XLWorksheet(String sheetName) { Style = XLWorkbook.DefaultStyle; - MergedCells = new List(); + Internals = new XLWorksheetInternals(new Dictionary(), new Dictionary(), new Dictionary(), new List()); RowNumber = 1; ColumnNumber = 1; ColumnLetter = "A"; - PrintOptions = new XLPrintOptions(); + PrintOptions = new XLPrintOptions(XLWorkbook.DefaultPrintOptions); this.Name = sheetName; } - public IXLPrintOptions PrintOptions { get; private set; } + public IXLWorksheetInternals Internals { get; private set; } #region IXLRange Members - public List MergedCells { get; private set; } - public Dictionary CellsCollection - { - get { return cellsCollection; } - } - public Dictionary ColumnsCollection - { - get { return columnsCollection; } - } - public Dictionary RowsCollection - { - get { return rowsCollection; } - } - - public IXLAddress FirstCellAddress - { - get { return new XLAddress(1, 1); } - } - - public IXLAddress LastCellAddress - { - get { return new XLAddress(MaxNumberOfRows, MaxNumberOfColumns); } - } public Int32 RowNumber { get; private set; } public Int32 ColumnNumber { get; private set; } @@ -66,11 +39,11 @@ var retVal = new List(); var columnList = new List(); - if (CellsCollection.Count > 0) - columnList.AddRange(CellsCollection.Keys.Select(k => k.Column).Distinct()); + if (Internals.CellsCollection.Count > 0) + columnList.AddRange(Internals.CellsCollection.Keys.Select(k => k.Column).Distinct()); - if (ColumnsCollection.Count > 0) - columnList.AddRange(ColumnsCollection.Keys.Where(c => !columnList.Contains(c))); + if (Internals.ColumnsCollection.Count > 0) + columnList.AddRange(Internals.ColumnsCollection.Keys.Where(c => !columnList.Contains(c))); foreach (var c in columnList) { @@ -104,7 +77,7 @@ get { UpdatingStyle = true; - foreach (var c in cellsCollection.Values) + foreach (var c in Internals.CellsCollection.Values) { yield return c.Style; } @@ -119,21 +92,15 @@ public IXLRow Row(Int32 row) { IXLRow xlRow; - if (rowsCollection.ContainsKey(row)) + if (Internals.RowsCollection.ContainsKey(row)) { - xlRow = rowsCollection[row]; + xlRow = Internals.RowsCollection[row]; } else { - var xlRangeParameters = new XLRangeParameters() - { - CellsCollection = cellsCollection, - MergedCells = this.MergedCells, - DefaultStyle = Style, - PrintArea = this.PrintArea - }; - xlRow = new XLRow(row, xlRangeParameters); - rowsCollection.Add(row, xlRow); + var xlRowParameters = new XLRowParameters(this, Style); + xlRow = new XLRow(row, xlRowParameters); + Internals.RowsCollection.Add(row, xlRow); } return xlRow; @@ -141,21 +108,15 @@ public IXLColumn Column(Int32 column) { IXLColumn xlColumn; - if (columnsCollection.ContainsKey(column)) + if (Internals.ColumnsCollection.ContainsKey(column)) { - xlColumn = columnsCollection[column]; + xlColumn = Internals.ColumnsCollection[column]; } else { - var xlRangeParameters = new XLRangeParameters() - { - CellsCollection = cellsCollection, - MergedCells = this.MergedCells, - DefaultStyle = Style, - PrintArea = this.PrintArea - }; - xlColumn = new XLColumn(column, xlRangeParameters); - columnsCollection.Add(column, xlColumn); + var xlColumnParameters = new XLColumnParameters(this, Style); + xlColumn = new XLColumn(column, xlColumnParameters); + Internals.ColumnsCollection.Add(column, xlColumn); } return xlColumn; @@ -190,5 +151,17 @@ public String Name { get; set; } + + + public IXLPrintOptions PrintOptions { get; private set; } + + + IXLRangeInternals IXLRange.Internals + { + get + { + return new XLRangeInternals(Internals.FirstCellAddress, Internals.LastCellAddress, this); + } + } } } diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheetInternals.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheetInternals.cs new file mode 100644 index 0000000..df6a651 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/XLWorksheetInternals.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public class XLWorksheetInternals: IXLWorksheetInternals + { + public XLWorksheetInternals( + Dictionary cellsCollection , + Dictionary columnsCollection, + Dictionary rowsCollection, + List mergedCells) + { + CellsCollection = cellsCollection; + ColumnsCollection = columnsCollection; + RowsCollection = rowsCollection; + MergedCells = mergedCells; + } + public IXLAddress FirstCellAddress + { + get { return new XLAddress(1, 1); } + } + + public IXLAddress LastCellAddress + { + get { return new XLAddress(XLWorksheet.MaxNumberOfRows, XLWorksheet.MaxNumberOfColumns); } + } + public Dictionary CellsCollection { get; private set; } + public Dictionary ColumnsCollection { get; private set; } + public Dictionary RowsCollection { get; private set; } + public List MergedCells { get; private set; } + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/BasicTable.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/BasicTable.cs index 5f58812..9cf5335 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/BasicTable.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/BasicTable.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using ClosedXML.Excel; -using ClosedXML.Excel.Style; + using System.Drawing; namespace ClosedXML_Examples diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj b/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj index 2af221b..21b5975 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj @@ -53,6 +53,7 @@ + diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Columns/ColumnCollections.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Columns/ColumnCollections.cs index ffe44dc..31b3f13 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Columns/ColumnCollections.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Columns/ColumnCollections.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using ClosedXML.Excel; -using ClosedXML.Excel.Style; + using System.Drawing; namespace ClosedXML_Examples.Columns diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Columns/ColumnSettings.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Columns/ColumnSettings.cs index 118f462..c7dfcda 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Columns/ColumnSettings.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Columns/ColumnSettings.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using ClosedXML.Excel; -using ClosedXML.Excel.Style; + using System.Drawing; namespace ClosedXML_Examples.Columns diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Columns/InsertColumns.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Columns/InsertColumns.cs index 4a71a32..8015ee5 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Columns/InsertColumns.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Columns/InsertColumns.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using ClosedXML.Excel; -using ClosedXML.Excel.Style; + using System.Drawing; namespace ClosedXML_Examples.Columns diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/DataTypes.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/DataTypes.cs index 5c0965d..0935ac8 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/DataTypes.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/DataTypes.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using ClosedXML.Excel; -using ClosedXML.Excel.Style; + using System.Drawing; namespace ClosedXML_Examples.Misc @@ -120,6 +120,11 @@ ws.Cell(ro, co + 1).Style.NumberFormat.Format = "#,##0.00"; ws.Cell(ro, co + 1).DataType = XLCellValues.Text; + ro++; + + ws.Cell(++ro, co).Value = "Blank Text:"; + ws.Cell(ro, co + 1).Value = ""; + workbook.SaveAs(filePath); } diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/MergeCells.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/MergeCells.cs index bdec928..72ebb06 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/MergeCells.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/MergeCells.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using ClosedXML.Excel; -using ClosedXML.Excel.Style; + using System.Drawing; namespace ClosedXML_Examples.Misc diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/MultipleSheets.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/MultipleSheets.cs new file mode 100644 index 0000000..2588d27 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Misc/MultipleSheets.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using ClosedXML.Excel; + +using System.Drawing; + +namespace ClosedXML_Examples.Misc +{ + public class MultipleSheets + { + #region Variables + + // Public + + // Private + + + #endregion + + #region Properties + + // Public + + // Private + + // Override + + + #endregion + + #region Events + + // Public + + // Private + + // Override + + + #endregion + + #region Methods + + // Public + public void Create(String filePath) + { + var workbook = new XLWorkbook(); + foreach (var wsNum in Enumerable.Range(1, 10)) + { + var ws = workbook.Worksheets.Add("New Sheet " + wsNum.ToString()); + } + + workbook.SaveAs(filePath); + } + + // Private + + // Override + + + #endregion + } +} diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Program.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Program.cs index fae14b5..69fe1f6 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Program.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Program.cs @@ -23,6 +23,7 @@ new InsertColumns().Create(@"c:\InsertColumns.xlsx"); new ColumnCollection().Create(@"c:\ColumnCollection.xlsx"); new DataTypes().Create(@"c:\DataTypes.xlsx"); + new MultipleSheets().Create(@"c:\MultipleSheets.xlsx"); } } } \ No newline at end of file diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Rows/InsertRows.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Rows/InsertRows.cs index 349394c..6649207 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Rows/InsertRows.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Rows/InsertRows.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using ClosedXML.Excel; -using ClosedXML.Excel.Style; + using System.Drawing; namespace ClosedXML_Examples.Rows diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Rows/RowSettings.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Rows/RowSettings.cs index 22d0e1f..a7cf9ce 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Rows/RowSettings.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Rows/RowSettings.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using ClosedXML.Excel; -using ClosedXML.Excel.Style; + using System.Drawing; namespace ClosedXML_Examples.Rows diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleAlignment.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleAlignment.cs index ebeb408..96cc49f 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleAlignment.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleAlignment.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using ClosedXML.Excel; -using ClosedXML.Excel.Style; + namespace ClosedXML_Examples.Styles { diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleBorder.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleBorder.cs index b158caa..1b97e40 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleBorder.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleBorder.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using ClosedXML.Excel.Style; + using ClosedXML.Excel; using System.Drawing; diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleFill.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleFill.cs index 9c17307..ecfcebd 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleFill.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleFill.cs @@ -4,7 +4,7 @@ using System.Text; using ClosedXML.Excel; using System.Drawing; -using ClosedXML.Excel.Style; + namespace ClosedXML_Examples.Styles { diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleFont.cs b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleFont.cs index d76638c..6990d5a 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleFont.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/Styles/StyleFont.cs @@ -4,7 +4,7 @@ using System.Text; using ClosedXML.Excel; using System.Drawing; -using ClosedXML.Excel.Style; + namespace ClosedXML_Examples.Styles { diff --git a/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs b/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs index a50c2a7..6f4c9f5 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs +++ b/ClosedXML/ClosedXML/ClosedXML_Sandbox/Program.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using ClosedXML.Excel; -using ClosedXML.Excel.Style; + using System.Drawing; namespace ClosedXML_Sandbox @@ -15,24 +15,29 @@ var wb = new XLWorkbook(); var ws1 = wb.Worksheets.Add("Sheet1"); ws1.PrintOptions.PrintArea = ws1.Range("A1:B2"); - ws1.PrintOptions.PageOrientation = XLPageOrientation.Portrait; + ws1.PrintOptions.PageOrientation = XLPageOrientation.Landscape; + ws1.PrintOptions.AdjustTo(85); var ws2 = wb.Worksheets.Add("Sheet2"); ws2.PrintOptions.PrintArea = ws2.Range("B2:E5"); - ws2.PrintOptions.PageOrientation = XLPageOrientation.Landscape; + ws2.PrintOptions.PageOrientation = XLPageOrientation.Portrait; ws2.PrintOptions.PagesWide = 1; ws2.PrintOptions.PagesTall = 2; - foreach (var wsNum in Enumerable.Range(1, 5)) - { - var ws = wb.Worksheets.Add("New Sheet " + wsNum.ToString()); - foreach (var ro in Enumerable.Range(1, 5)) - { - foreach (var co in Enumerable.Range(1, 5)) - { - ws.Cell(ro, co).Value = "(" + ro + "," + co + ")"; - } - } - } + ws2.PrintOptions.PaperSize = XLPaperSize.MonarchEnvelope; + ws2.PrintOptions.HorizontalDpi = 600; + ws2.PrintOptions.VerticalDpi = 600; + ws2.PrintOptions.FirstPageNumber = 6; + ws2.PrintOptions.CenterHorizontally = true; + ws2.PrintOptions.CenterVertically = true; + ws2.PrintOptions.Margins.Top = 1.5; + var headerFont = new XLFont() { Bold = true }; + ws2.PrintOptions.Header.Left.AddText("Test", XLHFOccurrence.OddPages, headerFont); + ws2.PrintOptions.Header.Left.AddText("Test", XLHFOccurrence.EvenPages, headerFont); + ws2.PrintOptions.Header.Left.AddText("Test", XLHFOccurrence.FirstPage, headerFont); + ws2.PrintOptions.Header.Left.AddText("Test", XLHFOccurrence.AllPages, headerFont); + ws2.PrintOptions.Header.Left.Clear(); + + ws2.PrintOptions.Footer.Center.AddText(XLHFPredefinedText.SheetName, XLHFOccurrence.AllPages, headerFont); //foreach (var c in ws.Range("B2:C3").Columns()) //{