Leading space(s) character in cell value detection added. Related issue #32.

This commit is contained in:
Ri Xu 2017-03-28 11:48:09 +08:00
parent b6254209fe
commit bee487c445
4 changed files with 15 additions and 4 deletions

View File

@ -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
}

View File

@ -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))

View File

@ -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

View File

@ -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