diff options
author | Ri Xu <xuri.me@gmail.com> | 2017-03-28 11:48:09 +0800 |
---|---|---|
committer | Ri Xu <xuri.me@gmail.com> | 2017-03-28 11:48:09 +0800 |
commit | bee487c445768b8afd15bbfa7caa4d8427e4c880 (patch) | |
tree | 4b31fc11a593ad1a02e7f0726aa1d6fe6895fa97 | |
parent | b6254209fe56c84a9ac99805ce3dd877a494e134 (diff) |
Leading space(s) character in cell value detection added. Related issue #32.
-rw-r--r-- | excelize.go | 9 | ||||
-rw-r--r-- | excelize_test.go | 2 | ||||
-rw-r--r-- | xmlDrawing.go | 1 | ||||
-rw-r--r-- | xmlWorksheet.go | 7 |
4 files changed, 15 insertions, 4 deletions
diff --git a/excelize.go b/excelize.go index 1fbfcc2..e723cb5 100644 --- a/excelize.go +++ b/excelize.go @@ -161,6 +161,15 @@ func (f *File) SetCellStr(sheet, axis, value string) { completeRow(xlsx, rows, cell) completeCol(xlsx, rows, cell) + // Leading space(s) character detection. + if len(value) > 0 { + if value[0] == 32 { + xlsx.SheetData.Row[xAxis].C[yAxis].XMLSpace = xml.Attr{ + Name: xml.Name{Space: NameSpaceXML, Local: "space"}, + Value: "preserve", + } + } + } xlsx.SheetData.Row[xAxis].C[yAxis].T = "str" xlsx.SheetData.Row[xAxis].C[yAxis].V = value } diff --git a/excelize_test.go b/excelize_test.go index 31b2aa1..0ce1e54 100644 --- a/excelize_test.go +++ b/excelize_test.go @@ -53,7 +53,7 @@ func TestOpenFile(t *testing.T) { xlsx.GetCellValue("Sheet2", "D11") xlsx.GetCellValue("Sheet2", "D12") // Test SetCellValue function. - xlsx.SetCellValue("Sheet2", "F1", "Hello") + xlsx.SetCellValue("Sheet2", "F1", " Hello") xlsx.SetCellValue("Sheet2", "G1", []byte("World")) xlsx.SetCellValue("Sheet2", "F2", 42) xlsx.SetCellValue("Sheet2", "F2", int8(42)) diff --git a/xmlDrawing.go b/xmlDrawing.go index 3540a38..94fcc97 100644 --- a/xmlDrawing.go +++ b/xmlDrawing.go @@ -9,6 +9,7 @@ const ( SourceRelationshipWorkSheet = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" NameSpaceDrawingML = "http://schemas.openxmlformats.org/drawingml/2006/main" NameSpaceSpreadSheetDrawing = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" + NameSpaceXML = "http://www.w3.org/XML/1998/namespace" ) // xlsxCNvPr directly maps the cNvPr (Non-Visual Drawing Properties). This diff --git a/xmlWorksheet.go b/xmlWorksheet.go index 5919edb..f7188b6 100644 --- a/xmlWorksheet.go +++ b/xmlWorksheet.go @@ -302,9 +302,10 @@ type xlsxC struct { R string `xml:"r,attr"` // Cell ID, e.g. A1 S int `xml:"s,attr,omitempty"` // Style reference. // Str string `xml:"str,attr,omitempty"` // Style reference. - T string `xml:"t,attr,omitempty"` // Type. - F *xlsxF `xml:"f,omitempty"` // Formula - V string `xml:"v,omitempty"` // Value + T string `xml:"t,attr,omitempty"` // Type. + F *xlsxF `xml:"f,omitempty"` // Formula + V string `xml:"v,omitempty"` // Value + XMLSpace xml.Attr `xml:"space,attr,omitempty"` } // xlsxF directly maps the f element in the namespace |