From 2132de1a0848794a49225470e42f91e9c34bb6da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Thu, 14 Jun 2018 17:00:00 +0200 Subject: Extract WriteTo method (see io.WriterTo) to expose bytes written Extract a WriteTo() method (see io.WriterTo) that exposes the count of bytes written and rewrite Write() to use it. --- file.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'file.go') diff --git a/file.go b/file.go index 39798e1..4f06d1e 100644 --- a/file.go +++ b/file.go @@ -60,6 +60,12 @@ func (f *File) SaveAs(name string) error { // Write provides function to write to an io.Writer. func (f *File) Write(w io.Writer) error { + _, err := f.WriteTo(w) + return err +} + +// WriteTo implements io.WriterTo to write the file. +func (f *File) WriteTo(w io.Writer) (int64, error) { buf := new(bytes.Buffer) zw := zip.NewWriter(buf) f.contentTypesWriter() @@ -70,21 +76,17 @@ func (f *File) Write(w io.Writer) error { for path, content := range f.XLSX { fi, err := zw.Create(path) if err != nil { - return err + return 0, err } _, err = fi.Write(content) if err != nil { - return err + return 0, err } } err := zw.Close() if err != nil { - return err - } - - if _, err := buf.WriteTo(w); err != nil { - return err + return 0, err } - return nil + return buf.WriteTo(w) } -- cgit v1.2.1 From d6468fc114217678e8bc8b4324fd6185794e0182 Mon Sep 17 00:00:00 2001 From: xuri Date: Sat, 7 Jul 2018 15:59:48 +0800 Subject: - Initialize theme support; - RGBA, HSL color convert has been added; - go test updated --- file.go | 1 + 1 file changed, 1 insertion(+) (limited to 'file.go') diff --git a/file.go b/file.go index 4f06d1e..2b1f1e0 100644 --- a/file.go +++ b/file.go @@ -36,6 +36,7 @@ func NewFile() *File { f.WorkBookRels = f.workbookRelsReader() f.Sheet["xl/worksheets/sheet1.xml"] = f.workSheetReader("Sheet1") f.sheetMap["Sheet1"] = "xl/worksheets/sheet1.xml" + f.Theme = f.themeReader() return f } -- cgit v1.2.1 From ec37b114c3b704a84c66fcf3e135c9df88ffb24d Mon Sep 17 00:00:00 2001 From: xuri Date: Mon, 6 Aug 2018 10:21:24 +0800 Subject: Fixes #256 and format document. --- file.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'file.go') diff --git a/file.go b/file.go index 2b1f1e0..a45fc28 100644 --- a/file.go +++ b/file.go @@ -8,7 +8,7 @@ import ( "os" ) -// NewFile provides function to create new file by default template. For +// NewFile provides a function to create new file by default template. For // example: // // xlsx := NewFile() @@ -40,7 +40,7 @@ func NewFile() *File { return f } -// Save provides function to override the xlsx file with origin path. +// Save provides a function to override the xlsx file with origin path. func (f *File) Save() error { if f.Path == "" { return fmt.Errorf("No path defined for file, consider File.WriteTo or File.Write") @@ -48,8 +48,8 @@ func (f *File) Save() error { return f.SaveAs(f.Path) } -// SaveAs provides function to create or update to an xlsx file at the provided -// path. +// SaveAs provides a function to create or update to an xlsx file at the +// provided path. func (f *File) SaveAs(name string) error { file, err := os.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666) if err != nil { @@ -59,7 +59,7 @@ func (f *File) SaveAs(name string) error { return f.Write(file) } -// Write provides function to write to an io.Writer. +// Write provides a function to write to an io.Writer. func (f *File) Write(w io.Writer) error { _, err := f.WriteTo(w) return err -- cgit v1.2.1 From b4a6e61ec34d4a0db1110907cc969f0d7d38991a Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 12 Sep 2018 15:47:56 +0800 Subject: Fix golint errors under confidence 0.1 --- file.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'file.go') diff --git a/file.go b/file.go index a45fc28..76ef986 100644 --- a/file.go +++ b/file.go @@ -1,3 +1,11 @@ +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. +// +// Copyright 2016 - 2018 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. package excelize import ( @@ -43,7 +51,7 @@ func NewFile() *File { // Save provides a function to override the xlsx file with origin path. func (f *File) Save() error { if f.Path == "" { - return fmt.Errorf("No path defined for file, consider File.WriteTo or File.Write") + return fmt.Errorf("no path defined for file, consider File.WriteTo or File.Write") } return f.SaveAs(f.Path) } -- cgit v1.2.1 From 2f146c923ccd19c5ecc1f732b5b09d591fb935a3 Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 14 Sep 2018 00:35:47 +0800 Subject: Comments style changed. --- file.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'file.go') diff --git a/file.go b/file.go index 76ef986..350f753 100644 --- a/file.go +++ b/file.go @@ -1,11 +1,13 @@ -// Package excelize providing a set of functions that allow you to write to -// and read from XLSX files. Support reads and writes XLSX file generated by -// Microsoft Excel™ 2007 and later. Support save file without losing original -// charts of XLSX. This library needs Go version 1.8 or later. -// -// Copyright 2016 - 2018 The excelize Authors. All rights reserved. Use of -// this source code is governed by a BSD-style license that can be found in -// the LICENSE file. +/* +Package excelize providing a set of functions that allow you to write to +and read from XLSX files. Support reads and writes XLSX file generated by +Microsoft Excel™ 2007 and later. Support save file without losing original +charts of XLSX. This library needs Go version 1.8 or later. + +Copyright 2016 - 2018 The excelize Authors. All rights reserved. Use of +this source code is governed by a BSD-style license that can be found in +the LICENSE file. +*/ package excelize import ( -- cgit v1.2.1 From 13a9769cc5bde486c52d8e45661ff8108cd786ae Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 14 Sep 2018 00:44:23 +0800 Subject: Comments style changed. --- file.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'file.go') diff --git a/file.go b/file.go index 350f753..582228f 100644 --- a/file.go +++ b/file.go @@ -1,13 +1,11 @@ -/* -Package excelize providing a set of functions that allow you to write to -and read from XLSX files. Support reads and writes XLSX file generated by -Microsoft Excel™ 2007 and later. Support save file without losing original -charts of XLSX. This library needs Go version 1.8 or later. - -Copyright 2016 - 2018 The excelize Authors. All rights reserved. Use of -this source code is governed by a BSD-style license that can be found in -the LICENSE file. -*/ +// Copyright 2016 - 2018 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excel™ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.8 or later. package excelize import ( -- cgit v1.2.1 From 3e004d900b103379c2d62657a3070de4a2e8585a Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 14 Sep 2018 00:58:48 +0800 Subject: Comments style changed. --- file.go | 1 + 1 file changed, 1 insertion(+) (limited to 'file.go') diff --git a/file.go b/file.go index 582228f..5bfed39 100644 --- a/file.go +++ b/file.go @@ -6,6 +6,7 @@ // and read from XLSX files. Support reads and writes XLSX file generated by // Microsoft Excel™ 2007 and later. Support save file without losing original // charts of XLSX. This library needs Go version 1.8 or later. + package excelize import ( -- cgit v1.2.1