summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRi Xu <xuri.me@gmail.com>2017-10-31 16:33:36 +0800
committerRi Xu <xuri.me@gmail.com>2017-10-31 16:33:36 +0800
commitf10ee929d0818f6327f33c7813eaa9a318555cc3 (patch)
tree7a0e4035fee8963eeec925bb6f2d5258e88379b5
parentebafbdde73e3e0498e547a2bd862552d9e304701 (diff)
- Bugfix: use sheet name in func `AddPicture`, relate issue #142;
- godoc updated
-rw-r--r--cell.go8
-rw-r--r--chart.go2
-rw-r--r--col.go4
-rw-r--r--excelize.go2
-rw-r--r--excelize_test.go3
-rw-r--r--picture.go6
-rw-r--r--sheet.go1
7 files changed, 15 insertions, 11 deletions
diff --git a/cell.go b/cell.go
index c4edf71..f5394a1 100644
--- a/cell.go
+++ b/cell.go
@@ -85,9 +85,9 @@ func (f *File) SetCellValue(sheet, axis string, value interface{}) {
}
// GetCellValue provides function to get formatted value from cell by given
-// sheet index and axis in XLSX file. If it is possible to apply a format to the
-// cell value, it will do so, if not then an error will be returned, along with
-// the raw value of the cell.
+// worksheet name and axis in XLSX file. If it is possible to apply a format to
+// the cell value, it will do so, if not then an error will be returned, along
+// with the raw value of the cell.
func (f *File) GetCellValue(sheet, axis string) string {
xlsx := f.workSheetReader(sheet)
axis = f.mergeCellsParser(xlsx, axis)
@@ -191,7 +191,7 @@ func (f *File) GetCellFormula(sheet, axis string) string {
}
// SetCellFormula provides function to set cell formula by given string and
-// sheet index.
+// worksheet name.
func (f *File) SetCellFormula(sheet, axis, formula string) {
xlsx := f.workSheetReader(sheet)
axis = f.mergeCellsParser(xlsx, axis)
diff --git a/chart.go b/chart.go
index e6cb94f..9ddff9d 100644
--- a/chart.go
+++ b/chart.go
@@ -238,7 +238,7 @@ func (f *File) countCharts() int {
}
// prepareDrawing provides function to prepare drawing ID and XML by given
-// drawingID, worksheet index and default drawingXML.
+// drawingID, worksheet name and default drawingXML.
func (f *File) prepareDrawing(xlsx *xlsxWorksheet, drawingID int, sheet, drawingXML string) (int, string) {
sheetRelationshipsDrawingXML := "../drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
if xlsx.Drawing != nil {
diff --git a/col.go b/col.go
index da2a004..51ad8a7 100644
--- a/col.go
+++ b/col.go
@@ -15,7 +15,7 @@ const (
)
// GetColVisible provides a function to get visible of a single column by given
-// worksheet index and column name. For example, get visible state of column D
+// worksheet name and column name. For example, get visible state of column D
// in Sheet1:
//
// xlsx.GetColVisible("Sheet1", "D")
@@ -36,7 +36,7 @@ func (f *File) GetColVisible(sheet, column string) bool {
}
// SetColVisible provides a function to set visible of a single column by given
-// worksheet index and column name. For example, hide column D in Sheet1:
+// worksheet name and column name. For example, hide column D in Sheet1:
//
// xlsx.SetColVisible("Sheet1", "D", false)
//
diff --git a/excelize.go b/excelize.go
index 73c6eda..0056e79 100644
--- a/excelize.go
+++ b/excelize.go
@@ -78,7 +78,7 @@ func (f *File) setDefaultTimeStyle(sheet, axis string) {
}
// workSheetReader provides function to get the pointer to the structure after
-// deserialization by given worksheet index.
+// deserialization by given worksheet name.
func (f *File) workSheetReader(sheet string) *xlsxWorksheet {
name, ok := f.sheetMap[trimSheetName(sheet)]
if !ok {
diff --git a/excelize_test.go b/excelize_test.go
index 7e88271..f11b182 100644
--- a/excelize_test.go
+++ b/excelize_test.go
@@ -50,7 +50,7 @@ func TestOpenFile(t *testing.T) {
xlsx.SetActiveSheet(2)
// Test get cell formula with given rows number.
xlsx.GetCellFormula("Sheet1", "B19")
- // Test get cell formula with illegal worksheet index.
+ // Test get cell formula with illegal worksheet name.
xlsx.GetCellFormula("Sheet2", "B20")
// Test get cell formula with illegal rows number.
xlsx.GetCellFormula("Sheet1", "B20")
@@ -638,6 +638,7 @@ func TestGetPicture(t *testing.T) {
xlsx.getDrawingRelationships("xl/worksheets/_rels/sheet1.xml.rels", "rId8")
xlsx.getDrawingRelationships("", "")
xlsx.getSheetRelationshipsTargetByID("", "")
+ xlsx.deleteSheetRelationships("", "")
}
func TestSheetVisibility(t *testing.T) {
diff --git a/picture.go b/picture.go
index a7ff524..ba8eef1 100644
--- a/picture.go
+++ b/picture.go
@@ -364,7 +364,11 @@ func (f *File) addContentTypePart(index int, contentType string) {
// value in xl/worksheets/_rels/sheet%d.xml.rels by given worksheet name and
// relationship index.
func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string {
- var rels = "xl/worksheets/_rels/" + strings.ToLower(sheet) + ".xml.rels"
+ name, ok := f.sheetMap[trimSheetName(sheet)]
+ if !ok {
+ name = strings.ToLower(sheet) + ".xml"
+ }
+ var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
var sheetRels xlsxWorkbookRels
xml.Unmarshal([]byte(f.readXML(rels)), &sheetRels)
for _, v := range sheetRels.Relationships {
diff --git a/sheet.go b/sheet.go
index 2725214..e17aef9 100644
--- a/sheet.go
+++ b/sheet.go
@@ -313,7 +313,6 @@ func (f *File) GetSheetIndex(name string) int {
//
// xlsx, err := excelize.OpenFile("./Workbook.xlsx")
// if err != nil {
-// fmt.Println(err)
// return
// }
// for index, name := range xlsx.GetSheetMap() {