From 821632cf89422b9955160a3af7f28f05a12f70f8 Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 12 Jun 2019 08:10:33 +0800 Subject: Fix #424, refactor merged cells adjuster --- table.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'table.go') diff --git a/table.go b/table.go index f3819d3..3d8d402 100644 --- a/table.go +++ b/table.go @@ -115,29 +115,24 @@ func (f *File) addSheetTable(sheet string, rID int) { // addTable provides a function to add table by given worksheet name, // coordinate area and format set. -func (f *File) addTable(sheet, tableXML string, hcol, hrow, vcol, vrow, i int, formatSet *formatTable) error { +func (f *File) addTable(sheet, tableXML string, x1, y1, x2, y2, i int, formatSet *formatTable) error { // Correct the minimum number of rows, the table at least two lines. - if hrow == vrow { - vrow++ + if y1 == y2 { + y2++ } // Correct table reference coordinate area, such correct C1:B3 to B1:C3. - hcell, err := CoordinatesToCellName(hcol, hrow) + ref, err := f.coordinatesToAreaRef([]int{x1, y1, x2, y2}) if err != nil { return err } - vcell, err := CoordinatesToCellName(vcol, vrow) - if err != nil { - return err - } - ref := hcell + ":" + vcell var tableColumn []*xlsxTableColumn idx := 0 - for i := hcol; i <= vcol; i++ { + for i := x1; i <= x2; i++ { idx++ - cell, err := CoordinatesToCellName(i, hrow) + cell, err := CoordinatesToCellName(i, y1) if err != nil { return err } -- cgit v1.2.1 From 9c70d0ac868f66badf2663cc7b4b3c46d5411131 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 11 Aug 2019 00:36:14 +0800 Subject: Documentation updated, Go 1.10+ required --- table.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'table.go') diff --git a/table.go b/table.go index 3d8d402..45a1622 100644 --- a/table.go +++ b/table.go @@ -5,7 +5,7 @@ // 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. +// charts of XLSX. This library needs Go version 1.10 or later. package excelize -- cgit v1.2.1 From 8922f659788187afa6d0a5d3248e999c2c1bb846 Mon Sep 17 00:00:00 2001 From: xuri Date: Mon, 16 Sep 2019 01:17:35 +0800 Subject: Combine functions: workBookRelsWriter, drawingRelsWriter into relsWriter; drawingRelsReader, workbookRelsReader, workSheetRelsReader into relsReader; addDrawingRelationships, addSheetRelationships into addRels --- table.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'table.go') diff --git a/table.go b/table.go index 45a1622..d26f8fd 100644 --- a/table.go +++ b/table.go @@ -77,7 +77,9 @@ func (f *File) AddTable(sheet, hcell, vcell, format string) error { sheetRelationshipsTableXML := "../tables/table" + strconv.Itoa(tableID) + ".xml" tableXML := strings.Replace(sheetRelationshipsTableXML, "..", "xl", -1) // Add first table for given sheet. - rID := f.addSheetRelationships(sheet, SourceRelationshipTable, sheetRelationshipsTableXML, "") + sheetPath, _ := f.sheetMap[trimSheetName(sheet)] + sheetRels := "xl/worksheets/_rels/" + strings.TrimPrefix(sheetPath, "xl/worksheets/") + ".rels" + rID := f.addRels(sheetRels, SourceRelationshipTable, sheetRelationshipsTableXML, "") f.addSheetTable(sheet, rID) err = f.addTable(sheet, tableXML, hcol, hrow, vcol, vrow, tableID, formatSet) if err != nil { -- cgit v1.2.1 From 4e4a5b9b3e052d1694442515492792fb1aa74c5a Mon Sep 17 00:00:00 2001 From: xuri Date: Mon, 23 Dec 2019 00:07:40 +0800 Subject: Improve compatibility, fix workbook's rels ID calc error --- table.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'table.go') diff --git a/table.go b/table.go index d26f8fd..c5a704c 100644 --- a/table.go +++ b/table.go @@ -77,8 +77,7 @@ func (f *File) AddTable(sheet, hcell, vcell, format string) error { sheetRelationshipsTableXML := "../tables/table" + strconv.Itoa(tableID) + ".xml" tableXML := strings.Replace(sheetRelationshipsTableXML, "..", "xl", -1) // Add first table for given sheet. - sheetPath, _ := f.sheetMap[trimSheetName(sheet)] - sheetRels := "xl/worksheets/_rels/" + strings.TrimPrefix(sheetPath, "xl/worksheets/") + ".rels" + sheetRels := "xl/worksheets/_rels/" + strings.TrimPrefix(f.sheetMap[trimSheetName(sheet)], "xl/worksheets/") + ".rels" rID := f.addRels(sheetRels, SourceRelationshipTable, sheetRelationshipsTableXML, "") f.addSheetTable(sheet, rID) err = f.addTable(sheet, tableXML, hcol, hrow, vcol, vrow, tableID, formatSet) -- cgit v1.2.1 From 1666d04559d9f5b579ab7c850ccc95863c31bd25 Mon Sep 17 00:00:00 2001 From: xuri Date: Tue, 24 Dec 2019 01:09:28 +0800 Subject: optimization: checking error in unit tests --- table.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'table.go') diff --git a/table.go b/table.go index c5a704c..3d76690 100644 --- a/table.go +++ b/table.go @@ -139,7 +139,7 @@ func (f *File) addTable(sheet, tableXML string, x1, y1, x2, y2, i int, formatSet } name, _ := f.GetCellValue(sheet, cell) if _, err := strconv.Atoi(name); err == nil { - f.SetCellStr(sheet, cell, name) + _ = f.SetCellStr(sheet, cell, name) } if name == "" { name = "Column" + strconv.Itoa(idx) -- cgit v1.2.1 From 09485b3f9f0aefc58d51462aed65c2416205c591 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 29 Dec 2019 16:02:31 +0800 Subject: Improve code coverage unit tests --- table.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'table.go') diff --git a/table.go b/table.go index 3d76690..566238c 100644 --- a/table.go +++ b/table.go @@ -1,4 +1,4 @@ -// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// Copyright 2016 - 2020 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. // -- cgit v1.2.1 From e51aff2d9562bbfb290ef76a948facb6d4660eff Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 7 Feb 2020 00:25:01 +0800 Subject: Resolve #570, flat columns for the column's operation --- table.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'table.go') diff --git a/table.go b/table.go index 566238c..55901cd 100644 --- a/table.go +++ b/table.go @@ -39,8 +39,10 @@ func parseFormatTableSet(formatSet string) (*formatTable, error) { // // err := f.AddTable("Sheet2", "F2", "H6", `{"table_name":"table","table_style":"TableStyleMedium2", "show_first_column":true,"show_last_column":true,"show_row_stripes":false,"show_column_stripes":true}`) // -// Note that the table at least two lines include string type header. Multiple -// tables coordinate areas can't have an intersection. +// Note that the table must be at least two lines including the header. The +// header cells must contain strings and must be unique, and must set the +// header row data of the table before calling the AddTable function. Multiple +// tables coordinate areas that can't have an intersection. // // table_name: The name of the table, in the same worksheet name of the table should be unique // -- cgit v1.2.1 From 9baa1bbc9865bee1b3c8981ab98eb8c9049c40e4 Mon Sep 17 00:00:00 2001 From: xuri Date: Thu, 14 May 2020 22:36:00 +0800 Subject: Fix #637, improve the compatibility of the auto filter with Office 2007 - 2013 --- table.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'table.go') diff --git a/table.go b/table.go index 55901cd..ae47471 100644 --- a/table.go +++ b/table.go @@ -290,6 +290,20 @@ func (f *File) AutoFilter(sheet, hcell, vcell, format string) error { return err } ref := cellStart + ":" + cellEnd + wb := f.workbookReader() + d := xlsxDefinedName{ + Name: "_xlnm._FilterDatabase", + Hidden: true, + LocalSheetID: intPtr(f.GetSheetIndex(sheet)), + Data: fmt.Sprintf("%s!%s", sheet, ref), + } + if wb.DefinedNames != nil { + wb.DefinedNames.DefinedName = append(wb.DefinedNames.DefinedName, d) + } else { + wb.DefinedNames = &xlsxDefinedNames{ + DefinedName: []xlsxDefinedName{d}, + } + } refRange := vcol - hcol return f.autoFilter(sheet, ref, refRange, hcol, formatSet) } -- cgit v1.2.1 From c815e4b84b9b777c30d127f384b38105afa2640d Mon Sep 17 00:00:00 2001 From: yuemanxilou Date: Fri, 15 May 2020 14:03:02 +0800 Subject: avoid duplicate filter database in workbook defined name --- table.go | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'table.go') diff --git a/table.go b/table.go index ae47471..5a0e46f 100644 --- a/table.go +++ b/table.go @@ -281,28 +281,38 @@ func (f *File) AutoFilter(sheet, hcell, vcell, format string) error { formatSet, _ := parseAutoFilterSet(format) var cellStart, cellEnd string - cellStart, err = CoordinatesToCellName(hcol, hrow) - if err != nil { + if cellStart, err = CoordinatesToCellName(hcol, hrow); err != nil { return err } - cellEnd, err = CoordinatesToCellName(vcol, vrow) - if err != nil { + if cellEnd, err = CoordinatesToCellName(vcol, vrow); err != nil { return err } - ref := cellStart + ":" + cellEnd + ref, filterDB := cellStart+":"+cellEnd, "_xlnm._FilterDatabase" wb := f.workbookReader() + sheetID := f.GetSheetIndex(sheet) + filterRange := fmt.Sprintf("%s!%s", sheet, ref) d := xlsxDefinedName{ - Name: "_xlnm._FilterDatabase", + Name: filterDB, Hidden: true, - LocalSheetID: intPtr(f.GetSheetIndex(sheet)), - Data: fmt.Sprintf("%s!%s", sheet, ref), + LocalSheetID: intPtr(sheetID), + Data: filterRange, } - if wb.DefinedNames != nil { - wb.DefinedNames.DefinedName = append(wb.DefinedNames.DefinedName, d) - } else { + if wb.DefinedNames == nil { wb.DefinedNames = &xlsxDefinedNames{ DefinedName: []xlsxDefinedName{d}, } + } else { + var definedNameExists bool + for idx := range wb.DefinedNames.DefinedName { + definedName := wb.DefinedNames.DefinedName[idx] + if definedName.Name == filterDB && *definedName.LocalSheetID == sheetID && definedName.Hidden { + wb.DefinedNames.DefinedName[idx].Data = filterRange + definedNameExists = true + } + } + if !definedNameExists { + wb.DefinedNames.DefinedName = append(wb.DefinedNames.DefinedName, d) + } } refRange := vcol - hcol return f.autoFilter(sheet, ref, refRange, hcol, formatSet) -- cgit v1.2.1