diff --git a/ClosedXML/ClosedXML.sln b/ClosedXML/ClosedXML.sln new file mode 100644 index 0000000..c619cc0 --- /dev/null +++ b/ClosedXML/ClosedXML.sln @@ -0,0 +1,29 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClosedXML", "ClosedXML\ClosedXML.csproj", "{BD5E6BFE-E837-4A35-BCA9-39667D873A20}" +EndProject +Global + GlobalSection(TeamFoundationVersionControl) = preSolution + SccNumberOfProjects = 2 + SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} + SccTeamFoundationServer = https://tfs09.codeplex.com/ + SccLocalPath0 = . + SccProjectUniqueName1 = ClosedXML\\ClosedXML.csproj + SccProjectName1 = ClosedXML + SccLocalPath1 = ClosedXML + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BD5E6BFE-E837-4A35-BCA9-39667D873A20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BD5E6BFE-E837-4A35-BCA9-39667D873A20}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BD5E6BFE-E837-4A35-BCA9-39667D873A20}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BD5E6BFE-E837-4A35-BCA9-39667D873A20}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/ClosedXML/ClosedXML.vssscc b/ClosedXML/ClosedXML.vssscc new file mode 100644 index 0000000..794f014 --- /dev/null +++ b/ClosedXML/ClosedXML.vssscc @@ -0,0 +1,10 @@ +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "" +"NUMBER_OF_EXCLUDED_FILES" = "0" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROJECT" +} diff --git a/ClosedXML/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML/ClosedXML.csproj new file mode 100644 index 0000000..8517855 --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML.csproj @@ -0,0 +1,67 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {BD5E6BFE-E837-4A35-BCA9-39667D873A20} + Library + Properties + ClosedXML + ClosedXML + v4.0 + 512 + SAK + SAK + SAK + SAK + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ClosedXML/ClosedXML/ClosedXML.csproj.vspscc b/ClosedXML/ClosedXML/ClosedXML.csproj.vspscc new file mode 100644 index 0000000..feffdec --- /dev/null +++ b/ClosedXML/ClosedXML/ClosedXML.csproj.vspscc @@ -0,0 +1,10 @@ +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "" +"NUMBER_OF_EXCLUDED_FILES" = "0" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" +} diff --git a/ClosedXML/ClosedXML/Excel/XLCell.cs b/ClosedXML/ClosedXML/Excel/XLCell.cs new file mode 100644 index 0000000..64f25f0 --- /dev/null +++ b/ClosedXML/ClosedXML/Excel/XLCell.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using DocumentFormat.OpenXml.Spreadsheet; + +namespace ClosedXML.Excel +{ + + public class XLCell + { + public XLCellAddress CellAddress { get; private set; } + private XLWorkbook workbook; + public XLCell(XLWorkbook workbook, XLCellAddress cellAddress) + { + this.CellAddress = cellAddress; + this.workbook = workbook; + } + + public XLCell(XLWorkbook workbook, String cellAddressString) + { + this.CellAddress = new XLCellAddress(cellAddressString); + this.workbook = workbook; + } + + public UInt32 Row { get { return CellAddress.Row; } } + public UInt32 Column { get { return CellAddress.Column; } } + public String ColumnLetter { get { return XLWorksheet.ColumnNumberToLetter(this.Column); } } + + public CellValues DataType { get; private set; } + public String InnerValue { get; private set; } + public String Value { + get + { + if (DataType == CellValues.Boolean) + { + return (InnerValue == "1").ToString(); + } + else if (DataType == CellValues.SharedString) + { + return workbook.SharedStrings.GetString(UInt32.Parse(InnerValue)); + } + else if (DataType == CellValues.Date) + { + return GetDateTimeFromSerial(Int32.Parse(InnerValue)).ToString(); + } + else + { + return InnerValue; + } + } + set + { + String val = value; + + Double dTest; + DateTime dtTest; + Boolean bTest; + if (Double.TryParse(val, out dTest)) + { + DataType = CellValues.Number; + } + else if (DateTime.TryParse(val, out dtTest)) + { + DataType = CellValues.Date; + String datePart = GetSerialFromDateTime(dtTest.Day, dtTest.Month, dtTest.Year).ToString(); + val = datePart; + } + else if (Boolean.TryParse(val, out bTest)) + { + DataType = CellValues.Boolean; + val = bTest ? "1" : "0"; + } + else + { + DataType = CellValues.SharedString; + val = workbook.SharedStrings.Add(val).ToString(); + } + InnerValue = val; + HasValue = !value.Equals(String.Empty); + } + } + + public Boolean HasValue { get; private set; } + + private DateTime GetDateTimeFromSerial(Int32 SerialDate) + { + if (SerialDate > 59) SerialDate -= 1; //Excel/Lotus 2/29/1900 bug + return new DateTime(1899, 12, 31).AddDays(SerialDate); + } + + private Int32 GetSerialFromDateTime(Int32 nDay, Int32 nMonth, Int32 nYear) + { + // Excel/Lotus 123 have a bug with 29-02-1900. 1900 is not a + + // leap year, but Excel/Lotus 123 think it is... + + if (nDay == 29 && nMonth == 02 && nYear == 1900) + return 60; + + // DMY to Modified Julian calculatie with an extra substraction of 2415019. + + long nSerialDate = + (int)((1461 * (nYear + 4800 + (int)((nMonth - 14) / 12))) / 4) + + (int)((367 * (nMonth - 2 - 12 * ((nMonth - 14) / 12))) / 12) - + (int)((3 * ((int)((nYear + 4900 + (int)((nMonth - 14) / 12)) / 100))) / 4) + + nDay - 2415019 - 32075; + + if (nSerialDate < 60) + { + // Because of the 29-02-1900 bug, any serial date + + // under 60 is one off... Compensate. + + nSerialDate--; + } + + return (int)nSerialDate; + } + + + } +} diff --git a/ClosedXML/ClosedXML/Excel/XLCellAddress.cs b/ClosedXML/ClosedXML/Excel/XLCellAddress.cs new file mode 100644 index 0000000..5caee90 --- /dev/null +++ b/ClosedXML/ClosedXML/Excel/XLCellAddress.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace ClosedXML.Excel +{ + public struct XLCellAddress : IEqualityComparer, IEquatable, IComparable + { + + public XLCellAddress(UInt32 row, UInt32 column) + { + this.row = row; + this.column = column; + } + + public XLCellAddress(String cellAddressString) + { + Match m = Regex.Match(cellAddressString, @"^([a-zA-Z]+)(\d+)$"); + String columnLetter = m.Groups[1].Value; + this.row = UInt32.Parse(m.Groups[2].Value); + this.column = XLWorksheet.ColumnLetterToNumber(columnLetter); + } + + private UInt32 row; + public UInt32 Row + { + get { return row; } + private set { row = value; } + } + + private UInt32 column; + public UInt32 Column + { + get { return column; } + private set { column = value; } + } + + public static XLCellAddress operator +(XLCellAddress cellAddress1, XLCellAddress cellAddress2) + { + return new XLCellAddress() { Row = cellAddress1.Row + cellAddress2.Row, Column = cellAddress1.Column + cellAddress2.Column }; + } + + public static XLCellAddress operator -(XLCellAddress cellAddress1, XLCellAddress cellAddress2) + { + return new XLCellAddress() { Row = cellAddress1.Row - cellAddress2.Row, Column = cellAddress1.Column - cellAddress2.Column }; + } + + public static Boolean operator ==(XLCellAddress cellAddress1, XLCellAddress cellAddress2) + { + return + cellAddress1.Row == cellAddress2.Row + && cellAddress1.Column == cellAddress2.Column; + } + + public static Boolean operator !=(XLCellAddress cellAddress1, XLCellAddress cellAddress2) + { + return !(cellAddress1 == cellAddress2); + } + + public static Boolean operator >(XLCellAddress cellAddress1, XLCellAddress cellAddress2) + { + return !(cellAddress1 == cellAddress2) + && cellAddress1.Row >= cellAddress2.Row && cellAddress1.Column >= cellAddress2.Column; + } + + public static Boolean operator <(XLCellAddress cellAddress1, XLCellAddress cellAddress2) + { + return !(cellAddress1 == cellAddress2) + && cellAddress1.Row <= cellAddress2.Row && cellAddress1.Column <= cellAddress2.Column; + } + + public static Boolean operator >=(XLCellAddress cellAddress1, XLCellAddress cellAddress2) + { + return + cellAddress1.Row >= cellAddress2.Row + && cellAddress1.Column >= cellAddress2.Column; + } + + public static Boolean operator <=(XLCellAddress cellAddress1, XLCellAddress cellAddress2) + { + return + cellAddress1.Row <= cellAddress2.Row + && cellAddress1.Column <= cellAddress2.Column; + } + + public override String ToString() + { + return XLWorksheet.ColumnNumberToLetter(Column) + Row.ToString(); + } + + #region IEqualityComparer Members + + public Boolean Equals(XLCellAddress x, XLCellAddress y) + { + return x == y; + } + + public Int32 GetHashCode(XLCellAddress obj) + { + return obj.GetHashCode(); + } + + new public Boolean Equals(Object x, Object y) + { + return x == y; + } + + public Int32 GetHashCode(Object obj) + { + return obj.GetHashCode(); + } + + public override Int32 GetHashCode() + { + return this.ToString().GetHashCode(); + } + + #endregion + + #region IEquatable Members + + public Boolean Equals(XLCellAddress other) + { + return this == other; + } + + public override Boolean Equals(Object other) + { + return this == (XLCellAddress)other; + } + + #endregion + + #region IComparable Members + + public Int32 CompareTo(object obj) + { + var other = (XLCellAddress)obj; + if (this == other) + return 0; + else if (this > other) + return 1; + else + return -1; + } + + #endregion + } +} diff --git a/ClosedXML/ClosedXML/Excel/XLCells.cs b/ClosedXML/ClosedXML/Excel/XLCells.cs new file mode 100644 index 0000000..66a4a49 --- /dev/null +++ b/ClosedXML/ClosedXML/Excel/XLCells.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public class XLCells: IEnumerable + { + private Dictionary cells = new Dictionary(); + private XLWorkbook workbook; + public XLCells(XLWorkbook workbook) + { + this.workbook = workbook; + } + + public XLCell this[XLCellAddress cellAddress] + { + get + { + Add(cellAddress); + return cells[cellAddress]; + } + } + + public void Add(XLCellAddress cellAddress) + { + if (!cells.ContainsKey(cellAddress)) + cells.Add(cellAddress, new XLCell(workbook, cellAddress)); + } + + #region IEnumerable Members + + public IEnumerator GetEnumerator() + { + return cells.Values.AsEnumerable().GetEnumerator(); + } + + #endregion + + #region IEnumerable Members + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return this.GetEnumerator(); + } + + #endregion + } +} diff --git a/ClosedXML/ClosedXML/Excel/XLRange.cs b/ClosedXML/ClosedXML/Excel/XLRange.cs new file mode 100644 index 0000000..b6bc1a1 --- /dev/null +++ b/ClosedXML/ClosedXML/Excel/XLRange.cs @@ -0,0 +1,198 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public enum CellContent { All, WithValues } + public class XLRange + { + private XLCell firstCell { get; set; } + public XLCell FirstCell() + { + return FirstCell(CellContent.All); + } + public XLCell FirstCell(CellContent cellContent) + { + if (cellContent == CellContent.WithValues) + { + var cellsWithValues = Cells(cellContent); + var minAddress = cellsWithValues.Min(c => c.CellAddress); + return new XLCell(this.workbook, minAddress); + } + else + { + return firstCell; + } + } + + private XLCell lastCell { get; set; } + public XLCell LastCell() + { + return LastCell(CellContent.All); + } + public XLCell LastCell(CellContent cellContent) + { + if (cellContent == CellContent.WithValues) + { + var cellsWithValues = Cells(cellContent); + var maxAddress = cellsWithValues.Max(c => c.CellAddress); + return new XLCell(this.workbook, maxAddress); + } + else + { + return lastCell; + } + } + + private XLCells cellData; + public XLRange ParentRange { get; private set; } + protected XLWorkbook workbook; + + internal XLRange(XLCell firstCell, XLCell lastCell, XLCells cellData, XLRange parentRange) + { + this.cellData = cellData; + this.firstCell = firstCell; + this.lastCell = lastCell; + this.ParentRange = parentRange; + this.workbook = parentRange == null ? null : parentRange.workbook; + } + + public XLCell Cell(UInt32 row, String column) + { + return Cell(column + row.ToString()); + } + + public XLCell Cell(UInt32 row, UInt32 column) + { + XLCellAddress cellAddress = new XLCellAddress(row-1, column-1) + firstCell.CellAddress; + return cellData[cellAddress]; + } + + public XLCell Cell(String cellAddressString) + { + XLCellAddress cellAddress = new XLCellAddress(cellAddressString); + return cellData[cellAddress]; + } + + public XLRange Range(XLCell firstCell, XLCell lastCell) + { + return new XLRange(firstCell, lastCell, cellData, this); + } + + public XLRange Range(String range) + { + String[] ranges = range.Split(':'); + XLCell firstCell = new XLCell(workbook, ranges[0] ); + XLCell lastCell = new XLCell(workbook, ranges[1] ); + return Range(firstCell, lastCell); + } + + public Boolean HasData { get { return cellData.Any(); } } + + + public UInt32 CellCount() + { + return CellCount(CellContent.All); + } + public UInt32 CellCount(CellContent cellContent) + { + return (UInt32)Cells(cellContent).Count; + } + + public UInt32 Row { get { return firstCell.Row; } } + public List Rows() + { + return Rows(CellContent.All); + } + public List Rows(CellContent cellContent) + { + if (cellContent == CellContent.WithValues) + { + var cellsWithValues = Cells(CellContent.WithValues); + var distinct = cellsWithValues.Select(c => c.Row).Distinct(); + var rows = from d in distinct + select new XLRange( + new XLCell(workbook, new XLCellAddress(d, 1)) + , new XLCell(workbook, new XLCellAddress(d, XLWorksheet.MaxNumberOfColumns)) + , cellData, this); + return rows.ToList(); + } + else + { + var distinct = Cells().Select(c => c.Row).Distinct(); + var rows = from d in distinct + select new XLRange( + new XLCell(workbook, new XLCellAddress(d, 1)) + , new XLCell(workbook, new XLCellAddress(d, XLWorksheet.MaxNumberOfColumns)) + , cellData, this); + return rows.ToList(); + } + } + public UInt32 RowCount() + { + return RowCount(CellContent.All); + } + public UInt32 RowCount(CellContent cellContent) + { + if (cellContent == CellContent.WithValues) + { + var cellsWithValues = Cells(CellContent.WithValues); + var distinct = cellsWithValues.Select(c => c.Row).Distinct(); + return (UInt32)(distinct.Count()); + } + else + { + return (lastCell.CellAddress - firstCell.CellAddress).Row + 1; + } + } + + public UInt32 Column { get { return firstCell.Column; } } + public UInt32 ColumnCount() + { + return ColumnCount(CellContent.All); + } + public UInt32 ColumnCount(CellContent cellContent) + { + if (cellContent == CellContent.WithValues) + { + var cellsWithValues = Cells(CellContent.WithValues); + var distinct = cellsWithValues.Select(c => c.Column).Distinct(); + return (UInt32)(distinct.Count()); + } + else + { + return (lastCell.CellAddress - firstCell.CellAddress).Column + 1; + } + } + + public virtual List Cells() + { + return Cells(CellContent.All); + } + + public virtual List Cells(CellContent cellContent) + { + if (cellContent == CellContent.WithValues) + { + return cellData + .Where(c => c.HasValue && c.CellAddress >= this.firstCell.CellAddress && c.CellAddress <= lastCell.CellAddress) + .OrderBy(x => x.CellAddress) + .ToList(); + } + else + { + List retVal = new List(); + for (UInt32 row = firstCell.Row; row <= lastCell.Row; row++) + { + for (UInt32 column = firstCell.Column; column <= lastCell.Column; column++) + { + retVal.Add(Cell(row, column)); + } + } + return retVal; + } + } + } +} diff --git a/ClosedXML/ClosedXML/Excel/XLSharedStrings.cs b/ClosedXML/ClosedXML/Excel/XLSharedStrings.cs new file mode 100644 index 0000000..57e3cef --- /dev/null +++ b/ClosedXML/ClosedXML/Excel/XLSharedStrings.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public class XLSharedStrings: IEnumerable + { + internal class SharedStringInfo + { + public UInt32 Position { get; set; } + public UInt32 Count { get; set; } + } + + private Dictionary sharedStrings = new Dictionary(); + + private UInt32 lastPosition = 0; + public UInt32 Add(String sharedString) + { + SharedStringInfo stringInfo; + if(sharedStrings.ContainsKey(sharedString)) + { + stringInfo = sharedStrings[sharedString]; + stringInfo.Count++; + } + else + { + stringInfo = new SharedStringInfo() { Position = lastPosition, Count = 1 }; + sharedStrings.Add(sharedString, stringInfo); + lastPosition++; + } + return stringInfo.Position; + } + + public String GetString(UInt32 position) + { + return sharedStrings.Where(s => s.Value.Position == position).Single().Key; + } + + public UInt32 Count + { + get { return (UInt32)sharedStrings.Count; } + } + + #region IEnumerable Members + + public IEnumerator GetEnumerator() + { + return sharedStrings.Keys.GetEnumerator(); + } + + #endregion + + #region IEnumerable Members + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + #endregion + } +} diff --git a/ClosedXML/ClosedXML/Excel/XLWorkbook.cs b/ClosedXML/ClosedXML/Excel/XLWorkbook.cs new file mode 100644 index 0000000..9965123 --- /dev/null +++ b/ClosedXML/ClosedXML/Excel/XLWorkbook.cs @@ -0,0 +1,929 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using DocumentFormat.OpenXml.Packaging; +using Ap = DocumentFormat.OpenXml.ExtendedProperties; +using Vt = DocumentFormat.OpenXml.VariantTypes; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Spreadsheet; +using A = DocumentFormat.OpenXml.Drawing; + + +namespace ClosedXML.Excel +{ + public class XLWorkbook + { + public XLWorksheets Worksheets; + public XLSharedStrings SharedStrings = new XLSharedStrings(); + + public XLWorkbook(String file) + { + FileInfo fi = new FileInfo(file); + workbookName = fi.Name; + workbookFullName = fi.FullName; + Worksheets = new XLWorksheets(this); + } + + private String workbookName; + public String Name + { + get { return workbookName; } + } + + private String workbookFullName; + public String FullName + { + get { return workbookFullName; } + } + + public void Save() + { + if (File.Exists(FullName)) File.Delete(FullName); + + using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(FullName, SpreadsheetDocumentType.Workbook)) + { + CreateParts(spreadsheetDocument); + } + } + + #region CreateParts + // Adds child parts and generates content of the specified part. + private void CreateParts(SpreadsheetDocument document) + { + ExtendedFilePropertiesPart extendedFilePropertiesPart = document.AddNewPart("rId1"); + GenerateExtendedFilePropertiesPart1Content(extendedFilePropertiesPart); + + WorkbookPart workbookPart1 = document.AddWorkbookPart(); + GenerateWorkbookPart1Content(workbookPart1); + + UInt32Value sheetId = 0; + foreach (var worksheet in Worksheets) + { + sheetId++; + WorksheetPart worksheetPart1 = workbookPart1.AddNewPart("rId" + sheetId.ToString()); + GenerateWorksheetPart3Content(worksheetPart1, worksheet); + } + + SharedStringTablePart sharedStringTablePart1 = workbookPart1.AddNewPart(); + GenerateSharedStringTablePart1Content(sharedStringTablePart1); + + WorkbookStylesPart workbookStylesPart1 = workbookPart1.AddNewPart(); + GenerateWorkbookStylesPart1Content(workbookStylesPart1); + + ThemePart themePart1 = workbookPart1.AddNewPart(); + GenerateThemePart1Content(themePart1); + + SetPackageProperties(document); + } + + // Generates content of extendedFilePropertiesPart1. + private void GenerateExtendedFilePropertiesPart1Content(ExtendedFilePropertiesPart extendedFilePropertiesPart1) + { + Ap.Properties properties1 = new Ap.Properties(); + properties1.AddNamespaceDeclaration("vt", "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"); + Ap.Application application1 = new Ap.Application(); + application1.Text = "Microsoft Excel"; + Ap.DocumentSecurity documentSecurity1 = new Ap.DocumentSecurity(); + documentSecurity1.Text = "0"; + Ap.ScaleCrop scaleCrop1 = new Ap.ScaleCrop(); + scaleCrop1.Text = "false"; + + Ap.HeadingPairs headingPairs1 = new Ap.HeadingPairs(); + + Vt.VTVector vTVector1 = new Vt.VTVector() { BaseType = Vt.VectorBaseValues.Variant, Size = (UInt32Value)2U }; + + Vt.Variant variant1 = new Vt.Variant(); + Vt.VTLPSTR vTLPSTR1 = new Vt.VTLPSTR(); + vTLPSTR1.Text = "Worksheets"; + + variant1.Append(vTLPSTR1); + + Vt.Variant variant2 = new Vt.Variant(); + Vt.VTInt32 vTInt321 = new Vt.VTInt32(); + vTInt321.Text = Worksheets.Count.ToString(); + + variant2.Append(vTInt321); + + vTVector1.Append(variant1); + vTVector1.Append(variant2); + + headingPairs1.Append(vTVector1); + + Ap.TitlesOfParts titlesOfParts1 = new Ap.TitlesOfParts(); + + Vt.VTVector vTVector2 = new Vt.VTVector() { BaseType = Vt.VectorBaseValues.Lpstr, Size = (UInt32Value)Worksheets.Count }; + foreach (var sheet in Worksheets) + { + Vt.VTLPSTR vTLPSTR = new Vt.VTLPSTR(); + vTLPSTR.Text = sheet.Name; + vTVector2.Append(vTLPSTR); + } + + + titlesOfParts1.Append(vTVector2); + Ap.LinksUpToDate linksUpToDate1 = new Ap.LinksUpToDate(); + linksUpToDate1.Text = "false"; + Ap.SharedDocument sharedDocument1 = new Ap.SharedDocument(); + sharedDocument1.Text = "false"; + Ap.HyperlinksChanged hyperlinksChanged1 = new Ap.HyperlinksChanged(); + hyperlinksChanged1.Text = "false"; + Ap.ApplicationVersion applicationVersion1 = new Ap.ApplicationVersion(); + applicationVersion1.Text = "12.0000"; + + properties1.Append(application1); + properties1.Append(documentSecurity1); + properties1.Append(scaleCrop1); + properties1.Append(headingPairs1); + properties1.Append(titlesOfParts1); + properties1.Append(linksUpToDate1); + properties1.Append(sharedDocument1); + properties1.Append(hyperlinksChanged1); + properties1.Append(applicationVersion1); + + extendedFilePropertiesPart1.Properties = properties1; + } + + + // Generates content of workbookPart1. + private void GenerateWorkbookPart1Content(WorkbookPart workbookPart1) + { + Workbook workbook1 = new Workbook(); + workbook1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); + FileVersion fileVersion1 = new FileVersion() { ApplicationName = "xl", LastEdited = "5", LowestEdited = "5", BuildVersion = "9114" }; + WorkbookProperties workbookProperties1 = new WorkbookProperties() { DefaultThemeVersion = (UInt32Value)124226U }; + + BookViews bookViews1 = new BookViews(); + WorkbookView workbookView1 = new WorkbookView() { XWindow = 360, YWindow = 45, WindowWidth = (UInt32Value)14355U, WindowHeight = (UInt32Value)8250U }; + + bookViews1.Append(workbookView1); + + UInt32 sheetCount = 0; + Sheets sheets1 = new Sheets(); + foreach (var worksheet in Worksheets) + { + sheetCount++; + Sheet sheet = new Sheet() { Name = worksheet.Name, SheetId = (UInt32Value)sheetCount, Id = "rId" + sheetCount.ToString() }; + sheets1.Append(sheet); + } + + CalculationProperties calculationProperties1 = new CalculationProperties() { CalculationId = (UInt32Value)144315U, ReferenceMode = ReferenceModeValues.R1C1 }; + + workbook1.Append(fileVersion1); + workbook1.Append(workbookProperties1); + workbook1.Append(bookViews1); + workbook1.Append(sheets1); + workbook1.Append(calculationProperties1); + + workbookPart1.Workbook = workbook1; + } + + // Generates content of worksheetPart3. + private void GenerateWorksheetPart3Content(WorksheetPart worksheetPart3, XLWorksheet worksheet) + { + Worksheet worksheet3 = new Worksheet(); + worksheet3.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); + SheetDimension sheetDimension3 = new SheetDimension() { Reference = "A1" }; + + SheetViews sheetViews3 = new SheetViews(); + + SheetView sheetView3; + if (worksheet.Name != "SheetName1") + { + sheetView3 = new SheetView() { WorkbookViewId = (UInt32Value)0U }; + } + else + { + sheetView3 = new SheetView() { TabSelected = true, WorkbookViewId = (UInt32Value)0U }; + } + + sheetViews3.Append(sheetView3); + SheetFormatProperties sheetFormatProperties3 = new SheetFormatProperties() { DefaultRowHeight = 15D, DyDescent = 0.25D }; + + SheetData sheetData3 = new SheetData(); + + #region Insert Rows/Cells + if (worksheet.HasData) + { + foreach (var xlRow in worksheet.Rows(CellContent.WithValues)) + { + Row row = new Row() { RowIndex = (UInt32Value)xlRow.Row, Spans = new ListValue() { InnerText = xlRow.Column.ToString() + ":" + xlRow.LastCell(CellContent.WithValues).Column }, DyDescent = 0.25D }; + foreach (var xlCell in xlRow.Cells(CellContent.WithValues)) + { + Cell cell; + String address = xlCell.CellAddress.ToString(); + if (xlCell.DataType == CellValues.Date) + cell = new Cell() { CellReference = address, StyleIndex = (UInt32Value)1U }; + else if (xlCell.DataType == CellValues.SharedString) + cell = new Cell() { CellReference = address, DataType = CellValues.SharedString }; + else if (xlCell.DataType == CellValues.Boolean) + cell = new Cell() { CellReference = address, DataType = CellValues.Boolean }; + else + cell = new Cell() { CellReference = address }; + + CellValue cellValue = new CellValue(); + cellValue.Text = xlCell.InnerValue; + + cell.Append(cellValue); + row.Append(cell); + } + + sheetData3.Append(row); + } + } + #endregion + + PageMargins pageMargins3 = new PageMargins() { Left = 0.7D, Right = 0.7D, Top = 0.75D, Bottom = 0.75D, Header = 0.3D, Footer = 0.3D }; + + worksheet3.Append(sheetDimension3); + worksheet3.Append(sheetViews3); + worksheet3.Append(sheetFormatProperties3); + worksheet3.Append(sheetData3); + worksheet3.Append(pageMargins3); + + worksheetPart3.Worksheet = worksheet3; + } + + + + // Generates content of sharedStringTablePart1. + private void GenerateSharedStringTablePart1Content(SharedStringTablePart sharedStringTablePart1) + { + SharedStringTable sharedStringTable = new SharedStringTable() { Count = (UInt32Value)SharedStrings.Count, UniqueCount = (UInt32Value)SharedStrings.Count }; + + foreach (String sharedString in SharedStrings) + { + SharedStringItem sharedStringItem = new SharedStringItem(); + Text text = new Text(); + text.Text = sharedString; + sharedStringItem.Append(text); + sharedStringTable.Append(sharedStringItem); + } + + sharedStringTablePart1.SharedStringTable = sharedStringTable; + } + + // Generates content of workbookStylesPart1. + private void GenerateWorkbookStylesPart1Content(WorkbookStylesPart workbookStylesPart1) + { + Stylesheet stylesheet1 = new Stylesheet(); + + Fonts fonts1 = new Fonts() { Count = (UInt32Value)1U }; + + Font font1 = new Font(); + FontSize fontSize1 = new FontSize() { Val = 11D }; + Color color1 = new Color() { Theme = (UInt32Value)1U }; + FontName fontName1 = new FontName() { Val = "Calibri" }; + FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering() { Val = 2 }; + FontScheme fontScheme1 = new FontScheme() { Val = FontSchemeValues.Minor }; + + font1.Append(fontSize1); + font1.Append(color1); + font1.Append(fontName1); + font1.Append(fontFamilyNumbering1); + font1.Append(fontScheme1); + + fonts1.Append(font1); + + Fills fills1 = new Fills() { Count = (UInt32Value)2U }; + + Fill fill1 = new Fill(); + PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; + + fill1.Append(patternFill1); + + Fill fill2 = new Fill(); + PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; + + fill2.Append(patternFill2); + + fills1.Append(fill1); + fills1.Append(fill2); + + Borders borders1 = new Borders() { Count = (UInt32Value)1U }; + + Border border1 = new Border(); + LeftBorder leftBorder1 = new LeftBorder(); + RightBorder rightBorder1 = new RightBorder(); + TopBorder topBorder1 = new TopBorder(); + BottomBorder bottomBorder1 = new BottomBorder(); + DiagonalBorder diagonalBorder1 = new DiagonalBorder(); + + border1.Append(leftBorder1); + border1.Append(rightBorder1); + border1.Append(topBorder1); + border1.Append(bottomBorder1); + border1.Append(diagonalBorder1); + + borders1.Append(border1); + + CellStyleFormats cellStyleFormats1 = new CellStyleFormats() { Count = (UInt32Value)1U }; + CellFormat cellFormat1 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U }; + + cellStyleFormats1.Append(cellFormat1); + + CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)2U }; + CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; + CellFormat cellFormat3 = new CellFormat() { NumberFormatId = (UInt32Value)14U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true }; + + cellFormats1.Append(cellFormat2); + cellFormats1.Append(cellFormat3); + + CellStyles cellStyles1 = new CellStyles() { Count = (UInt32Value)1U }; + CellStyle cellStyle1 = new CellStyle() { Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U }; + + cellStyles1.Append(cellStyle1); + DifferentialFormats differentialFormats1 = new DifferentialFormats() { Count = (UInt32Value)0U }; + TableStyles tableStyles1 = new TableStyles() { Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium9", DefaultPivotStyle = "PivotStyleLight16" }; + + stylesheet1.Append(fonts1); + stylesheet1.Append(fills1); + stylesheet1.Append(borders1); + stylesheet1.Append(cellStyleFormats1); + stylesheet1.Append(cellFormats1); + stylesheet1.Append(cellStyles1); + stylesheet1.Append(differentialFormats1); + stylesheet1.Append(tableStyles1); + + workbookStylesPart1.Stylesheet = stylesheet1; + } + + // Generates content of themePart1. + private void GenerateThemePart1Content(ThemePart themePart1) + { + A.Theme theme1 = new A.Theme() { Name = "Office Theme" }; + theme1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main"); + + A.ThemeElements themeElements1 = new A.ThemeElements(); + + A.ColorScheme colorScheme1 = new A.ColorScheme() { Name = "Office" }; + + A.Dark1Color dark1Color1 = new A.Dark1Color(); + A.SystemColor systemColor1 = new A.SystemColor() { Val = A.SystemColorValues.WindowText, LastColor = "000000" }; + + dark1Color1.Append(systemColor1); + + A.Light1Color light1Color1 = new A.Light1Color(); + A.SystemColor systemColor2 = new A.SystemColor() { Val = A.SystemColorValues.Window, LastColor = "FFFFFF" }; + + light1Color1.Append(systemColor2); + + A.Dark2Color dark2Color1 = new A.Dark2Color(); + A.RgbColorModelHex rgbColorModelHex1 = new A.RgbColorModelHex() { Val = "1F497D" }; + + dark2Color1.Append(rgbColorModelHex1); + + A.Light2Color light2Color1 = new A.Light2Color(); + A.RgbColorModelHex rgbColorModelHex2 = new A.RgbColorModelHex() { Val = "EEECE1" }; + + light2Color1.Append(rgbColorModelHex2); + + A.Accent1Color accent1Color1 = new A.Accent1Color(); + A.RgbColorModelHex rgbColorModelHex3 = new A.RgbColorModelHex() { Val = "4F81BD" }; + + accent1Color1.Append(rgbColorModelHex3); + + A.Accent2Color accent2Color1 = new A.Accent2Color(); + A.RgbColorModelHex rgbColorModelHex4 = new A.RgbColorModelHex() { Val = "C0504D" }; + + accent2Color1.Append(rgbColorModelHex4); + + A.Accent3Color accent3Color1 = new A.Accent3Color(); + A.RgbColorModelHex rgbColorModelHex5 = new A.RgbColorModelHex() { Val = "9BBB59" }; + + accent3Color1.Append(rgbColorModelHex5); + + A.Accent4Color accent4Color1 = new A.Accent4Color(); + A.RgbColorModelHex rgbColorModelHex6 = new A.RgbColorModelHex() { Val = "8064A2" }; + + accent4Color1.Append(rgbColorModelHex6); + + A.Accent5Color accent5Color1 = new A.Accent5Color(); + A.RgbColorModelHex rgbColorModelHex7 = new A.RgbColorModelHex() { Val = "4BACC6" }; + + accent5Color1.Append(rgbColorModelHex7); + + A.Accent6Color accent6Color1 = new A.Accent6Color(); + A.RgbColorModelHex rgbColorModelHex8 = new A.RgbColorModelHex() { Val = "F79646" }; + + accent6Color1.Append(rgbColorModelHex8); + + A.Hyperlink hyperlink1 = new A.Hyperlink(); + A.RgbColorModelHex rgbColorModelHex9 = new A.RgbColorModelHex() { Val = "0000FF" }; + + hyperlink1.Append(rgbColorModelHex9); + + A.FollowedHyperlinkColor followedHyperlinkColor1 = new A.FollowedHyperlinkColor(); + A.RgbColorModelHex rgbColorModelHex10 = new A.RgbColorModelHex() { Val = "800080" }; + + followedHyperlinkColor1.Append(rgbColorModelHex10); + + colorScheme1.Append(dark1Color1); + colorScheme1.Append(light1Color1); + colorScheme1.Append(dark2Color1); + colorScheme1.Append(light2Color1); + colorScheme1.Append(accent1Color1); + colorScheme1.Append(accent2Color1); + colorScheme1.Append(accent3Color1); + colorScheme1.Append(accent4Color1); + colorScheme1.Append(accent5Color1); + colorScheme1.Append(accent6Color1); + colorScheme1.Append(hyperlink1); + colorScheme1.Append(followedHyperlinkColor1); + + A.FontScheme fontScheme2 = new A.FontScheme() { Name = "Office" }; + + A.MajorFont majorFont1 = new A.MajorFont(); + A.LatinFont latinFont1 = new A.LatinFont() { Typeface = "Cambria" }; + A.EastAsianFont eastAsianFont1 = new A.EastAsianFont() { Typeface = "" }; + A.ComplexScriptFont complexScriptFont1 = new A.ComplexScriptFont() { Typeface = "" }; + A.SupplementalFont supplementalFont1 = new A.SupplementalFont() { Script = "Jpan", Typeface = "MS Pゴシック" }; + A.SupplementalFont supplementalFont2 = new A.SupplementalFont() { Script = "Hang", Typeface = "맑은 고딕" }; + A.SupplementalFont supplementalFont3 = new A.SupplementalFont() { Script = "Hans", Typeface = "宋体" }; + A.SupplementalFont supplementalFont4 = new A.SupplementalFont() { Script = "Hant", Typeface = "新細明體" }; + A.SupplementalFont supplementalFont5 = new A.SupplementalFont() { Script = "Arab", Typeface = "Times New Roman" }; + A.SupplementalFont supplementalFont6 = new A.SupplementalFont() { Script = "Hebr", Typeface = "Times New Roman" }; + A.SupplementalFont supplementalFont7 = new A.SupplementalFont() { Script = "Thai", Typeface = "Tahoma" }; + A.SupplementalFont supplementalFont8 = new A.SupplementalFont() { Script = "Ethi", Typeface = "Nyala" }; + A.SupplementalFont supplementalFont9 = new A.SupplementalFont() { Script = "Beng", Typeface = "Vrinda" }; + A.SupplementalFont supplementalFont10 = new A.SupplementalFont() { Script = "Gujr", Typeface = "Shruti" }; + A.SupplementalFont supplementalFont11 = new A.SupplementalFont() { Script = "Khmr", Typeface = "MoolBoran" }; + A.SupplementalFont supplementalFont12 = new A.SupplementalFont() { Script = "Knda", Typeface = "Tunga" }; + A.SupplementalFont supplementalFont13 = new A.SupplementalFont() { Script = "Guru", Typeface = "Raavi" }; + A.SupplementalFont supplementalFont14 = new A.SupplementalFont() { Script = "Cans", Typeface = "Euphemia" }; + A.SupplementalFont supplementalFont15 = new A.SupplementalFont() { Script = "Cher", Typeface = "Plantagenet Cherokee" }; + A.SupplementalFont supplementalFont16 = new A.SupplementalFont() { Script = "Yiii", Typeface = "Microsoft Yi Baiti" }; + A.SupplementalFont supplementalFont17 = new A.SupplementalFont() { Script = "Tibt", Typeface = "Microsoft Himalaya" }; + A.SupplementalFont supplementalFont18 = new A.SupplementalFont() { Script = "Thaa", Typeface = "MV Boli" }; + A.SupplementalFont supplementalFont19 = new A.SupplementalFont() { Script = "Deva", Typeface = "Mangal" }; + A.SupplementalFont supplementalFont20 = new A.SupplementalFont() { Script = "Telu", Typeface = "Gautami" }; + A.SupplementalFont supplementalFont21 = new A.SupplementalFont() { Script = "Taml", Typeface = "Latha" }; + A.SupplementalFont supplementalFont22 = new A.SupplementalFont() { Script = "Syrc", Typeface = "Estrangelo Edessa" }; + A.SupplementalFont supplementalFont23 = new A.SupplementalFont() { Script = "Orya", Typeface = "Kalinga" }; + A.SupplementalFont supplementalFont24 = new A.SupplementalFont() { Script = "Mlym", Typeface = "Kartika" }; + A.SupplementalFont supplementalFont25 = new A.SupplementalFont() { Script = "Laoo", Typeface = "DokChampa" }; + A.SupplementalFont supplementalFont26 = new A.SupplementalFont() { Script = "Sinh", Typeface = "Iskoola Pota" }; + A.SupplementalFont supplementalFont27 = new A.SupplementalFont() { Script = "Mong", Typeface = "Mongolian Baiti" }; + A.SupplementalFont supplementalFont28 = new A.SupplementalFont() { Script = "Viet", Typeface = "Times New Roman" }; + A.SupplementalFont supplementalFont29 = new A.SupplementalFont() { Script = "Uigh", Typeface = "Microsoft Uighur" }; + + majorFont1.Append(latinFont1); + majorFont1.Append(eastAsianFont1); + majorFont1.Append(complexScriptFont1); + majorFont1.Append(supplementalFont1); + majorFont1.Append(supplementalFont2); + majorFont1.Append(supplementalFont3); + majorFont1.Append(supplementalFont4); + majorFont1.Append(supplementalFont5); + majorFont1.Append(supplementalFont6); + majorFont1.Append(supplementalFont7); + majorFont1.Append(supplementalFont8); + majorFont1.Append(supplementalFont9); + majorFont1.Append(supplementalFont10); + majorFont1.Append(supplementalFont11); + majorFont1.Append(supplementalFont12); + majorFont1.Append(supplementalFont13); + majorFont1.Append(supplementalFont14); + majorFont1.Append(supplementalFont15); + majorFont1.Append(supplementalFont16); + majorFont1.Append(supplementalFont17); + majorFont1.Append(supplementalFont18); + majorFont1.Append(supplementalFont19); + majorFont1.Append(supplementalFont20); + majorFont1.Append(supplementalFont21); + majorFont1.Append(supplementalFont22); + majorFont1.Append(supplementalFont23); + majorFont1.Append(supplementalFont24); + majorFont1.Append(supplementalFont25); + majorFont1.Append(supplementalFont26); + majorFont1.Append(supplementalFont27); + majorFont1.Append(supplementalFont28); + majorFont1.Append(supplementalFont29); + + A.MinorFont minorFont1 = new A.MinorFont(); + A.LatinFont latinFont2 = new A.LatinFont() { Typeface = "Calibri" }; + A.EastAsianFont eastAsianFont2 = new A.EastAsianFont() { Typeface = "" }; + A.ComplexScriptFont complexScriptFont2 = new A.ComplexScriptFont() { Typeface = "" }; + A.SupplementalFont supplementalFont30 = new A.SupplementalFont() { Script = "Jpan", Typeface = "MS Pゴシック" }; + A.SupplementalFont supplementalFont31 = new A.SupplementalFont() { Script = "Hang", Typeface = "맑은 고딕" }; + A.SupplementalFont supplementalFont32 = new A.SupplementalFont() { Script = "Hans", Typeface = "宋体" }; + A.SupplementalFont supplementalFont33 = new A.SupplementalFont() { Script = "Hant", Typeface = "新細明體" }; + A.SupplementalFont supplementalFont34 = new A.SupplementalFont() { Script = "Arab", Typeface = "Arial" }; + A.SupplementalFont supplementalFont35 = new A.SupplementalFont() { Script = "Hebr", Typeface = "Arial" }; + A.SupplementalFont supplementalFont36 = new A.SupplementalFont() { Script = "Thai", Typeface = "Tahoma" }; + A.SupplementalFont supplementalFont37 = new A.SupplementalFont() { Script = "Ethi", Typeface = "Nyala" }; + A.SupplementalFont supplementalFont38 = new A.SupplementalFont() { Script = "Beng", Typeface = "Vrinda" }; + A.SupplementalFont supplementalFont39 = new A.SupplementalFont() { Script = "Gujr", Typeface = "Shruti" }; + A.SupplementalFont supplementalFont40 = new A.SupplementalFont() { Script = "Khmr", Typeface = "DaunPenh" }; + A.SupplementalFont supplementalFont41 = new A.SupplementalFont() { Script = "Knda", Typeface = "Tunga" }; + A.SupplementalFont supplementalFont42 = new A.SupplementalFont() { Script = "Guru", Typeface = "Raavi" }; + A.SupplementalFont supplementalFont43 = new A.SupplementalFont() { Script = "Cans", Typeface = "Euphemia" }; + A.SupplementalFont supplementalFont44 = new A.SupplementalFont() { Script = "Cher", Typeface = "Plantagenet Cherokee" }; + A.SupplementalFont supplementalFont45 = new A.SupplementalFont() { Script = "Yiii", Typeface = "Microsoft Yi Baiti" }; + A.SupplementalFont supplementalFont46 = new A.SupplementalFont() { Script = "Tibt", Typeface = "Microsoft Himalaya" }; + A.SupplementalFont supplementalFont47 = new A.SupplementalFont() { Script = "Thaa", Typeface = "MV Boli" }; + A.SupplementalFont supplementalFont48 = new A.SupplementalFont() { Script = "Deva", Typeface = "Mangal" }; + A.SupplementalFont supplementalFont49 = new A.SupplementalFont() { Script = "Telu", Typeface = "Gautami" }; + A.SupplementalFont supplementalFont50 = new A.SupplementalFont() { Script = "Taml", Typeface = "Latha" }; + A.SupplementalFont supplementalFont51 = new A.SupplementalFont() { Script = "Syrc", Typeface = "Estrangelo Edessa" }; + A.SupplementalFont supplementalFont52 = new A.SupplementalFont() { Script = "Orya", Typeface = "Kalinga" }; + A.SupplementalFont supplementalFont53 = new A.SupplementalFont() { Script = "Mlym", Typeface = "Kartika" }; + A.SupplementalFont supplementalFont54 = new A.SupplementalFont() { Script = "Laoo", Typeface = "DokChampa" }; + A.SupplementalFont supplementalFont55 = new A.SupplementalFont() { Script = "Sinh", Typeface = "Iskoola Pota" }; + A.SupplementalFont supplementalFont56 = new A.SupplementalFont() { Script = "Mong", Typeface = "Mongolian Baiti" }; + A.SupplementalFont supplementalFont57 = new A.SupplementalFont() { Script = "Viet", Typeface = "Arial" }; + A.SupplementalFont supplementalFont58 = new A.SupplementalFont() { Script = "Uigh", Typeface = "Microsoft Uighur" }; + + minorFont1.Append(latinFont2); + minorFont1.Append(eastAsianFont2); + minorFont1.Append(complexScriptFont2); + minorFont1.Append(supplementalFont30); + minorFont1.Append(supplementalFont31); + minorFont1.Append(supplementalFont32); + minorFont1.Append(supplementalFont33); + minorFont1.Append(supplementalFont34); + minorFont1.Append(supplementalFont35); + minorFont1.Append(supplementalFont36); + minorFont1.Append(supplementalFont37); + minorFont1.Append(supplementalFont38); + minorFont1.Append(supplementalFont39); + minorFont1.Append(supplementalFont40); + minorFont1.Append(supplementalFont41); + minorFont1.Append(supplementalFont42); + minorFont1.Append(supplementalFont43); + minorFont1.Append(supplementalFont44); + minorFont1.Append(supplementalFont45); + minorFont1.Append(supplementalFont46); + minorFont1.Append(supplementalFont47); + minorFont1.Append(supplementalFont48); + minorFont1.Append(supplementalFont49); + minorFont1.Append(supplementalFont50); + minorFont1.Append(supplementalFont51); + minorFont1.Append(supplementalFont52); + minorFont1.Append(supplementalFont53); + minorFont1.Append(supplementalFont54); + minorFont1.Append(supplementalFont55); + minorFont1.Append(supplementalFont56); + minorFont1.Append(supplementalFont57); + minorFont1.Append(supplementalFont58); + + fontScheme2.Append(majorFont1); + fontScheme2.Append(minorFont1); + + A.FormatScheme formatScheme1 = new A.FormatScheme() { Name = "Office" }; + + A.FillStyleList fillStyleList1 = new A.FillStyleList(); + + A.SolidFill solidFill1 = new A.SolidFill(); + A.SchemeColor schemeColor1 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + + solidFill1.Append(schemeColor1); + + A.GradientFill gradientFill1 = new A.GradientFill() { RotateWithShape = true }; + + A.GradientStopList gradientStopList1 = new A.GradientStopList(); + + A.GradientStop gradientStop1 = new A.GradientStop() { Position = 0 }; + + A.SchemeColor schemeColor2 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + A.Tint tint1 = new A.Tint() { Val = 50000 }; + A.SaturationModulation saturationModulation1 = new A.SaturationModulation() { Val = 300000 }; + + schemeColor2.Append(tint1); + schemeColor2.Append(saturationModulation1); + + gradientStop1.Append(schemeColor2); + + A.GradientStop gradientStop2 = new A.GradientStop() { Position = 35000 }; + + A.SchemeColor schemeColor3 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + A.Tint tint2 = new A.Tint() { Val = 37000 }; + A.SaturationModulation saturationModulation2 = new A.SaturationModulation() { Val = 300000 }; + + schemeColor3.Append(tint2); + schemeColor3.Append(saturationModulation2); + + gradientStop2.Append(schemeColor3); + + A.GradientStop gradientStop3 = new A.GradientStop() { Position = 100000 }; + + A.SchemeColor schemeColor4 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + A.Tint tint3 = new A.Tint() { Val = 15000 }; + A.SaturationModulation saturationModulation3 = new A.SaturationModulation() { Val = 350000 }; + + schemeColor4.Append(tint3); + schemeColor4.Append(saturationModulation3); + + gradientStop3.Append(schemeColor4); + + gradientStopList1.Append(gradientStop1); + gradientStopList1.Append(gradientStop2); + gradientStopList1.Append(gradientStop3); + A.LinearGradientFill linearGradientFill1 = new A.LinearGradientFill() { Angle = 16200000, Scaled = true }; + + gradientFill1.Append(gradientStopList1); + gradientFill1.Append(linearGradientFill1); + + A.GradientFill gradientFill2 = new A.GradientFill() { RotateWithShape = true }; + + A.GradientStopList gradientStopList2 = new A.GradientStopList(); + + A.GradientStop gradientStop4 = new A.GradientStop() { Position = 0 }; + + A.SchemeColor schemeColor5 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + A.Shade shade1 = new A.Shade() { Val = 51000 }; + A.SaturationModulation saturationModulation4 = new A.SaturationModulation() { Val = 130000 }; + + schemeColor5.Append(shade1); + schemeColor5.Append(saturationModulation4); + + gradientStop4.Append(schemeColor5); + + A.GradientStop gradientStop5 = new A.GradientStop() { Position = 80000 }; + + A.SchemeColor schemeColor6 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + A.Shade shade2 = new A.Shade() { Val = 93000 }; + A.SaturationModulation saturationModulation5 = new A.SaturationModulation() { Val = 130000 }; + + schemeColor6.Append(shade2); + schemeColor6.Append(saturationModulation5); + + gradientStop5.Append(schemeColor6); + + A.GradientStop gradientStop6 = new A.GradientStop() { Position = 100000 }; + + A.SchemeColor schemeColor7 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + A.Shade shade3 = new A.Shade() { Val = 94000 }; + A.SaturationModulation saturationModulation6 = new A.SaturationModulation() { Val = 135000 }; + + schemeColor7.Append(shade3); + schemeColor7.Append(saturationModulation6); + + gradientStop6.Append(schemeColor7); + + gradientStopList2.Append(gradientStop4); + gradientStopList2.Append(gradientStop5); + gradientStopList2.Append(gradientStop6); + A.LinearGradientFill linearGradientFill2 = new A.LinearGradientFill() { Angle = 16200000, Scaled = false }; + + gradientFill2.Append(gradientStopList2); + gradientFill2.Append(linearGradientFill2); + + fillStyleList1.Append(solidFill1); + fillStyleList1.Append(gradientFill1); + fillStyleList1.Append(gradientFill2); + + A.LineStyleList lineStyleList1 = new A.LineStyleList(); + + A.Outline outline1 = new A.Outline() { Width = 9525, CapType = A.LineCapValues.Flat, CompoundLineType = A.CompoundLineValues.Single, Alignment = A.PenAlignmentValues.Center }; + + A.SolidFill solidFill2 = new A.SolidFill(); + + A.SchemeColor schemeColor8 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + A.Shade shade4 = new A.Shade() { Val = 95000 }; + A.SaturationModulation saturationModulation7 = new A.SaturationModulation() { Val = 105000 }; + + schemeColor8.Append(shade4); + schemeColor8.Append(saturationModulation7); + + solidFill2.Append(schemeColor8); + A.PresetDash presetDash1 = new A.PresetDash() { Val = A.PresetLineDashValues.Solid }; + + outline1.Append(solidFill2); + outline1.Append(presetDash1); + + A.Outline outline2 = new A.Outline() { Width = 25400, CapType = A.LineCapValues.Flat, CompoundLineType = A.CompoundLineValues.Single, Alignment = A.PenAlignmentValues.Center }; + + A.SolidFill solidFill3 = new A.SolidFill(); + A.SchemeColor schemeColor9 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + + solidFill3.Append(schemeColor9); + A.PresetDash presetDash2 = new A.PresetDash() { Val = A.PresetLineDashValues.Solid }; + + outline2.Append(solidFill3); + outline2.Append(presetDash2); + + A.Outline outline3 = new A.Outline() { Width = 38100, CapType = A.LineCapValues.Flat, CompoundLineType = A.CompoundLineValues.Single, Alignment = A.PenAlignmentValues.Center }; + + A.SolidFill solidFill4 = new A.SolidFill(); + A.SchemeColor schemeColor10 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + + solidFill4.Append(schemeColor10); + A.PresetDash presetDash3 = new A.PresetDash() { Val = A.PresetLineDashValues.Solid }; + + outline3.Append(solidFill4); + outline3.Append(presetDash3); + + lineStyleList1.Append(outline1); + lineStyleList1.Append(outline2); + lineStyleList1.Append(outline3); + + A.EffectStyleList effectStyleList1 = new A.EffectStyleList(); + + A.EffectStyle effectStyle1 = new A.EffectStyle(); + + A.EffectList effectList1 = new A.EffectList(); + + A.OuterShadow outerShadow1 = new A.OuterShadow() { BlurRadius = 40000L, Distance = 20000L, Direction = 5400000, RotateWithShape = false }; + + A.RgbColorModelHex rgbColorModelHex11 = new A.RgbColorModelHex() { Val = "000000" }; + A.Alpha alpha1 = new A.Alpha() { Val = 38000 }; + + rgbColorModelHex11.Append(alpha1); + + outerShadow1.Append(rgbColorModelHex11); + + effectList1.Append(outerShadow1); + + effectStyle1.Append(effectList1); + + A.EffectStyle effectStyle2 = new A.EffectStyle(); + + A.EffectList effectList2 = new A.EffectList(); + + A.OuterShadow outerShadow2 = new A.OuterShadow() { BlurRadius = 40000L, Distance = 23000L, Direction = 5400000, RotateWithShape = false }; + + A.RgbColorModelHex rgbColorModelHex12 = new A.RgbColorModelHex() { Val = "000000" }; + A.Alpha alpha2 = new A.Alpha() { Val = 35000 }; + + rgbColorModelHex12.Append(alpha2); + + outerShadow2.Append(rgbColorModelHex12); + + effectList2.Append(outerShadow2); + + effectStyle2.Append(effectList2); + + A.EffectStyle effectStyle3 = new A.EffectStyle(); + + A.EffectList effectList3 = new A.EffectList(); + + A.OuterShadow outerShadow3 = new A.OuterShadow() { BlurRadius = 40000L, Distance = 23000L, Direction = 5400000, RotateWithShape = false }; + + A.RgbColorModelHex rgbColorModelHex13 = new A.RgbColorModelHex() { Val = "000000" }; + A.Alpha alpha3 = new A.Alpha() { Val = 35000 }; + + rgbColorModelHex13.Append(alpha3); + + outerShadow3.Append(rgbColorModelHex13); + + effectList3.Append(outerShadow3); + + A.Scene3DType scene3DType1 = new A.Scene3DType(); + + A.Camera camera1 = new A.Camera() { Preset = A.PresetCameraValues.OrthographicFront }; + A.Rotation rotation1 = new A.Rotation() { Latitude = 0, Longitude = 0, Revolution = 0 }; + + camera1.Append(rotation1); + + A.LightRig lightRig1 = new A.LightRig() { Rig = A.LightRigValues.ThreePoints, Direction = A.LightRigDirectionValues.Top }; + A.Rotation rotation2 = new A.Rotation() { Latitude = 0, Longitude = 0, Revolution = 1200000 }; + + lightRig1.Append(rotation2); + + scene3DType1.Append(camera1); + scene3DType1.Append(lightRig1); + + A.Shape3DType shape3DType1 = new A.Shape3DType(); + A.BevelTop bevelTop1 = new A.BevelTop() { Width = 63500L, Height = 25400L }; + + shape3DType1.Append(bevelTop1); + + effectStyle3.Append(effectList3); + effectStyle3.Append(scene3DType1); + effectStyle3.Append(shape3DType1); + + effectStyleList1.Append(effectStyle1); + effectStyleList1.Append(effectStyle2); + effectStyleList1.Append(effectStyle3); + + A.BackgroundFillStyleList backgroundFillStyleList1 = new A.BackgroundFillStyleList(); + + A.SolidFill solidFill5 = new A.SolidFill(); + A.SchemeColor schemeColor11 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + + solidFill5.Append(schemeColor11); + + A.GradientFill gradientFill3 = new A.GradientFill() { RotateWithShape = true }; + + A.GradientStopList gradientStopList3 = new A.GradientStopList(); + + A.GradientStop gradientStop7 = new A.GradientStop() { Position = 0 }; + + A.SchemeColor schemeColor12 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + A.Tint tint4 = new A.Tint() { Val = 40000 }; + A.SaturationModulation saturationModulation8 = new A.SaturationModulation() { Val = 350000 }; + + schemeColor12.Append(tint4); + schemeColor12.Append(saturationModulation8); + + gradientStop7.Append(schemeColor12); + + A.GradientStop gradientStop8 = new A.GradientStop() { Position = 40000 }; + + A.SchemeColor schemeColor13 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + A.Tint tint5 = new A.Tint() { Val = 45000 }; + A.Shade shade5 = new A.Shade() { Val = 99000 }; + A.SaturationModulation saturationModulation9 = new A.SaturationModulation() { Val = 350000 }; + + schemeColor13.Append(tint5); + schemeColor13.Append(shade5); + schemeColor13.Append(saturationModulation9); + + gradientStop8.Append(schemeColor13); + + A.GradientStop gradientStop9 = new A.GradientStop() { Position = 100000 }; + + A.SchemeColor schemeColor14 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + A.Shade shade6 = new A.Shade() { Val = 20000 }; + A.SaturationModulation saturationModulation10 = new A.SaturationModulation() { Val = 255000 }; + + schemeColor14.Append(shade6); + schemeColor14.Append(saturationModulation10); + + gradientStop9.Append(schemeColor14); + + gradientStopList3.Append(gradientStop7); + gradientStopList3.Append(gradientStop8); + gradientStopList3.Append(gradientStop9); + + A.PathGradientFill pathGradientFill1 = new A.PathGradientFill() { Path = A.PathShadeValues.Circle }; + A.FillToRectangle fillToRectangle1 = new A.FillToRectangle() { Left = 50000, Top = -80000, Right = 50000, Bottom = 180000 }; + + pathGradientFill1.Append(fillToRectangle1); + + gradientFill3.Append(gradientStopList3); + gradientFill3.Append(pathGradientFill1); + + A.GradientFill gradientFill4 = new A.GradientFill() { RotateWithShape = true }; + + A.GradientStopList gradientStopList4 = new A.GradientStopList(); + + A.GradientStop gradientStop10 = new A.GradientStop() { Position = 0 }; + + A.SchemeColor schemeColor15 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + A.Tint tint6 = new A.Tint() { Val = 80000 }; + A.SaturationModulation saturationModulation11 = new A.SaturationModulation() { Val = 300000 }; + + schemeColor15.Append(tint6); + schemeColor15.Append(saturationModulation11); + + gradientStop10.Append(schemeColor15); + + A.GradientStop gradientStop11 = new A.GradientStop() { Position = 100000 }; + + A.SchemeColor schemeColor16 = new A.SchemeColor() { Val = A.SchemeColorValues.PhColor }; + A.Shade shade7 = new A.Shade() { Val = 30000 }; + A.SaturationModulation saturationModulation12 = new A.SaturationModulation() { Val = 200000 }; + + schemeColor16.Append(shade7); + schemeColor16.Append(saturationModulation12); + + gradientStop11.Append(schemeColor16); + + gradientStopList4.Append(gradientStop10); + gradientStopList4.Append(gradientStop11); + + A.PathGradientFill pathGradientFill2 = new A.PathGradientFill() { Path = A.PathShadeValues.Circle }; + A.FillToRectangle fillToRectangle2 = new A.FillToRectangle() { Left = 50000, Top = 50000, Right = 50000, Bottom = 50000 }; + + pathGradientFill2.Append(fillToRectangle2); + + gradientFill4.Append(gradientStopList4); + gradientFill4.Append(pathGradientFill2); + + backgroundFillStyleList1.Append(solidFill5); + backgroundFillStyleList1.Append(gradientFill3); + backgroundFillStyleList1.Append(gradientFill4); + + formatScheme1.Append(fillStyleList1); + formatScheme1.Append(lineStyleList1); + formatScheme1.Append(effectStyleList1); + formatScheme1.Append(backgroundFillStyleList1); + + themeElements1.Append(colorScheme1); + themeElements1.Append(fontScheme2); + themeElements1.Append(formatScheme1); + A.ObjectDefaults objectDefaults1 = new A.ObjectDefaults(); + A.ExtraColorSchemeList extraColorSchemeList1 = new A.ExtraColorSchemeList(); + + theme1.Append(themeElements1); + theme1.Append(objectDefaults1); + theme1.Append(extraColorSchemeList1); + + themePart1.Theme = theme1; + } + + private void SetPackageProperties(OpenXmlPackage document) + { + document.PackageProperties.Creator = "manleon"; + document.PackageProperties.Created = System.Xml.XmlConvert.ToDateTime("2009-08-12T20:10:16Z", System.Xml.XmlDateTimeSerializationMode.RoundtripKind); + document.PackageProperties.Modified = System.Xml.XmlConvert.ToDateTime("2010-05-10T20:23:10Z", System.Xml.XmlDateTimeSerializationMode.RoundtripKind); + document.PackageProperties.LastModifiedBy = "manleon"; + } + + + #endregion + } +} diff --git a/ClosedXML/ClosedXML/Excel/XLWorksheet.cs b/ClosedXML/ClosedXML/Excel/XLWorksheet.cs new file mode 100644 index 0000000..6229ca3 --- /dev/null +++ b/ClosedXML/ClosedXML/Excel/XLWorksheet.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public class XLWorksheet: XLRange + { + public const UInt32 MaxNumberOfRows = 1048576; + public const UInt32 MaxNumberOfColumns = 16384; + + public XLWorksheet(XLWorkbook workbook, String sheetName, XLCells cells) + : base( + new XLCell(workbook, new XLCellAddress(1,1)) + , new XLCell(workbook, new XLCellAddress(MaxNumberOfRows, MaxNumberOfColumns)) + , cells, null) + { + this.name = sheetName; + } + + public override List Cells() + { + return Cells(CellContent.All); + } + + public override List Cells(CellContent cellContent) + { + if (cellContent == CellContent.WithValues) + { + return base.Cells(cellContent); + } + else + { + String errorText = "Cannot load entire worksheet into memory. Please use a range (eg. XLWorksheet.Range(\"A1:D5\")) or retrieve cells with values (eg. XLWorksheet.Cells(CellContent.WithValues))."; + throw new InvalidOperationException(errorText); + } + } + + private String name; + public String Name + { + get + { + return name; + } + set + { + name = value; + } + } + + public static String ColumnNumberToLetter(UInt32 column) + { + String s = String.Empty; + for ( + Int32 i = Convert.ToInt32( + Math.Log( + Convert.ToDouble( + 25 * ( + Convert.ToDouble(column) + + 1 + ) + ) + ) / Math.Log(26) + ) - 1 + ; i >= 0 + ; i-- + ) + { + Int32 x = Convert.ToInt32(Math.Pow(26, i + 1) - 1) / 25 - 1; + if (column > x) + { + s += (Char)(((column - x - 1) / Convert.ToInt32(Math.Pow(26, i))) % 26 + 65); + } + } + return s; + } + + public static UInt32 ColumnLetterToNumber(String column) + { + Int32 intColumnLetterLength = column.Length; + Int32 retVal = 0; + for (Int32 intCount = 0; intCount < intColumnLetterLength; intCount++) + { + retVal = retVal * 26 + (column.Substring(intCount, 1).ToUpper().ToCharArray()[0] - 64); + } + return (UInt32)retVal; + } + } +} diff --git a/ClosedXML/ClosedXML/Excel/XLWorksheets.cs b/ClosedXML/ClosedXML/Excel/XLWorksheets.cs new file mode 100644 index 0000000..fb89db1 --- /dev/null +++ b/ClosedXML/ClosedXML/Excel/XLWorksheets.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML.Excel +{ + public class XLWorksheets : IEnumerable + { + private Dictionary worksheets = new Dictionary(); + + private XLWorkbook workbook; + + public XLWorksheets(XLWorkbook workbook) + { + this.workbook = workbook; + } + + public XLWorksheet this[String sheetName] + { + get + { + return worksheets[sheetName]; + } + } + + public XLWorksheet Add(String name) + { + XLWorksheet worksheet = new XLWorksheet(workbook, name, new XLCells(workbook)); + worksheets.Add(name, worksheet); + return worksheet; + } + + public UInt32 Count + { + get + { + return (UInt32)worksheets.Count; + } + } + + private Int32 nextWorksheetId = 1; + private Int32 GetNextWorksheetId() + { + return nextWorksheetId++; + } + + #region IEnumerable Members + + public IEnumerator GetEnumerator() + { + return worksheets.Values.AsEnumerable().GetEnumerator(); + } + + #endregion + + #region IEnumerable Members + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return this.GetEnumerator(); + } + + #endregion + } +} diff --git a/ClosedXML/ClosedXML/Properties/AssemblyInfo.cs b/ClosedXML/ClosedXML/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..367a544 --- /dev/null +++ b/ClosedXML/ClosedXML/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ClosedXML")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ClosedXML")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8747331d-de58-4621-8c7f-a7d57ca3467a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]