summaryrefslogtreecommitdiff
path: root/cell_test.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2020-04-06 00:23:27 +0800
committerxuri <xuri.me@gmail.com>2020-04-06 00:23:27 +0800
commit66d0272f6af59b5f0c97a304379a795420a43e8b (patch)
tree2d7f059160e6bb4cb3dc57964c87f0a200a519c8 /cell_test.go
parent0f2a9053246c3ae45e6c7ba911a1fb135664abdf (diff)
Resolve #172, init rich text support
Diffstat (limited to 'cell_test.go')
-rw-r--r--cell_test.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/cell_test.go b/cell_test.go
index 1efbc5a..f46b4b9 100644
--- a/cell_test.go
+++ b/cell_test.go
@@ -141,3 +141,84 @@ func TestOverflowNumericCell(t *testing.T) {
// GOARCH=amd64 - all ok; GOARCH=386 - actual: "-2147483648"
assert.Equal(t, "8595602512225", val, "A1 should be 8595602512225")
}
+
+func TestSetCellRichText(t *testing.T) {
+ f := NewFile()
+ assert.NoError(t, f.SetRowHeight("Sheet1", 1, 35))
+ assert.NoError(t, f.SetColWidth("Sheet1", "A", "A", 44))
+ richTextRun := []RichTextRun{
+ {
+ Text: "blod",
+ Font: &Font{
+ Bold: true,
+ Color: "2354e8",
+ Family: "Times New Roman",
+ },
+ },
+ {
+ Text: " and ",
+ Font: &Font{
+ Family: "Times New Roman",
+ },
+ },
+ {
+ Text: "italic ",
+ Font: &Font{
+ Bold: true,
+ Color: "e83723",
+ Italic: true,
+ Family: "Times New Roman",
+ },
+ },
+ {
+ Text: "text with color and font-family,",
+ Font: &Font{
+ Bold: true,
+ Color: "2354e8",
+ Family: "Times New Roman",
+ },
+ },
+ {
+ Text: "\r\nlarge text with ",
+ Font: &Font{
+ Size: 14,
+ Color: "ad23e8",
+ },
+ },
+ {
+ Text: "strike",
+ Font: &Font{
+ Color: "e89923",
+ Strike: true,
+ },
+ },
+ {
+ Text: " and ",
+ Font: &Font{
+ Size: 14,
+ Color: "ad23e8",
+ },
+ },
+ {
+ Text: "underline.",
+ Font: &Font{
+ Color: "23e833",
+ Underline: "single",
+ },
+ },
+ }
+ assert.NoError(t, f.SetCellRichText("Sheet1", "A1", richTextRun))
+ assert.NoError(t, f.SetCellRichText("Sheet1", "A2", richTextRun))
+ style, err := f.NewStyle(&Style{
+ Alignment: &Alignment{
+ WrapText: true,
+ },
+ })
+ assert.NoError(t, err)
+ assert.NoError(t, f.SetCellStyle("Sheet1", "A1", "A1", style))
+ assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetCellRichText.xlsx")))
+ // Test set cell rich text on not exists worksheet
+ assert.EqualError(t, f.SetCellRichText("SheetN", "A1", richTextRun), "sheet SheetN is not exist")
+ // Test set cell rich text with illegal cell coordinates
+ assert.EqualError(t, f.SetCellRichText("Sheet1", "A", richTextRun), `cannot convert cell "A" to coordinates: invalid cell name "A"`)
+}