Skip to content

Commit f10ee92

Browse files
committed
- Bugfix: use sheet name in func AddPicture, relate issue qax-os#142;
- godoc updated
1 parent ebafbdd commit f10ee92

File tree

7 files changed

+15
-11
lines changed

7 files changed

+15
-11
lines changed

cell.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ func (f *File) SetCellValue(sheet, axis string, value interface{}) {
8585
}
8686

8787
// GetCellValue provides function to get formatted value from cell by given
88-
// sheet index and axis in XLSX file. If it is possible to apply a format to the
89-
// cell value, it will do so, if not then an error will be returned, along with
90-
// the raw value of the cell.
88+
// worksheet name and axis in XLSX file. If it is possible to apply a format to
89+
// the cell value, it will do so, if not then an error will be returned, along
90+
// with the raw value of the cell.
9191
func (f *File) GetCellValue(sheet, axis string) string {
9292
xlsx := f.workSheetReader(sheet)
9393
axis = f.mergeCellsParser(xlsx, axis)
@@ -191,7 +191,7 @@ func (f *File) GetCellFormula(sheet, axis string) string {
191191
}
192192

193193
// SetCellFormula provides function to set cell formula by given string and
194-
// sheet index.
194+
// worksheet name.
195195
func (f *File) SetCellFormula(sheet, axis, formula string) {
196196
xlsx := f.workSheetReader(sheet)
197197
axis = f.mergeCellsParser(xlsx, axis)

chart.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func (f *File) countCharts() int {
238238
}
239239

240240
// prepareDrawing provides function to prepare drawing ID and XML by given
241-
// drawingID, worksheet index and default drawingXML.
241+
// drawingID, worksheet name and default drawingXML.
242242
func (f *File) prepareDrawing(xlsx *xlsxWorksheet, drawingID int, sheet, drawingXML string) (int, string) {
243243
sheetRelationshipsDrawingXML := "../drawings/drawing" + strconv.Itoa(drawingID) + ".xml"
244244
if xlsx.Drawing != nil {

col.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const (
1515
)
1616

1717
// GetColVisible provides a function to get visible of a single column by given
18-
// worksheet index and column name. For example, get visible state of column D
18+
// worksheet name and column name. For example, get visible state of column D
1919
// in Sheet1:
2020
//
2121
// xlsx.GetColVisible("Sheet1", "D")
@@ -36,7 +36,7 @@ func (f *File) GetColVisible(sheet, column string) bool {
3636
}
3737

3838
// SetColVisible provides a function to set visible of a single column by given
39-
// worksheet index and column name. For example, hide column D in Sheet1:
39+
// worksheet name and column name. For example, hide column D in Sheet1:
4040
//
4141
// xlsx.SetColVisible("Sheet1", "D", false)
4242
//

excelize.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (f *File) setDefaultTimeStyle(sheet, axis string) {
7878
}
7979

8080
// workSheetReader provides function to get the pointer to the structure after
81-
// deserialization by given worksheet index.
81+
// deserialization by given worksheet name.
8282
func (f *File) workSheetReader(sheet string) *xlsxWorksheet {
8383
name, ok := f.sheetMap[trimSheetName(sheet)]
8484
if !ok {

excelize_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestOpenFile(t *testing.T) {
5050
xlsx.SetActiveSheet(2)
5151
// Test get cell formula with given rows number.
5252
xlsx.GetCellFormula("Sheet1", "B19")
53-
// Test get cell formula with illegal worksheet index.
53+
// Test get cell formula with illegal worksheet name.
5454
xlsx.GetCellFormula("Sheet2", "B20")
5555
// Test get cell formula with illegal rows number.
5656
xlsx.GetCellFormula("Sheet1", "B20")
@@ -638,6 +638,7 @@ func TestGetPicture(t *testing.T) {
638638
xlsx.getDrawingRelationships("xl/worksheets/_rels/sheet1.xml.rels", "rId8")
639639
xlsx.getDrawingRelationships("", "")
640640
xlsx.getSheetRelationshipsTargetByID("", "")
641+
xlsx.deleteSheetRelationships("", "")
641642
}
642643

643644
func TestSheetVisibility(t *testing.T) {

picture.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,11 @@ func (f *File) addContentTypePart(index int, contentType string) {
364364
// value in xl/worksheets/_rels/sheet%d.xml.rels by given worksheet name and
365365
// relationship index.
366366
func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string {
367-
var rels = "xl/worksheets/_rels/" + strings.ToLower(sheet) + ".xml.rels"
367+
name, ok := f.sheetMap[trimSheetName(sheet)]
368+
if !ok {
369+
name = strings.ToLower(sheet) + ".xml"
370+
}
371+
var rels = "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
368372
var sheetRels xlsxWorkbookRels
369373
xml.Unmarshal([]byte(f.readXML(rels)), &sheetRels)
370374
for _, v := range sheetRels.Relationships {

sheet.go

-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ func (f *File) GetSheetIndex(name string) int {
313313
//
314314
// xlsx, err := excelize.OpenFile("./Workbook.xlsx")
315315
// if err != nil {
316-
// fmt.Println(err)
317316
// return
318317
// }
319318
// for index, name := range xlsx.GetSheetMap() {

0 commit comments

Comments
 (0)