Skip to content

Commit

Permalink
friday night
Browse files Browse the repository at this point in the history
  • Loading branch information
tillwolff committed Mar 25, 2017
1 parent 759aead commit 53818f2
Show file tree
Hide file tree
Showing 18 changed files with 649 additions and 0 deletions.
6 changes: 6 additions & 0 deletions EPPlus.Html.Test/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
74 changes: 74 additions & 0 deletions EPPlus.Html.Test/EPPlus.Html.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?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>{DB4C442E-D5FF-4DD2-A809-496D16646D9D}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EPPlus.Html.Test</RootNamespace>
<AssemblyName>EPPlus.Html.Test</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EPPlus, Version=4.1.0.0, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL">
<HintPath>..\packages\EPPlus.4.1.0\lib\net40\EPPlus.dll</HintPath>
<Private>True</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" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="Resources\Test001.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EPPlus.Html\EPPlus.Html.csproj">
<Project>{6a9878f8-48ca-410e-92e8-6941f580d39b}</Project>
<Name>EPPlus.Html</Name>
</ProjectReference>
</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>
35 changes: 35 additions & 0 deletions EPPlus.Html.Test/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace EPPlus.Html.Test
{
class Program
{
private static string CurrentLocation = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
private static FileInfo Test001 = new FileInfo(CurrentLocation + "\\Resources\\Test001.xlsx");

static void Main(string[] args)
{
var package = new ExcelPackage(new FileInfo(CurrentLocation + "/Resources/Test001.xlsx"));
var worksheet = package.Workbook.Worksheets[1];

string html = worksheet.ToHtml();

Show(html);
}

static void Show(string html)
{
string tmpFile = Path.GetTempFileName() + ".html";
File.WriteAllText(tmpFile, html);
Process.Start(tmpFile);
}
}
}
36 changes: 36 additions & 0 deletions EPPlus.Html.Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("EPPlus.Html.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EPPlus.Html.Test")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[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("db4c442e-d5ff-4dd2-a809-496d16646d9d")]

// 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")]
Binary file added EPPlus.Html.Test/Resources/Test001.xlsx
Binary file not shown.
4 changes: 4 additions & 0 deletions EPPlus.Html.Test/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EPPlus" version="4.1.0" targetFramework="net452" />
</packages>
28 changes: 28 additions & 0 deletions EPPlus.Html.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EPPlus.Html", "EPPlus.Html\EPPlus.Html.csproj", "{6A9878F8-48CA-410E-92E8-6941F580D39B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EPPlus.Html.Test", "EPPlus.Html.Test\EPPlus.Html.Test.csproj", "{DB4C442E-D5FF-4DD2-A809-496D16646D9D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6A9878F8-48CA-410E-92E8-6941F580D39B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6A9878F8-48CA-410E-92E8-6941F580D39B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A9878F8-48CA-410E-92E8-6941F580D39B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A9878F8-48CA-410E-92E8-6941F580D39B}.Release|Any CPU.Build.0 = Release|Any CPU
{DB4C442E-D5FF-4DD2-A809-496D16646D9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB4C442E-D5FF-4DD2-A809-496D16646D9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB4C442E-D5FF-4DD2-A809-496D16646D9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB4C442E-D5FF-4DD2-A809-496D16646D9D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
128 changes: 128 additions & 0 deletions EPPlus.Html/Converters/ExcelToCss.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using EPPlus.Html.Html;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EPPlus.Html.Converters
{
internal static class ExcelToCss
{
internal static CssDeclaration ToCss(this ExcelRow excelRow)
{
var css = new CssDeclaration();

css["height"] = excelRow.Height + "px";

css.Update(excelRow.Style.ToCss());

return css;
}

internal static CssDeclaration ToCss(this ExcelRange excelRange)
{
var css = new CssDeclaration();
if (excelRange.Columns == 1 && excelRange.Rows == 1)
{
var excelColumn = excelRange.Worksheet.Column(excelRange.Start.Column);

css["max-width"] = excelColumn.Width + "em";
css["width"] = excelColumn.Width + "em";
css.Update(excelRange.Style.ToCss());
}
return css;
}

internal static CssDeclaration ToCss(this ExcelStyle excelStyle)
{
var css = new CssDeclaration();
css["text-align"] = excelStyle.HorizontalAlignment.ToCssProperty();
css["background-color"] = excelStyle.Fill.BackgroundColor.ToHexCode();
css.Update(excelStyle.Font.ToCss());
css.Update(excelStyle.Border.ToCss());
return css;
}

internal static CssDeclaration ToCss(this ExcelFont excelFont)
{
var css = new CssDeclaration();

if (excelFont.Bold)
{
css["font-weight"] = "bold";
}

css["font-family"] = excelFont.Name;
css["font-size"] = excelFont.Size + "pt";

css["color"] = excelFont.Color.ToHexCode();

return css;
}

internal static CssDeclaration ToCss(this Border border)
{
var css = new CssDeclaration();

css["border-top"] = border.Top.ToCssProperty();
css["border-bottom"] = border.Bottom.ToCssProperty();

return css;
}

internal static string ToCssProperty(this ExcelBorderItem excelBorderItem)
{
if (excelBorderItem != null)
{
return excelBorderItem.Style.ToCssProperty() + " " + excelBorderItem.Color.Rgb;
}
else
{
return null;
}
}

internal static string ToCssProperty(this ExcelBorderStyle excelBorderStyle)
{
switch (excelBorderStyle)
{
case ExcelBorderStyle.Thin:
return "1px solid";
case ExcelBorderStyle.Thick:
return "2px solid";
default:
return "none";
}
}

internal static string ToCssProperty(this ExcelHorizontalAlignment excelHorizontalAlignment)
{
switch (excelHorizontalAlignment)
{
case ExcelHorizontalAlignment.Right:
return "right";
case ExcelHorizontalAlignment.Left:
return "left";
case ExcelHorizontalAlignment.Center:
return "center";
default:
return null;
}
}

internal static string ToHexCode(this ExcelColor excelColor)
{
if (excelColor != null && excelColor.Rgb != null && excelColor.Rgb.Length > 3)
{
return "#" + excelColor.Rgb.Substring(2);
}
else
{
return null;
}
}
}
}
68 changes: 68 additions & 0 deletions EPPlus.Html/EPPlus.Html.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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>{6A9878F8-48CA-410E-92E8-6941F580D39B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EPPlus.Html</RootNamespace>
<AssemblyName>EPPlus.Html</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\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>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EPPlus, Version=4.1.0.0, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL">
<HintPath>..\packages\EPPlus.4.1.0\lib\net40\EPPlus.dll</HintPath>
<Private>True</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" />
</ItemGroup>
<ItemGroup>
<Compile Include="Converters\ExcelToCss.cs" />
<Compile Include="EPPlusExtensions.cs" />
<Compile Include="Html\CssDeclaration.cs" />
<Compile Include="Html\CssInlineStyles.cs" />
<Compile Include="Html\HtmlAttributeCollection.cs" />
<Compile Include="Html\HtmlElement.cs" />
<Compile Include="Html\HtmlElementCollection.cs" />
<Compile Include="Html\RenderElement.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>
Loading

0 comments on commit 53818f2

Please sign in to comment.