Skip to content

Commit

Permalink
Merge pull request qax-os#464 from mlh758/fix-462
Browse files Browse the repository at this point in the history
Fixed qax-os#462 Handle multi row inline strings
  • Loading branch information
xuri authored Aug 10, 2019
2 parents 23c8d1e + acd7642 commit adc4aed
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
## Introduction

Excelize is a library written in pure Go providing a set of functions that allow you to write to and read from XLSX files. Supports reading and writing XLSX file generated by Microsoft Excel™ 2007 and later.
Supports saving a file without losing original charts of XLSX. This library needs Go version 1.8 or later. The full API docs can be seen using go's built-in documentation tool, or online at [godoc.org](https://godoc.org/github.com/360EntSecGroup-Skylar/excelize) and [docs reference](https://xuri.me/excelize/).
Supports saving a file without losing original charts of XLSX. This library needs Go version 1.10 or later. The full API docs can be seen using go's built-in documentation tool, or online at [godoc.org](https://godoc.org/github.com/360EntSecGroup-Skylar/excelize) and [docs reference](https://xuri.me/excelize/).

## Basic Usage

Expand Down
5 changes: 5 additions & 0 deletions excelize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,11 @@ func TestSharedStrings(t *testing.T) {
t.FailNow()
}
assert.Equal(t, "A", rows[0][0])
rows, err = f.GetRows("Sheet2")
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, "Test Weight (Kgs)", rows[0][0])
}

func TestSetSheetRow(t *testing.T) {
Expand Down
11 changes: 2 additions & 9 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,11 @@ func (xlsx *xlsxC) getValueFrom(f *File, d *xlsxSST) (string, error) {
case "s":
xlsxSI := 0
xlsxSI, _ = strconv.Atoi(xlsx.V)
if len(d.SI[xlsxSI].R) > 0 {
value := ""
for _, v := range d.SI[xlsxSI].R {
value += v.T
}
return value, nil
}
return f.formattedValue(xlsx.S, d.SI[xlsxSI].T), nil
return f.formattedValue(xlsx.S, d.SI[xlsxSI].String()), nil
case "str":
return f.formattedValue(xlsx.S, xlsx.V), nil
case "inlineStr":
return f.formattedValue(xlsx.S, xlsx.IS.T), nil
return f.formattedValue(xlsx.S, xlsx.IS.String()), nil
default:
return f.formattedValue(xlsx.S, xlsx.V), nil
}
Expand Down
Binary file modified test/SharedStrings.xlsx
Binary file not shown.
16 changes: 15 additions & 1 deletion xmlSharedStrings.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

package excelize

import "encoding/xml"
import (
"encoding/xml"
"strings"
)

// xlsxSST directly maps the sst element from the namespace
// http://schemas.openxmlformats.org/spreadsheetml/2006/main. String values may
Expand All @@ -33,6 +36,17 @@ type xlsxSI struct {
R []xlsxR `xml:"r"`
}

func (x xlsxSI) String() string {
if len(x.R) > 0 {
var rows strings.Builder
for _, s := range x.R {
rows.WriteString(s.T)
}
return rows.String()
}
return x.T
}

// xlsxR directly maps the r element from the namespace
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
// not checked this for completeness - it does as much as I need.
Expand Down
14 changes: 4 additions & 10 deletions xmlWorksheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

package excelize

import "encoding/xml"
import (
"encoding/xml"
)

// xlsxWorksheet directly maps the worksheet element in the namespace
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
Expand Down Expand Up @@ -424,18 +426,10 @@ type xlsxC struct {
T string `xml:"t,attr,omitempty"` // Type.
F *xlsxF `xml:"f,omitempty"` // Formula
V string `xml:"v,omitempty"` // Value
IS *xlsxIS `xml:"is"`
IS *xlsxSI `xml:"is"`
XMLSpace xml.Attr `xml:"space,attr,omitempty"`
}

// xlsxIS directly maps the t element. Cell containing an (inline) rich
// string, i.e., one not in the shared string table. If this cell type is
// used, then the cell value is in the is element rather than the v element in
// the cell (c element).
type xlsxIS struct {
T string `xml:"t"`
}

// xlsxF directly maps the f element in the namespace
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - currently I have
// not checked it for completeness - it does as much as I need.
Expand Down

0 comments on commit adc4aed

Please sign in to comment.