...
 
Commits (6)
......@@ -27,3 +27,10 @@
/src/CMS/bin
/src/CMS/obj
/tmp
bin
obj
/src/build/Debug/Breeze.OpenXML.dll
/src/build/Debug/Breeze.OpenXML.pdb
/src/OpenXML/.vs/Breeze.OpenXML/v14/.suo
/src/OpenXML/packages/DocumentFormat.OpenXml.2.5/DocumentFormat.OpenXml.2.5.nupkg
/src/OpenXML/packages/DocumentFormat.OpenXml.2.5/lib/DocumentFormat.OpenXml.dll
......@@ -41,10 +41,14 @@
</Target>
<Target Name="nuget-pack" DependsOnTargets="Build;">
<MakeDir Directories="build\nuget\BreezeLib;build\nuget\BreezeLib.Azure;build\nuget\BreezeLib.CMS" />
<MakeDir Directories="build\nuget\BreezeLib;build\nuget\BreezeLib.Azure;build\nuget\BreezeLib.CMS;build\nuget\BreezeLib.OpenXml" />
<CreateItem Include="build\$(Configuration)\Breeze.CMS.dll">
<Output TaskParameter="Include" ItemName="BreezeLibCMSDLLs"/>
</CreateItem>
<CreateItem Include="build\$(Configuration)\Breeze.OpenXml.dll">
<Output TaskParameter="Include" ItemName="BreezeLibOpenXmlDLLs"/>
</CreateItem>
<CreateItem Include="build\$(Configuration)\Breeze.Media.Services.Azure.dll">
<Output TaskParameter="Include" ItemName="BreezeLibAzureDLLs"/>
</CreateItem>
......@@ -52,10 +56,12 @@
<Output TaskParameter="Include" ItemName="BreezeLibDLLs"/>
</CreateItem>
<Copy SourceFiles="@(BreezeLibOpenXmlDLLs)" DestinationFolder="$(BuildRoot)\nuget\BreezeLib.OpenXml\lib\net45" />
<Copy SourceFiles="@(BreezeLibDLLs)" DestinationFolder="$(BuildRoot)\nuget\BreezeLib\lib\net45" />
<Copy SourceFiles="@(BreezeLibAzureDLLs)" DestinationFolder="$(BuildRoot)\nuget\BreezeLib.Azure\lib\net45" />
<Copy SourceFiles="@(BreezeLibCMSDLLs)" DestinationFolder="$(BuildRoot)\nuget\BreezeLib.CMS\lib\net45" />
<ReplaceText
InputFile="src\nuspec\BreezeLib.nuspec"
OutputFile="build\nuget\BreezeLib\BreezeLib.nuspec"
......@@ -73,10 +79,18 @@
OutputFile="build\nuget\BreezeLib.CMS\BreezeLib.CMS.nuspec"
FindFor="\[VERSION\]"
ReplaceBy="$(productVersion).$(svnRevision)" />
<ReplaceText
InputFile="src\nuspec\BreezeLib.OpenXml.nuspec"
OutputFile="build\nuget\BreezeLib.OpenXml\BreezeLib.OpenXml.nuspec"
FindFor="\[VERSION\]"
ReplaceBy="$(productVersion).$(svnRevision)" />
<Exec Command="nuget pack $(MSBuildProjectDirectory)\build\nuget\BreezeLib\BreezeLib.nuspec" WorkingDirectory="$(BuildRoot)\nuget" />
<Exec Command="nuget pack $(MSBuildProjectDirectory)\build\nuget\BreezeLib.Azure\BreezeLib.Azure.nuspec" WorkingDirectory="$(BuildRoot)\nuget" />
<Exec Command="nuget pack $(MSBuildProjectDirectory)\build\nuget\BreezeLib.CMS\BreezeLib.CMS.nuspec" WorkingDirectory="$(BuildRoot)\nuget" />
<Exec Command="nuget pack $(MSBuildProjectDirectory)\build\nuget\BreezeLib.OpenXml\BreezeLib.OpenXml.nuspec" WorkingDirectory="$(BuildRoot)\nuget" />
</Target>
<Target Name="Clean">
......
......@@ -35,6 +35,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CMS", "CMS", "{3FDE8105-6BF
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Breeze.CMS", "CMS\Breeze.CMS.csproj", "{D6AB428D-0220-49B7-8CC4-84D3CD6F5836}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OpenXML", "OpenXML", "{4A084430-C00C-4D53-B378-AE4D3E0860A5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Breeze.OpenXML", "OpenXML\Breeze.OpenXML.csproj", "{AE2D5B86-7445-40E3-92F5-E59B27076ACB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -77,6 +81,10 @@ Global
{D6AB428D-0220-49B7-8CC4-84D3CD6F5836}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6AB428D-0220-49B7-8CC4-84D3CD6F5836}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6AB428D-0220-49B7-8CC4-84D3CD6F5836}.Release|Any CPU.Build.0 = Release|Any CPU
{AE2D5B86-7445-40E3-92F5-E59B27076ACB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE2D5B86-7445-40E3-92F5-E59B27076ACB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE2D5B86-7445-40E3-92F5-E59B27076ACB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE2D5B86-7445-40E3-92F5-E59B27076ACB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -91,5 +99,6 @@ Global
{84F8B9D1-E15F-487E-B6B2-54ED1FA8A3F7} = {3E6CAF49-0045-46AD-B6C9-D9376E27EA52}
{F02F6D71-F6C9-46D8-8D9E-5BD8CEB97D8A} = {41C66594-D42A-4FE1-B651-95185B6D70EB}
{D6AB428D-0220-49B7-8CC4-84D3CD6F5836} = {3FDE8105-6BFC-42CF-B00A-DE24F3301285}
{AE2D5B86-7445-40E3-92F5-E59B27076ACB} = {4A084430-C00C-4D53-B378-AE4D3E0860A5}
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AE2D5B86-7445-40E3-92F5-E59B27076ACB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Breeze.OpenXML</RootNamespace>
<AssemblyName>Breeze.OpenXML</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\build\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\build\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\DocumentFormat.OpenXml.2.5\lib\DocumentFormat.OpenXml.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="OpenXmlXLSX.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
using System;
using System.IO;
using System.Data;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System.Reflection;
namespace Breeze.OpenXML {
public static class OpenXmlXLSX {
static SpreadsheetDocument CreateEmpty(SpreadsheetDocument doc) {
doc.AddWorkbookPart().Workbook = new DocumentFormat.OpenXml.Spreadsheet.Workbook() { Sheets = new DocumentFormat.OpenXml.Spreadsheet.Sheets() };
return doc;
}
public static SpreadsheetDocument CreateEmpty(string fileName) {
return CreateEmpty(SpreadsheetDocument.Create(fileName, DocumentFormat.OpenXml.SpreadsheetDocumentType.Workbook));
}
public static SpreadsheetDocument CreateEmpty(Stream stream) {
return CreateEmpty(SpreadsheetDocument.Create(stream, DocumentFormat.OpenXml.SpreadsheetDocumentType.Workbook));
}
public static void Export(DataSet ds, string fileName) {
using (var doc = CreateEmpty(fileName))
foreach (System.Data.DataTable table in ds.Tables)
Export(doc, table);
}
public static void Export(DataSet ds, Stream stream) {
using (var doc = CreateEmpty(stream))
foreach (System.Data.DataTable table in ds.Tables)
Export(doc, table);
}
public static void Export(DataTable table, string fileName) {
using (var doc = CreateEmpty(fileName))
Export(doc, table);
}
public static void Export(DataTable table, Stream stream) {
using (var doc = CreateEmpty(stream))
Export(doc, table);
}
public static void Export(SpreadsheetDocument doc, DataTable table) {
WorksheetPart sheetPart = doc.WorkbookPart.AddNewPart<WorksheetPart>();
sheetPart.Worksheet = new Worksheet();
Sheets sheets = doc.WorkbookPart.Workbook.GetFirstChild<Sheets>();
string relationshipId = doc.WorkbookPart.GetIdOfPart(sheetPart);
uint sheetId = (sheets.Elements<Sheet>().Count() > 0) ?
sheets.Elements<Sheet>().Select(s => s.SheetId.Value).Max() + 1 : 1;
Sheet sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = table.TableName };
sheets.Append(sheet);
sheetPart.Worksheet.Append(
new SheetViews(
new SheetView(
new Selection() { ActiveCell = "A" + (table.Rows.Count + 2), SequenceOfReferences = new ListValue<StringValue>() { InnerText = "A" + (table.Rows.Count + 2) } }
) { WorkbookViewId = (UInt32Value)0U }));
SheetData sheetData = sheetPart.Worksheet.AppendChild<SheetData>(new SheetData());
Export(sheetData, table.Columns);
foreach (DataRow row in table.Rows)
Export(sheetData, row.ItemArray);
AddTableDefinition(sheetPart, table);
}
public static void Export(SheetData sheetData, IEnumerable row) {
DocumentFormat.OpenXml.Spreadsheet.Row newRow = new DocumentFormat.OpenXml.Spreadsheet.Row();
foreach (var col in row) {
DocumentFormat.OpenXml.Spreadsheet.Cell cell = new DocumentFormat.OpenXml.Spreadsheet.Cell();
decimal tmp;
cell.DataType = (decimal.TryParse(col.ToString(), out tmp)) ? DocumentFormat.OpenXml.Spreadsheet.CellValues.Number : DocumentFormat.OpenXml.Spreadsheet.CellValues.String;
cell.CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(col.ToString());
newRow.AppendChild(cell);
}
sheetData.AppendChild(newRow);
}
public static void AddTableDefinition(WorksheetPart sheetPart, DataTable table) {
if (((SpreadsheetDocument)sheetPart.OpenXmlPackage).WorkbookPart.WorkbookStylesPart == null)
((SpreadsheetDocument)sheetPart.OpenXmlPackage).WorkbookPart.AddNewPart<WorkbookStylesPart>().Stylesheet = new Stylesheet(
new DifferentialFormats(
new DifferentialFormat(
new Border(
new LeftBorder(new Color() { Indexed = (UInt32Value)12U }) { Style = BorderStyleValues.Thin },
new RightBorder(new Color() { Indexed = (UInt32Value)12U }) { Style = BorderStyleValues.Thin },
new TopBorder(new Color() { Indexed = (UInt32Value)12U }) { Style = BorderStyleValues.Thin },
new BottomBorder(new Color() { Indexed = (UInt32Value)12U }) { Style = BorderStyleValues.Thin }
) { DiagonalUp = false, DiagonalDown = false }
)) { Count = (UInt32Value)1U });
Table xlsxTable = new Table(
new TableColumns() { Count = (UInt32Value)(uint)(table.Columns.Count) },
new TableStyleInfo() { ShowFirstColumn = false, ShowLastColumn = false, ShowRowStripes = true, ShowColumnStripes = false }
) {
Id = ((SpreadsheetDocument)sheetPart.OpenXmlPackage).WorkbookPart.WorksheetParts.Select(x => x.TableDefinitionParts.Select(y => (uint)y.Table.Id).DefaultIfEmpty(0U).Max()).DefaultIfEmpty(0U).Max() + 1,
Name = table.TableName,
DisplayName = table.TableName,
Reference = OpenXmlXLSX.GetXLSRangeReference(0, 1, table.Columns.Count - 1, table.Rows.Count + 1),
TotalsRowShown = false,
BorderFormatId = (UInt32Value)0U
};
for (int i = 0; i < table.Columns.Count; i++)
xlsxTable.TableColumns.Append(new TableColumn() { Id = (UInt32Value)(uint)(i + 1), Name = table.Columns[i].Caption });
TableDefinitionPart tableDefinition = sheetPart.AddNewPart<TableDefinitionPart>();
tableDefinition.Table = xlsxTable;
sheetPart.Worksheet.Append(new TableParts(new TablePart() { Id = sheetPart.GetIdOfPart(tableDefinition) }) { Count = (UInt32Value)1U });
}
#region Helpers
public static DataTable ToDataTable<T>(this List<T> items) {
var tbl = new DataTable(typeof(T).Name);
PropertyInfo[] props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var prop in props) {
tbl.Columns.Add(prop.Name, prop.PropertyType);
}
foreach (var item in items) {
var values = new object[props.Length];
for (var i = 0; i < props.Length; i++) {
values[i] = props[i].GetValue(item, null);
}
tbl.Rows.Add(values);
}
return tbl;
}
#endregion
#region XLS Addreesing Helpers
public static string GetSheetReference(string sheet) {
return string.IsNullOrEmpty(sheet)
? string.Empty
: sheet.Contains(" ")
? string.Format("'{0}'!", sheet)
: sheet + "!";
}
public static string GetXLSColumnReference(int colIndex) {
string r = "";
do {
r = (char)((byte)'A' + colIndex % 26) + r;
} while ((colIndex = colIndex / 26 - 1) >= 0);
return r;
}
public static string GetXLSCellReference(int col, int row, bool absolute = false, string sheet = null) {
return string.Format(absolute ? "{0}${1}${2}" : "{0}{1}{2}", GetSheetReference(sheet), GetXLSColumnReference(col), row);
}
public static string GetXLSRangeReference(int col1, int row1, int col2, int row2, bool absolute = false, string sheet = null) {
return string.Format("{0}:{1}",
GetXLSCellReference(Math.Min(col1, col2), Math.Min(row1, row2), absolute, sheet),
GetXLSCellReference(Math.Max(col1, col2), Math.Max(row1, row2), absolute));
}
#endregion
}
}
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("Breeze.OpenXML")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
// 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("ae2d5b86-7445-40e3-92f5-e59b27076acb")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DocumentFormat.OpenXml" version="2.5" targetFramework="net452" />
</packages>
\ No newline at end of file
<?xml version="1.0"?>
<package >
<metadata>
<id>Breeze.OpenXml</id>
<version>[VERSION]</version>
<authors>Breeze Software</authors>
<owners>andrey</owners>
<licenseUrl>https://git.breeze-soft.com/breeze/bl/wikis/license</licenseUrl>
<projectUrl>https://git.breeze-soft.com/breeze/bl</projectUrl>
<!-- <iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl> -->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Breeze OpenXml Library</description>
<copyright>Copyright 2016 Breeze Software</copyright>
<!-- <tags>Tag1 Tag2</tags> -->
<dependencies>
<dependency id="DocumentFormat.OpenXml" version="2.5.0" />
</dependencies>
</metadata>
</package>
\ No newline at end of file