- In 8.9.0.0, TH cells were rendered the same way as TD cells: not bold, left-aligned.
- In 9.0.0.0, rendering of TH cells is in line with default styling proposed by W3 (https://www.w3.org/TR/html-markup/th.html): bold and centered.
th { font-weight: regular; text-align: left; }
using Aspose.Cells; using System.IO; using Microsoft.VisualStudio.TestTools.UnitTesting;namespace AsposeColspan
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestTh()
{
using (var inputStream = new MemoryStream())
{
using (var writer = new StreamWriter(inputStream))
{
writer.WriteLine(“”);
writer.WriteLine(“”);
writer.WriteLine(“Test TH styling”);
writer.WriteLine(“”);
writer.WriteLine(“.CustomCss th, .CustomCss { font-weight: regular; text-align: left; }”);
writer.WriteLine(“”);
writer.WriteLine(“”);
writer.WriteLine(“”);writer.WriteLine(<span style="color: rgb(163, 21, 21);">"<table><tr>"</span>); writer.WriteLine(<span style="color: rgb(163, 21, 21);">"<th>Default = bold, centered</th>"</span>); writer.WriteLine(<span style="color: rgb(163, 21, 21);">"<th class=\"CustomCss\">Non-bold stylesheet</th>"</span>); writer.WriteLine(<span style="color: rgb(163, 21, 21);">"<th style=\"font-weight: regular; text-align: left;\">Non-bold inline style</th>"</span>); writer.WriteLine(<span style="color: rgb(163, 21, 21);">"</tr></table>"</span>); writer.WriteLine(<span style="color: rgb(163, 21, 21);">"<table class=\"CustomCss\"><tr>"</span>); writer.WriteLine(<span style="color: rgb(163, 21, 21);">"<th>Non-bold stylesheet from table</th>"</span>); writer.WriteLine(<span style="color: rgb(163, 21, 21);">"</tr></table>"</span>); writer.WriteLine(<span style="color: rgb(163, 21, 21);">"</body>"</span>); writer.WriteLine(<span style="color: rgb(163, 21, 21);">"</html>"</span>); writer.Flush(); <span style="color: blue;">using</span> (<span style="color: blue;">var</span> workbook = <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">Workbook</span>(inputStream, <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">LoadOptions</span>(<span style="color: rgb(43, 145, 175);">LoadFormat</span>.Html))) { AssertCells_Desired(workbook); <span style="color: green;">// would like to see this one succeed</span> <span style="color: green;">//AssertCells_9000(workbook); // this one succeeds with Aspose.Cells 9.0.0.0 and 9.0.5.0</span> <span style="color: green;">//AssertCells_8900(workbook); // this one succeeds with Aspose.Cells 8.9.0.0</span> } } } } <span style="color: blue;">private</span> <span style="color: blue;">void</span> AssertCells_Desired(<span style="color: rgb(43, 145, 175);">Workbook</span> workbook) { AssertCell(workbook, 0, <span style="color: rgb(163, 21, 21);">"A1"</span>, <span style="color: rgb(163, 21, 21);">"Default = bold, centered"</span>, <span style="color: blue;">true</span>, <span style="color: rgb(43, 145, 175);">TextAlignmentType</span>.Center); AssertCell(workbook, 0, <span style="color: rgb(163, 21, 21);">"B1"</span>, <span style="color: rgb(163, 21, 21);">"Non-bold stylesheet"</span>, <span style="color: blue;">false</span>, <span style="color: rgb(43, 145, 175);">TextAlignmentType</span>.Left); AssertCell(workbook, 0, <span style="color: rgb(163, 21, 21);">"C1"</span>, <span style="color: rgb(163, 21, 21);">"Non-bold inline style"</span>, <span style="color: blue;">false</span>, <span style="color: rgb(43, 145, 175);">TextAlignmentType</span>.Left); AssertCell(workbook, 0, <span style="color: rgb(163, 21, 21);">"A2"</span>, <span style="color: rgb(163, 21, 21);">"Non-bold stylesheet from table"</span>, <span style="color: blue;">false</span>, <span style="color: rgb(43, 145, 175);">TextAlignmentType</span>.Left); } <span style="color: blue;">private</span> <span style="color: blue;">void</span> AssertCells_9000(<span style="color: rgb(43, 145, 175);">Workbook</span> workbook) { AssertCell(workbook, 0, <span style="color: rgb(163, 21, 21);">"A1"</span>, <span style="color: rgb(163, 21, 21);">"Default = bold, centered"</span>, <span style="color: blue;">true</span>, <span style="color: rgb(43, 145, 175);">TextAlignmentType</span>.Center); AssertCell(workbook, 0, <span style="color: rgb(163, 21, 21);">"B1"</span>, <span style="color: rgb(163, 21, 21);">"Non-bold stylesheet"</span>, <span style="color: blue;">true</span>, <span style="color: rgb(43, 145, 175);">TextAlignmentType</span>.Center); AssertCell(workbook, 0, <span style="color: rgb(163, 21, 21);">"C1"</span>, <span style="color: rgb(163, 21, 21);">"Non-bold inline style"</span>, <span style="color: blue;">true</span>, <span style="color: rgb(43, 145, 175);">TextAlignmentType</span>.Center); AssertCell(workbook, 0, <span style="color: rgb(163, 21, 21);">"A2"</span>, <span style="color: rgb(163, 21, 21);">"Non-bold stylesheet from table"</span>, <span style="color: blue;">true</span>, <span style="color: rgb(43, 145, 175);">TextAlignmentType</span>.Center); } <span style="color: blue;">private</span> <span style="color: blue;">void</span> AssertCells_8900(<span style="color: rgb(43, 145, 175);">Workbook</span> workbook) { AssertCell(workbook, 0, <span style="color: rgb(163, 21, 21);">"A1"</span>, <span style="color: rgb(163, 21, 21);">"Default = bold, centered"</span>, <span style="color: blue;">false</span>, <span style="color: rgb(43, 145, 175);">TextAlignmentType</span>.General); AssertCell(workbook, 0, <span style="color: rgb(163, 21, 21);">"B1"</span>, <span style="color: rgb(163, 21, 21);">"Non-bold stylesheet"</span>, <span style="color: blue;">false</span>, <span style="color: rgb(43, 145, 175);">TextAlignmentType</span>.General); AssertCell(workbook, 0, <span style="color: rgb(163, 21, 21);">"C1"</span>, <span style="color: rgb(163, 21, 21);">"Non-bold inline style"</span>, <span style="color: blue;">false</span>, <span style="color: rgb(43, 145, 175);">TextAlignmentType</span>.Left); AssertCell(workbook, 0, <span style="color: rgb(163, 21, 21);">"A2"</span>, <span style="color: rgb(163, 21, 21);">"Non-bold stylesheet from table"</span>, <span style="color: blue;">false</span>, <span style="color: rgb(43, 145, 175);">TextAlignmentType</span>.General); } <span style="color: blue;">private</span> <span style="color: blue;">void</span> AssertCell(<span style="color: rgb(43, 145, 175);">Workbook</span> workbook, <span style="color: blue;">int</span> worksheetNum, <span style="color: blue;">string</span> cellPos, <span style="color: blue;">string</span> expectedStringValue, <span style="color: blue;">bool</span> expectedBoldness, <span style="color: rgb(43, 145, 175);">TextAlignmentType</span> expectedAlignment) { <span style="color: blue;">var</span> cell = workbook.Worksheets[worksheetNum].Cells[cellPos]; <span style="color: blue;">string</span> description = <span style="color: blue;">string</span>.Format(<span style="color: rgb(163, 21, 21);">"Worksheet {0}, cell {1}: "</span>, worksheetNum, cellPos); <span style="color: rgb(43, 145, 175);">Assert</span>.AreEqual(<span style="color: rgb(43, 145, 175);">CellValueType</span>.IsString, cell.Type, description + <span style="color: rgb(163, 21, 21);">"Type."</span>); <span style="color: rgb(43, 145, 175);">Assert</span>.AreEqual(expectedStringValue, cell.StringValue, description + <span style="color: rgb(163, 21, 21);">"StringValue."</span>); <span style="color: rgb(43, 145, 175);">Assert</span>.AreEqual(expectedBoldness, cell.GetDisplayStyle().Font.IsBold, description + <span style="color: rgb(163, 21, 21);">"IsBold."</span>); <span style="color: rgb(43, 145, 175);">Assert</span>.AreEqual(expectedAlignment, cell.GetDisplayStyle().HorizontalAlignment, description + <span style="color: rgb(163, 21, 21);">"HorizontalAlignment."</span>); } }
}