xlsgen > overview > Html cells |
Adding formatting to cells is quite tedious as it involves learning an object model and every single of the 30+ properties of a cell's formatting takes a line of code to add.
Of course, you can cut the time spent by simply doing formattings by hand in Excel, and then use the automatic source code generator which is part of xlsgen, as it spits out the corresponding source code in the programming language of your choice.
That is all fine, but the fact remains there is still something new and specific to learn, even though formatting cells is not rocket science and thus should follow some formatting standard.
Can you guess a programming language which deals with this kind of stuff?
HTML, of course!
So what if xlsgen exposed the ability to read and write cells with just Html markup ? Would not that make it possible for web developers to use xlsgen without having to learn much?.
Html strings is a feature that lets you read and write numbers, strings, dates and formulas using Html markup. It's a very concise and convenient model. Here are a couple examples.
Java code |
worksheet.getCell(4,1).putHtmlLabel("<b>bold<i> and<br>italic</i> text</b>stop"); worksheet.getCell(7,1).putHtmlLabel("<font orientation=32 color=\"00FF00\">text</font>); worksheet.getCell(12,1).putHtmlLabel("<font style=\"background-color : #FFCCAA;fill-pattern:darkHorizontal\">text</font>); worksheet.getCell(2,2).putHtmlFloat("<font style=\"border-width:dashed;border-color: #FFCCAA\">-3.14159265361</font>); worksheet.getCell(3,2).putHtmlDate("<font style=\"border-bottom-width:double;border-bottom-color: black\" format=\"dddd/mm/yyyy\" autofit=true>11 Jan 2007</font>); worksheet.getCell(4,2).putHtmlNumber("<font format=\"# ##0.000\" style=\"background-color:DarkSalmon\">1</font>); worksheet.getCell(6,2).putHtmlFormula("<font style=\"background-color:GreenYellow\">=SUM(B4:B5)</font>"); |
VB code |
worksheet.Cell(4,1).HtmlLabel = "<b>bold<i> and<br>italic</i> text</b>stop"; worksheet.Cell(7,1).HtmlLabel = "<font orientation=32 color=""00FF00"">text</font>"; worksheet.Cell(12,1).HtmlLabel= "<font style=""background-color : #FFCCAA;fill-pattern:darkHorizontal"">text</font>"; worksheet.Cell(2,2).HtmlFloat = "<font style=""border-width:dashed;border-color: #FFCCAA"">-3.14159265361</font>"; worksheet.Cell(3,2).HtmlDate = "<font style=""border-bottom-width:double;border-bottom-color: black"" format=""dddd/mm/yyyy"" autofit=true>11 Jan 2007</font>"; worksheet.Cell(4,2).HtmlNumber = "<font format=""# ##0.000"" style=""background-color:DarkSalmon"">1</font>"; worksheet.Cell(6,2).HtmlFormula = "<font style=""background-color:GreenYellow"">=SUM(B4:B5)</font>"; |
C# code |
worksheet.get_Cell(4,1).HtmlLabel = "<b>bold<i> and<br>italic</i> text</b>stop"; worksheet.get_Cell(7,1).HtmlLabel = "<font orientation=32 color=\"00FF00\">text</font>"; worksheet.get_Cell(12,1).HtmlLabel= "<font style=\"background-color : #FFCCAA;fill-pattern:darkHorizontal\">text</font>"; worksheet.get_Cell(2,2).HtmlFloat = "<font style=\"border-width:dashed;border-color: #FFCCAA\">-3.14159265361</font>"; worksheet.get_Cell(3,2).HtmlDate = "<font style=\"border-bottom-width:double;border-bottom-color: black\" format=\"dddd/mm/yyyy\" autofit=true>11 Jan 2007</font>"; worksheet.get_Cell(4,2).HtmlNumber = "<font format=\"# ##0.000\" style=\"background-color:DarkSalmon\">1</font>"; worksheet.get_Cell(6,2).HtmlFormula = "<font style=\"background-color:GreenYellow\">=SUM(B4:B5)</font>"; |
C++ code |
worksheet->Cell[4][1]->HtmlLabel = L"<b>bold<i> and<br>italic</i> text</b>stop"; worksheet->Cell[7][1]->HtmlLabel = L"<font orientation=32 color=\"00FF00\">text</font>"; worksheet->Cell[12][1]->HtmlLabel= L"<font style=\"background-color : #FFCCAA;fill-pattern:darkHorizontal\">text</font>"; worksheet->Cell[2][2]->HtmlFloat = L"<font style=\"border-width:dashed;border-color: #FFCCAA\">-3.14159265361</font>"; worksheet->Cell[3][2]->HtmlDate = L"<font style=\"border-bottom-width:double;border-bottom-color: black\" format=\"dddd/mm/yyyy\" autofit=true>11 Jan 2007</font>"; worksheet->Cell[4][2]->HtmlNumber = L"<font format=\"# ##0.000\" style=\"background-color:DarkSalmon\">1</font>"; worksheet->Cell[6][2]->HtmlFormula = L"<font style=\"background-color:GreenYellow\">=SUM(B4:B5)</font>"; |
Here is an example of screen capture of cells resulting from statements like this :
Read/write methods are available from the IXlsCell interface. The IXlsCell interface is available from the IXlsWorksheet interface.
Methods include reading and writing litterals such as numbers, floats, dates and strings.
There are also methods to read and write formulas. It's a convenient way to read or create formulas complete with their associated formatting. Of course, just like regular formula creation, the formula language is English by default, and you can set a different formula language. See formulas for more info.
If you are not sure about the Html markup, take a look at the reference sheet below, also you can always use the source code generator which creates source code that, depends on your choice, uses the object model interfaces, or plain Html.
Tag | Attribute | Attribute value |
B | ||
I | ||
U | ||
STRIKE | ||
SUP | ||
SUB | ||
H1 | ||
H2 | ||
H3 | ||
H4 | ||
H5 | ||
FONT | color | 24-bit RGB color such as #FF0000, or any the known html color names (red, black, ...) |
FONT | size | font height in pixels |
FONT | name | font name |
FONT | orientation | Any orientation angle in degrees, or "vertical" for a text with vertical layout. |
FONT | indent | integer value. |
FONT | shrinktofit | true or false |
FONT | align | horizontal alignmentgeneral |
FONT | valign | vertical alignmentgeneral |
FONT | rtl | right-to-left boolean : true or false |
FONT | format | string representing a number format |
FONT | width | width of cell in pixels |
FONT | height | height of cell in pixels |
FONT | autofit | true to autofit the column |
FONT | locked | true or false |
FONT | hidden | true or false |
FONT | underline | none |
Any tag | style | background-color: color |
Any tag | style | foreground-color: color |
Any tag | style | fill-pattern:none |
Any tag | style | fill-gradient:gradientstyle_horizontal0 |
Any tag | style | fill-gradient-color1: first color of the gradient fill |
Any tag | style | fill-gradient-color2: second color of the gradient fill |
Any tag | style | border-color: color of all 4 borders |
Any tag | style | border-width: style of all 4 borders |
Any tag | style | border-top-color: color |
Any tag | style | border-top-width:
|
Any tag | style | border-bottom-color: color |
Any tag | style | border-bottom-width: see border-top-width |
Any tag | style | border-left-color: color |
Any tag | style | border-left-width: see border-top-width |
Any tag | style | border-right-color: color |
Any tag | style | border-right-width: see border-top-width |
Any tag | style | border-diagonalup-color: color |
Any tag | style | border-diagonalup-width: see border-top-width |
Any tag | style | border-diagonaldown-color: color |
Any tag | style | border-diagonaldown-width: see border-top-width |
Any tag | format | number format (can be used with numbers and dates) |
Any tag | wrap | true or false |
BR | line break |
xlsgen documentation. © ARsT Design all rights reserved.