IOT Virtual Conference - Register now to book your ticket and get updates
x
CONGRATULATIONS! C# Corner Q1, 2021 MVPs Announced
Why Join
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forumguidelines
Devika M
1.9k
39
708
Convert Excel to HTML by XSLT transformation of XML
Jul 17 2020 12:28 AM
I have a requirement to preview excel files in browser. I could generate an XML for the worksheet. I am trying to convert the XML to HTML by XSLT transformation. I am able to get the data in table format. I could not get the style part in xsl. Below is the XML for a sample spreadsheet.
<Data>
<DataProps>
<sheetFormatPr defaultColWidth=
"9.25"
defaultRowHeight=
"15"
dyDescent=
"0.25"
/>
</DataProps>
<Row RowNumber=
"1"
>
<Cell Ref=
"A1"
ColumnId=
"A"
ColumnNumber=
"0"
Type=
"s"
>
<CellProps />
<Value>Make </Value>
<DisplayValue>Make </DisplayValue>
</Cell>
<Cell Ref=
"B1"
ColumnId=
"B"
ColumnNumber=
"1"
Type=
"s"
>
<CellProps />
<Value>Miles </Value>
<DisplayValue>Miles </DisplayValue>
</Cell>
<Cell Ref=
"C1"
ColumnId=
"C"
ColumnNumber=
"2"
Type=
"s"
>
<CellProps />
<Value>Cost</Value>
<DisplayValue>Cost</DisplayValue>
</Cell>
</Row>
<Row RowNumber=
"2"
>
<Cell Ref=
"A2"
ColumnId=
"A"
ColumnNumber=
"0"
Type=
"s"
>
<CellProps />
<Value>Ford</Value>
<DisplayValue>Ford</DisplayValue>
</Cell>
<Cell Ref=
"B2"
ColumnId=
"B"
ColumnNumber=
"1"
>
<CellProps />
<Value>40000</Value>
<DisplayValue>40000</DisplayValue>
</Cell>
<Cell Ref=
"C2"
ColumnId=
"C"
ColumnNumber=
"2"
Style=
"1"
>
<CellProps numFmtId=
"6"
formatCode=
""
$
"#,##0_);[Red]\("
$
"#,##0\)"
applyNumberFormat=
"1"
>
<font>
<sz val=
"11"
/>
<color theme=
"1"
/>
<name val=
"Calibri"
/>
<family val=
"Swiss"
/>
<scheme val=
"minor"
/>
</font>
</CellProps>
<Value>3500</Value>
<DisplayValue>$3,500</DisplayValue>
</Cell>
</Row>
<Row RowNumber=
"3"
>
<Cell Ref=
"A3"
ColumnId=
"A"
ColumnNumber=
"0"
Type=
"s"
>
<CellProps />
<Value>Chevi</Value>
<DisplayValue>Chevi</DisplayValue>
</Cell>
<Cell Ref=
"B3"
ColumnId=
"B"
ColumnNumber=
"1"
>
<CellProps />
<Value>55000</Value>
<DisplayValue>55000</DisplayValue>
</Cell>
<Cell Ref=
"C3"
ColumnId=
"C"
ColumnNumber=
"2"
Style=
"1"
>
<CellProps numFmtId=
"6"
formatCode=
""
$
"#,##0_);[Red]\("
$
"#,##0\)"
applyNumberFormat=
"1"
>
<font>
<sz val=
"11"
/>
<color theme=
"1"
/>
<name val=
"Calibri"
/>
<family val=
"Swiss"
/>
<scheme val=
"minor"
/>
</font>
</CellProps>
<Value>4200</Value>
<DisplayValue>$4,200</DisplayValue>
</Cell>
</Row>
<Row RowNumber=
"4"
>
<Cell Ref=
"A4"
ColumnId=
"A"
ColumnNumber=
"0"
Type=
"s"
>
<CellProps />
<Value>Tata</Value>
<DisplayValue>Tata</DisplayValue>
</Cell>
<Cell Ref=
"B4"
ColumnId=
"B"
ColumnNumber=
"1"
>
<CellProps />
<Value>51000</Value>
<DisplayValue>51000</DisplayValue>
</Cell>
<Cell Ref=
"C4"
ColumnId=
"C"
ColumnNumber=
"2"
Style=
"1"
>
<CellProps numFmtId=
"6"
formatCode=
""
$
"#,##0_);[Red]\("
$
"#,##0\)"
applyNumberFormat=
"1"
>
<font>
<sz val=
"11"
/>
<color theme=
"1"
/>
<name val=
"Calibri"
/>
<family val=
"Swiss"
/>
<scheme val=
"minor"
/>
</font>
</CellProps>
<Value>3800</Value>
<DisplayValue>$3,800</DisplayValue>
</Cell>
</Row>
</Data>
XSL Sheet
<xsl:stylesheet version=
"3.0"
xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform"
>
<!-- This is the identity transformation, it is the
default
action -->
<xsl:template match=
"@*|node()"
>
<xsl:copy>
<xsl:apply-templates select=
"@*|node()"
/>
</xsl:copy>
</xsl:template>
<!-- This transforms Data to table-->
<xsl:template match=
"Data"
>
<table>
<xsl:apply-templates select=
"@*|node()"
/>
</table>
</xsl:template>
<!-- This transforms Row to tr -->
<xsl:template match=
"Row"
>
<tr>
<xsl:apply-templates select=
"@*|node()"
/>
</tr>
</xsl:template>
<!-- This transforms Cell to td -->
<xsl:template match=
"Cell"
>
<td>
<xsl:value-of select=
"DisplayValue"
/>
</td>
</xsl:template>
</xsl:stylesheet>
Reply
Answers (
1
)
If service is up establish a TCP connection to the specified port
Why is .NET a good option?