Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Date Author Change
using OfficeOpenXml.Export.HtmlExport.Accessibility;
using OfficeOpenXml.Export.HtmlExport.HtmlCollections;
using OfficeOpenXml.Export.HtmlExport.Parsers;
using OfficeOpenXml.Export.HtmlExport.Settings;
using OfficeOpenXml.Export.HtmlExport.Translators;
using OfficeOpenXml.Table;
using OfficeOpenXml.Utils;
Expand Down Expand Up @@ -731,8 +732,33 @@ internal void GetClassData(HTMLElement element, bool isTable, HtmlImage image, E
element.AddChildElement(childHtml);
}
}

var textRotation = cell.Style.TextRotation;
if (textRotation != 0 && textRotation != 255 && IsTextRotationExcluded(settings, isHeader) == false)
{
var rotationValue = textRotation > 90 ? textRotation - 90 : 360 - textRotation;
var rotationWrapper = new HTMLElement("div");
rotationWrapper.AddAttribute("style", $"display:inline-block;transform:rotate({rotationValue}deg);");
element.AddChildElement(rotationWrapper);
valueElement = rotationWrapper;
}
}

private static bool IsTextRotationExcluded(HtmlExportSettings settings, bool isHeader)
{
if (settings is HtmlRangeExportSettings rangeSettings)
{
return rangeSettings.Css.CssExclude.TextRotation;
}
if (settings is HtmlTableExportSettings tableSettings)
{
var exclude = isHeader ? tableSettings.Css.Exclude.TableStyle : tableSettings.Css.Exclude.CellStyle;
return exclude.TextRotation;
}
return false;
}


public void AddTableDataFromCell(ExcelRangeBase cell, string dataType, HTMLElement element, HtmlExportSettings settings, bool addRowScope, HtmlImage image, ExporterContext content)
{
if (dataType != ColumnDataTypeManager.HtmlDataTypes.String && settings.RenderDataAttributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ internal override List<Declaration> GenerateDeclarationList(TranslatorContext co
AddDeclaration("writing-mode", "vertical-lr");
AddDeclaration("text-orientation", "upright");
}
else
{
var rotationvalue = _textRotation > 90 ? _textRotation - 90 : 360 - _textRotation;
AddDeclaration("transform", $"rotate({rotationvalue}deg)");
}
}
if (_indent > 0 && context.Exclude.Indent == false)
{
Expand Down
72 changes: 51 additions & 21 deletions src/EPPlusTest/Export/HtmlExport/RangeExporterTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OfficeOpenXml;
using OfficeOpenXml.Export.HtmlExport;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Information;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
using System;
using System.Collections.Generic;
using System.IO;
using System.Drawing;
using OfficeOpenXml.Style;
using System.Text;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace EPPlusTest.Export.HtmlExport
Expand All @@ -19,20 +20,20 @@ public class RangeExporterTests : TestBase
[TestMethod]
public void ShouldExportHtmlWithHeadersNoAccessibilityAttributes()
{
using(var package = new ExcelPackage())
using (var package = new ExcelPackage())
{
var sheet = package.Workbook.Worksheets.Add("Test");
sheet.Cells["A1"].Value = "Name";
sheet.Cells["B1"].Value = "Age";
sheet.Cells["A2"].Value = "John Doe";
sheet.Cells["B2"].Value = 23;
var range = sheet.Cells["A1:B2"];
using(var ms = new MemoryStream())
using (var ms = new MemoryStream())
{
var exporter = range.CreateHtmlExporter();
exporter.Settings.Accessibility.TableSettings.AddAccessibilityAttributes=false;
exporter.Settings.Accessibility.TableSettings.AddAccessibilityAttributes = false;
exporter.Settings.Culture = new CultureInfo("us-en");
exporter.RenderHtml(ms);
exporter.RenderHtml(ms);
var sr = new StreamReader(ms);
ms.Position = 0;
var result = sr.ReadToEnd();
Expand Down Expand Up @@ -81,12 +82,12 @@ public async Task ShouldExportHtmlWithHeadersWithStyles()
var range = sheet.Cells["A1:B2"];
sheet.Cells["A1:B1"].Style.Font.Bold = true;
sheet.Cells["A1:B1"].Style.Font.Color.SetColor(Color.Blue);
sheet.Cells["A1:B1"].Style.Border.Bottom.Style=ExcelBorderStyle.Thin;
sheet.Cells["A1:B1"].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
sheet.Cells["A1:B1"].Style.Border.Bottom.Color.SetColor(Color.Red);
sheet.Cells["A1:B1"].Style.Fill.PatternType = ExcelFillStyle.LightGray;
sheet.Cells["A1:B1"].Style.Fill.BackgroundColor.SetColor(Color.LightCoral);
sheet.Cells["A1:B1"].Style.Fill.PatternColor.SetColor(Color.LightCyan);
sheet.Cells["A2:B2"].Style.Font.Italic=true;
sheet.Cells["A2:B2"].Style.Font.Italic = true;
sheet.Cells["B1:B2"].Style.Font.Name = "Consolas";

var exporter = range.CreateHtmlExporter();
Expand All @@ -95,7 +96,7 @@ public async Task ShouldExportHtmlWithHeadersWithStyles()
var result = exporter.GetSinglePage();

var expected = "<!DOCTYPE html><html><head><style type=\"text/css\">table.epplus-table{font-family:Calibri;font-size:11pt;border-spacing:0;border-collapse:collapse;word-wrap:break-word;white-space:nowrap;}.epp-hidden {display:none;}.epp-al {text-align:left;}.epp-ar {text-align:right;}.epp-dcw {width:64px;}.epp-drh {height:20px;}.epp-s1{background-repeat:repeat;background:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHdpZHRoPSc0JyBoZWlnaHQ9JzInPjxyZWN0IHdpZHRoPSc0JyBoZWlnaHQ9JzInIGZpbGw9JyNlMGZmZmYnLz48cmVjdCB4PScyJyB5PScwJyB3aWR0aD0nMScgaGVpZ2h0PScxJyBmaWxsPScjZjA4MDgwJy8+PHJlY3QgeD0nMCcgeT0nMScgd2lkdGg9JzEnIGhlaWdodD0nMScgZmlsbD0nI2YwODA4MCcvPjwvc3ZnPg==);color:#0000ff;font-weight:bolder;border-bottom:thin solid #ff0000;white-space: nowrap;vertical-align:bottom;}.epp-s2{background-repeat:repeat;background:url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHdpZHRoPSc0JyBoZWlnaHQ9JzInPjxyZWN0IHdpZHRoPSc0JyBoZWlnaHQ9JzInIGZpbGw9JyNlMGZmZmYnLz48cmVjdCB4PScyJyB5PScwJyB3aWR0aD0nMScgaGVpZ2h0PScxJyBmaWxsPScjZjA4MDgwJy8+PHJlY3QgeD0nMCcgeT0nMScgd2lkdGg9JzEnIGhlaWdodD0nMScgZmlsbD0nI2YwODA4MCcvPjwvc3ZnPg==);font-family:Consolas;color:#0000ff;font-weight:bolder;border-bottom:thin solid #ff0000;white-space: nowrap;vertical-align:bottom;}.epp-s3{font-style:italic;white-space: nowrap;vertical-align:bottom;}.epp-s4{font-family:Consolas;font-style:italic;white-space: nowrap;vertical-align:bottom;}</style></head><body><table class=\"epplus-table\"><thead><tr><th data-datatype=\"string\" class=\"epp-al epp-s1\">Name</th><th data-datatype=\"number\" class=\"epp-al epp-s2\">Age</th></tr></thead><tbody><tr><td class=\"epp-s3\">John Doe</td><td data-value=\"23\" class=\"epp-ar epp-s4\">23</td></tr></tbody></table></body></html>";

Assert.AreEqual(expected, result);
var resultAsync = await exporter.GetSinglePageAsync();
Assert.AreEqual(result, resultAsync);
Expand Down Expand Up @@ -142,7 +143,7 @@ public async Task ShouldExportHtmlWithMergedCells()
var resultAsync = await exporter.GetSinglePageAsync();
SaveAndCleanup(package);
Assert.AreEqual(result, resultAsync);

}
}
[TestMethod]
Expand Down Expand Up @@ -170,7 +171,7 @@ public void WriteAllsvenskan()
exporter.Settings.SetColumnWidth = true;
exporter.Settings.SetRowHeight = true;
exporter.Settings.Pictures.Include = ePictureInclude.Include;
var html =exporter.GetSinglePage();
var html = exporter.GetSinglePage();
File.WriteAllText("c:\\temp\\" + sheet.Name + ".html", html);
SaveAndCleanup(p);
}
Expand All @@ -180,16 +181,16 @@ public async Task WriteImagesAsync()
{
using (var p = OpenTemplatePackage("20-CreateAFileSystemReport.xlsx"))
{
var sheet = p.Workbook.Worksheets[0];
var sheet = p.Workbook.Worksheets[0];
var exporter = sheet.Cells["A1:E30"].CreateHtmlExporter();

exporter.Settings.SetColumnWidth = true;
exporter.Settings.SetRowHeight = true;
exporter.Settings.Pictures.Include = ePictureInclude.Include;
exporter.Settings.Minify = false;
exporter.Settings.Encoding = Encoding.UTF8;
exporter.Settings.Encoding = Encoding.UTF8;
var html = exporter.GetSinglePage();
var htmlAsync = await exporter.GetSinglePageAsync();
var htmlAsync = await exporter.GetSinglePageAsync();
File.WriteAllText("c:\\temp\\" + sheet.Name + ".html", html);
File.WriteAllText("c:\\temp\\" + sheet.Name + "-async.html", htmlAsync);
Assert.AreEqual(html, htmlAsync);
Expand Down Expand Up @@ -223,7 +224,7 @@ public void ExportMultipleRanges()
{
var sheet1 = p.Workbook.Worksheets[0];
var sheet2 = p.Workbook.Worksheets[1];

var exporter = p.Workbook.CreateHtmlExporter(
sheet2.Cells["A1:B13"],
sheet2.Cells["A16:B26"],
Expand Down Expand Up @@ -564,11 +565,11 @@ public void ExportRangeIssue()
x.TableId = "asia-toll-free";
});
var css = exporter.GetCssString();
File.WriteAllText("c:\\temp\\html.html",$"<html><head><style type=\"text/css\">{css}</style></head><body>{html1}</body></html>");
File.WriteAllText("c:\\temp\\html.html", $"<html><head><style type=\"text/css\">{css}</style></head><body>{html1}</body></html>");
}
}

private static void SaveRangeFile(ExcelPackage package, string ws, string address, int headerRows=1)
private static void SaveRangeFile(ExcelPackage package, string ws, string address, int headerRows = 1)
{
var sheet = package.Workbook.Worksheets[ws];
var range = sheet.Cells[address];
Expand All @@ -584,7 +585,7 @@ public void NumberFormatColorShouldCreateCssColor()
using (var package = OpenPackage("html_numfRed_text.xlsx", true))
{
var wb = package.Workbook;
var aNewWs = wb.Worksheets.Add("NewWs");
var aNewWs = wb.Worksheets.Add("NewWs");

var range = aNewWs.Cells["A1:A5"];
range.Formula = "ROW()";
Expand All @@ -605,6 +606,35 @@ public void NumberFormatColorShouldCreateCssColor()
SaveAndCleanup(package);
}
}

[TestMethod]
public void S1053()
{
{
using var p = OpenTemplatePackage("R05.xlsx");
var ws = p.Workbook.Worksheets[0];

var range = ws.Cells["A1:AA7"];
var exporter = range.CreateHtmlExporter();
var settings = exporter.Settings;
settings.SetRowHeight = true;
settings.SetColumnWidth = true;
var page = exporter.GetSinglePage();
File.WriteAllText("c:\\temp\\" + "R05" + ".html", page);
}
{
using var p = OpenTemplatePackage("CR168.xlsx");
var ws = p.Workbook.Worksheets[0];

var range = ws.Cells["A1:AA36"];
var exporter = range.CreateHtmlExporter();
var settings = exporter.Settings;
settings.SetRowHeight = true;
settings.SetColumnWidth = true;
var page = exporter.GetSinglePage();
File.WriteAllText("c:\\temp\\" + "CR168" + ".html", page);
}
}

}
}

Loading