diff --git a/ClosedXML/ClosedXML.sln b/ClosedXML/ClosedXML.sln index fd10e4a..0c32eca 100644 --- a/ClosedXML/ClosedXML.sln +++ b/ClosedXML/ClosedXML.sln @@ -14,9 +14,11 @@ TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClosedXML_Examples", "ClosedXML_Examples\ClosedXML_Examples.csproj", "{03A518D0-1CB7-488E-861C-C4E782B27A46}" +EndProject Global GlobalSection(TeamFoundationVersionControl) = preSolution - SccNumberOfProjects = 4 + SccNumberOfProjects = 5 SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} SccTeamFoundationServer = https://tfs09.codeplex.com/ SccLocalPath0 = . @@ -29,6 +31,9 @@ SccProjectUniqueName3 = ClosedXML_Test\\ClosedXML_Test.csproj SccProjectName3 = ClosedXML_Test SccLocalPath3 = ClosedXML_Test + SccProjectUniqueName4 = ClosedXML_Examples\\ClosedXML_Examples.csproj + SccProjectName4 = ClosedXML_Examples + SccLocalPath4 = ClosedXML_Examples EndGlobalSection GlobalSection(TestCaseManagementSettings) = postSolution CategoryFile = ClosedXML.vsmdi @@ -72,6 +77,16 @@ {D41B4F43-AB44-4236-B959-D508D259F4A7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {D41B4F43-AB44-4236-B959-D508D259F4A7}.Release|Mixed Platforms.Build.0 = Release|Any CPU {D41B4F43-AB44-4236-B959-D508D259F4A7}.Release|x86.ActiveCfg = Release|Any CPU + {03A518D0-1CB7-488E-861C-C4E782B27A46}.Debug|Any CPU.ActiveCfg = Debug|x86 + {03A518D0-1CB7-488E-861C-C4E782B27A46}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {03A518D0-1CB7-488E-861C-C4E782B27A46}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {03A518D0-1CB7-488E-861C-C4E782B27A46}.Debug|x86.ActiveCfg = Debug|x86 + {03A518D0-1CB7-488E-861C-C4E782B27A46}.Debug|x86.Build.0 = Debug|x86 + {03A518D0-1CB7-488E-861C-C4E782B27A46}.Release|Any CPU.ActiveCfg = Release|x86 + {03A518D0-1CB7-488E-861C-C4E782B27A46}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {03A518D0-1CB7-488E-861C-C4E782B27A46}.Release|Mixed Platforms.Build.0 = Release|x86 + {03A518D0-1CB7-488E-861C-C4E782B27A46}.Release|x86.ActiveCfg = Release|x86 + {03A518D0-1CB7-488E-861C-C4E782B27A46}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ClosedXML/ClosedXML/Excel/XLRange.cs b/ClosedXML/ClosedXML/Excel/XLRange.cs index 69f6b18..321ffc0 100644 --- a/ClosedXML/ClosedXML/Excel/XLRange.cs +++ b/ClosedXML/ClosedXML/Excel/XLRange.cs @@ -194,7 +194,9 @@ { get { - CellStyle = new XLStyle(Worksheet.GetCell(FirstCellAddressInWorksheet).CellStyle, this); + if(CellStyle == null) + CellStyle = new XLStyle(Worksheet.GetCell(FirstCellAddressInWorksheet).CellStyle, this); + return CellStyle; } set diff --git a/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs index 571ab35..92e615c 100644 --- a/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/ClosedXML/Excel/XLWorkbook_Save.cs @@ -238,7 +238,7 @@ titlesOfParts1.Append(vTVector2); Ap.Company company1 = new Ap.Company(); - company1.Text = "NSI"; + company1.Text = ""; Ap.LinksUpToDate linksUpToDate1 = new Ap.LinksUpToDate(); linksUpToDate1.Text = "false"; Ap.SharedDocument sharedDocument1 = new Ap.SharedDocument(); @@ -1221,8 +1221,8 @@ private void SetPackageProperties(OpenXmlPackage document) { document.PackageProperties.Creator = ""; - document.PackageProperties.Created = System.Xml.XmlConvert.ToDateTime("2010-05-20T13:20:55Z", System.Xml.XmlDateTimeSerializationMode.RoundtripKind); - document.PackageProperties.Modified = System.Xml.XmlConvert.ToDateTime("2010-05-20T13:21:22Z", System.Xml.XmlDateTimeSerializationMode.RoundtripKind); + document.PackageProperties.Created = DateTime.Now; + document.PackageProperties.Modified = DateTime.Now; document.PackageProperties.LastModifiedBy = ""; } diff --git a/ClosedXML/ClosedXML_Examples/BasicTable.cs b/ClosedXML/ClosedXML_Examples/BasicTable.cs new file mode 100644 index 0000000..5d9c652 --- /dev/null +++ b/ClosedXML/ClosedXML_Examples/BasicTable.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using ClosedXML.Excel; +using ClosedXML.Excel.Style; + +namespace ClosedXML_Examples +{ + public class BasicTable + { + public void Create(String filePath) + { + var wb = new XLWorkbook(filePath); + var ws = wb.Worksheets.Add("Contacts"); + + //First Names + ws.Cell("A1").Value = "FName"; + ws.Cell("A2").Value = "John"; + ws.Cell("A3").Value = "Hank"; + ws.Cell("A4").Value = "Dagny"; + //Last Names + ws.Cell("B1").Value = "LName"; + ws.Cell("B2").Value = "Galt"; + ws.Cell("B3").Value = "Rearden"; + ws.Cell("B4").Value = "Taggart"; + //Is an outcast? + ws.Cell("C1").Value = "Outcast"; + ws.Cell("C2").Value = true.ToString(); + ws.Cell("C3").Value = false.ToString(); + ws.Cell("C4").Value = false.ToString(); + //Date of Birth + ws.Cell("D1").Value = "DOB"; + ws.Cell("D2").Value = new DateTime(1919, 1, 21).ToString(); + ws.Cell("D3").Value = new DateTime(1907, 3, 4).ToString(); + ws.Cell("D4").Value = new DateTime(1921, 12, 15).ToString(); + //Income + ws.Cell("E1").Value = "Income"; + ws.Cell("E2").Value = "2000"; + ws.Cell("E3").Value = "40000"; + ws.Cell("E4").Value = "10000"; + + var rngDates = ws.Range("D2:D4"); + var rngNumbers = ws.Range("E2:E4"); + + rngDates.Style.NumberFormat.Format = "mm-dd-yy"; + rngNumbers.Style.NumberFormat.Format = "$ #,##0"; + + var rngHeaders = ws.Range("A1:E1"); + rngHeaders.Style.Font.Bold = true; + rngHeaders.Style.Fill.BackgroundColor = "6BE8FF"; + + var rngTable = ws.Range("A1:E4"); + rngTable.Style.Border.BottomBorder = XLBorderStyleValues.Thin; + + wb.Save(); + } + } +} diff --git a/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj b/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj new file mode 100644 index 0000000..21f0231 --- /dev/null +++ b/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj @@ -0,0 +1,69 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {03A518D0-1CB7-488E-861C-C4E782B27A46} + Exe + Properties + ClosedXML_Examples + ClosedXML_Examples + v4.0 + Client + 512 + SAK + SAK + SAK + SAK + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + {BD5E6BFE-E837-4A35-BCA9-39667D873A20} + ClosedXML + + + + + \ No newline at end of file diff --git a/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj.vspscc b/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj.vspscc new file mode 100644 index 0000000..feffdec --- /dev/null +++ b/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.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_Examples/HelloWorld.cs b/ClosedXML/ClosedXML_Examples/HelloWorld.cs new file mode 100644 index 0000000..0c6a2d9 --- /dev/null +++ b/ClosedXML/ClosedXML_Examples/HelloWorld.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using ClosedXML.Excel; + +namespace ClosedXML_Examples +{ + public class HelloWorld + { + public void Create(String filePath) + { + var workbook = new XLWorkbook(filePath); + var worksheet = workbook.Worksheets.Add("Sample Sheet"); + worksheet.Cell("A1").Value = "Hello World!"; + workbook.Save(); + } + } +} diff --git a/ClosedXML/ClosedXML_Examples/Program.cs b/ClosedXML/ClosedXML_Examples/Program.cs new file mode 100644 index 0000000..5730cdd --- /dev/null +++ b/ClosedXML/ClosedXML_Examples/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ClosedXML_Examples +{ + class Program + { + static void Main(string[] args) + { + var helloWorld = new HelloWorld(); + helloWorld.Create(@"c:\HelloWorld.xlsx"); + + var basicTable = new BasicTable(); + basicTable.Create(@"c:\BasicTable.xlsx"); + } + } +} diff --git a/ClosedXML/ClosedXML_Examples/Properties/AssemblyInfo.cs b/ClosedXML/ClosedXML_Examples/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d492c06 --- /dev/null +++ b/ClosedXML/ClosedXML_Examples/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_Examples")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ClosedXML_Examples")] +[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("603cd89c-23f2-415e-8afc-2e9ab7a4c372")] + +// 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")]