提交 bee487c4 编写于 作者: xurime's avatar xurime

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

上级 b6254209
......@@ -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
}
......
......@@ -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))
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册