Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: qax-os/excelize
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0
Choose a base ref
...
head repository: qax-os/excelize
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.1
Choose a head ref

Commits on May 2, 2019

  1. Remove Go 1.8 test in TravisCI

    xuri committed May 2, 2019
    Copy the full SHA
    63e97ff View commit details

Commits on May 3, 2019

  1. Copy the full SHA
    72701e8 View commit details

Commits on May 5, 2019

  1. Copy the full SHA
    69b38dd View commit details

Commits on May 11, 2019

  1. Copy the full SHA
    25763ba View commit details

Commits on May 16, 2019

  1. Copy the full SHA
    7e77e14 View commit details

Commits on May 17, 2019

  1. Copy the full SHA
    f91f548 View commit details

Commits on May 23, 2019

  1. Add the ability to change the default font

    Closes #390
    Harris committed May 23, 2019
    Copy the full SHA
    b1c9884 View commit details

Commits on May 24, 2019

  1. Merge pull request #391 from mlh758/390-change-default-font

    Add the ability to change the default font
    xuri authored May 24, 2019
    Copy the full SHA
    6233757 View commit details

Commits on Jun 1, 2019

  1. Copy the full SHA
    d038ca2 View commit details

Commits on Jun 4, 2019

  1. Copy the full SHA
    db99373 View commit details

Commits on Jun 5, 2019

  1. - Supplemental worksheet struct fields and field order adjustment

    - Testing case for set and get doc properties
    - Update charts struct XML tags
    xuri committed Jun 5, 2019
    1
    Copy the full SHA
    cff16fa View commit details

Commits on Jun 7, 2019

  1. Copy the full SHA
    3997dee View commit details
  2. Fixed #418, #420, #421, init adjust calculation chain support

    Update testing case
    xuri committed Jun 7, 2019
    Copy the full SHA
    421f945 View commit details

Commits on Jun 9, 2019

  1. Copy the full SHA
    46a3632 View commit details

Commits on Jun 12, 2019

  1. Copy the full SHA
    821632c View commit details

Commits on Jun 13, 2019

  1. Copy the full SHA
    e124f60 View commit details
  2. Copy the full SHA
    dc0869f View commit details

Commits on Jun 15, 2019

  1. Copy the full SHA
    5cf1c05 View commit details

Commits on Jun 18, 2019

  1. Copy the full SHA
    a335be7 View commit details
  2. Copy the full SHA
    e77c462 View commit details

Commits on Jun 19, 2019

  1. Optimize code, fix golint issues

    xuri committed Jun 19, 2019
    Copy the full SHA
    9f86230 View commit details

Commits on Jun 27, 2019

  1. Add TIF, TIFF format images and more detailed error information when…

    … open the encrypted file
    xuri committed Jun 27, 2019
    Copy the full SHA
    54def7e View commit details

Commits on Jun 30, 2019

  1. Update GoDoc and typo fixed

    xuri committed Jun 30, 2019
    Copy the full SHA
    dc8210d View commit details
Showing with 2,653 additions and 993 deletions.
  1. +0 −1 .travis.yml
  2. +128 −63 adjust.go
  3. +47 −0 adjust_test.go
  4. +9 −13 cell.go
  5. +12 −2 cellmerged.go
  6. +855 −293 chart.go
  7. +83 −1 chart_test.go
  8. +61 −1 col.go
  9. +176 −0 col_test.go
  10. +14 −5 comment.go
  11. +4 −4 datavalidation.go
  12. +15 −15 datavalidation_test.go
  13. +140 −0 docProps.go
  14. +56 −0 docProps_test.go
  15. +12 −0 excelize.go
  16. +24 −222 excelize_test.go
  17. +17 −14 picture.go
  18. +17 −8 picture_test.go
  19. +7 −3 rows.go
  20. +1 −1 shape.go
  21. +241 −12 sheet.go
  22. +86 −16 sheet_test.go
  23. +38 −15 styles.go
  24. +29 −1 styles_test.go
  25. +6 −11 table.go
  26. +1 −1 templates.go
  27. BIN test/images/excel.tif
  28. +55 −0 xmlApp.go
  29. +182 −165 xmlChart.go
  30. +89 −0 xmlCore.go
  31. +74 −37 xmlDecodeDrawing.go
  32. +28 −24 xmlDrawing.go
  33. +18 −23 xmlStyles.go
  34. +12 −4 xmlWorkbook.go
  35. +116 −38 xmlWorksheet.go
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ install:
- go get -d -t -v ./... && go build -v ./...

go:
- 1.8.x
- 1.9.x
- 1.10.x
- 1.11.x
191 changes: 128 additions & 63 deletions adjust.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,10 @@

package excelize

import "strings"
import (
"errors"
"strings"
)

type adjustDirection bool

@@ -27,8 +30,7 @@ const (
// row: Index number of the row we're inserting/deleting before
// offset: Number of rows/column to insert/delete negative values indicate deletion
//
// TODO: adjustCalcChain, adjustPageBreaks, adjustComments,
// adjustDataValidations, adjustProtectedCells
// TODO: adjustPageBreaks, adjustComments, adjustDataValidations, adjustProtectedCells
//
func (f *File) adjustHelper(sheet string, dir adjustDirection, num, offset int) error {
xlsx, err := f.workSheetReader(sheet)
@@ -47,7 +49,9 @@ func (f *File) adjustHelper(sheet string, dir adjustDirection, num, offset int)
if err = f.adjustAutoFilter(xlsx, dir, num, offset); err != nil {
return err
}

if err = f.adjustCalcChain(dir, num, offset); err != nil {
return err
}
checkSheet(xlsx)
checkRow(xlsx)
return nil
@@ -139,46 +143,85 @@ func (f *File) adjustAutoFilter(xlsx *xlsxWorksheet, dir adjustDirection, num, o
return nil
}

rng := strings.Split(xlsx.AutoFilter.Ref, ":")
firstCell := rng[0]
lastCell := rng[1]

firstCol, firstRow, err := CellNameToCoordinates(firstCell)
coordinates, err := f.areaRefToCoordinates(xlsx.AutoFilter.Ref)
if err != nil {
return err
}
x1, y1, x2, y2 := coordinates[0], coordinates[1], coordinates[2], coordinates[3]

lastCol, lastRow, err := CellNameToCoordinates(lastCell)
if err != nil {
return err
}

if (dir == rows && firstRow == num && offset < 0) || (dir == columns && firstCol == num && lastCol == num) {
if (dir == rows && y1 == num && offset < 0) || (dir == columns && x1 == num && x2 == num) {
xlsx.AutoFilter = nil
for rowIdx := range xlsx.SheetData.Row {
rowData := &xlsx.SheetData.Row[rowIdx]
if rowData.R > firstRow && rowData.R <= lastRow {
if rowData.R > y1 && rowData.R <= y2 {
rowData.Hidden = false
}
}
return nil
}

coordinates = f.adjustAutoFilterHelper(dir, coordinates, num, offset)
x1, y1, x2, y2 = coordinates[0], coordinates[1], coordinates[2], coordinates[3]

if xlsx.AutoFilter.Ref, err = f.coordinatesToAreaRef([]int{x1, y1, x2, y2}); err != nil {
return err
}
return nil
}

// adjustAutoFilterHelper provides a function for adjusting auto filter to
// compare and calculate cell axis by the given adjust direction, operation
// axis and offset.
func (f *File) adjustAutoFilterHelper(dir adjustDirection, coordinates []int, num, offset int) []int {
if dir == rows {
if firstRow >= num {
firstCell, _ = CoordinatesToCellName(firstCol, firstRow+offset)
if coordinates[1] >= num {
coordinates[1] += offset
}
if lastRow >= num {
lastCell, _ = CoordinatesToCellName(lastCol, lastRow+offset)
if coordinates[3] >= num {
coordinates[3] += offset
}
} else {
if lastCol >= num {
lastCell, _ = CoordinatesToCellName(lastCol+offset, lastRow)
if coordinates[2] >= num {
coordinates[2] += offset
}
}
return coordinates
}

xlsx.AutoFilter.Ref = firstCell + ":" + lastCell
return nil
// areaRefToCoordinates provides a function to convert area reference to a
// pair of coordinates.
func (f *File) areaRefToCoordinates(ref string) ([]int, error) {
coordinates := make([]int, 4)
rng := strings.Split(ref, ":")
firstCell := rng[0]
lastCell := rng[1]
var err error
coordinates[0], coordinates[1], err = CellNameToCoordinates(firstCell)
if err != nil {
return coordinates, err
}
coordinates[2], coordinates[3], err = CellNameToCoordinates(lastCell)
if err != nil {
return coordinates, err
}
return coordinates, err
}

// coordinatesToAreaRef provides a function to convert a pair of coordinates
// to area reference.
func (f *File) coordinatesToAreaRef(coordinates []int) (string, error) {
if len(coordinates) != 4 {
return "", errors.New("coordinates length must be 4")
}
firstCell, err := CoordinatesToCellName(coordinates[0], coordinates[1])
if err != nil {
return "", err
}
lastCell, err := CoordinatesToCellName(coordinates[2], coordinates[3])
if err != nil {
return "", err
}
return firstCell + ":" + lastCell, err
}

// adjustMergeCells provides a function to update merged cells when inserting
@@ -189,57 +232,79 @@ func (f *File) adjustMergeCells(xlsx *xlsxWorksheet, dir adjustDirection, num, o
}

for i, areaData := range xlsx.MergeCells.Cells {
rng := strings.Split(areaData.Ref, ":")
firstCell := rng[0]
lastCell := rng[1]

firstCol, firstRow, err := CellNameToCoordinates(firstCell)
coordinates, err := f.areaRefToCoordinates(areaData.Ref)
if err != nil {
return err
}

lastCol, lastRow, err := CellNameToCoordinates(lastCell)
if err != nil {
return err
}

adjust := func(v int) int {
if v >= num {
v += offset
if v < 1 {
return 1
}
return v
}
return v
}

x1, y1, x2, y2 := coordinates[0], coordinates[1], coordinates[2], coordinates[3]
if dir == rows {
firstRow = adjust(firstRow)
lastRow = adjust(lastRow)
if y1 == num && y2 == num && offset < 0 {
f.deleteMergeCell(xlsx, i)
}
y1 = f.adjustMergeCellsHelper(y1, num, offset)
y2 = f.adjustMergeCellsHelper(y2, num, offset)
} else {
firstCol = adjust(firstCol)
lastCol = adjust(lastCol)
}

if firstCol == lastCol && firstRow == lastRow {
if len(xlsx.MergeCells.Cells) > 1 {
xlsx.MergeCells.Cells = append(xlsx.MergeCells.Cells[:i], xlsx.MergeCells.Cells[i+1:]...)
xlsx.MergeCells.Count = len(xlsx.MergeCells.Cells)
} else {
xlsx.MergeCells = nil
if x1 == num && x2 == num && offset < 0 {
f.deleteMergeCell(xlsx, i)
}
x1 = f.adjustMergeCellsHelper(x1, num, offset)
x2 = f.adjustMergeCellsHelper(x2, num, offset)
}

if firstCell, err = CoordinatesToCellName(firstCol, firstRow); err != nil {
if x1 == x2 && y1 == y2 {
f.deleteMergeCell(xlsx, i)
}
if areaData.Ref, err = f.coordinatesToAreaRef([]int{x1, y1, x2, y2}); err != nil {
return err
}
}
return nil
}

if lastCell, err = CoordinatesToCellName(lastCol, lastRow); err != nil {
return err
// adjustMergeCellsHelper provides a function for adjusting merge cells to
// compare and calculate cell axis by the given pivot, operation axis and
// offset.
func (f *File) adjustMergeCellsHelper(pivot, num, offset int) int {
if pivot >= num {
pivot += offset
if pivot < 1 {
return 1
}
return pivot
}
return pivot
}

// deleteMergeCell provides a function to delete merged cell by given index.
func (f *File) deleteMergeCell(sheet *xlsxWorksheet, idx int) {
if len(sheet.MergeCells.Cells) > 1 {
sheet.MergeCells.Cells = append(sheet.MergeCells.Cells[:idx], sheet.MergeCells.Cells[idx+1:]...)
sheet.MergeCells.Count = len(sheet.MergeCells.Cells)
} else {
sheet.MergeCells = nil
}
}

areaData.Ref = firstCell + ":" + lastCell
// adjustCalcChain provides a function to update the calculation chain when
// inserting or deleting rows or columns.
func (f *File) adjustCalcChain(dir adjustDirection, num, offset int) error {
if f.CalcChain == nil {
return nil
}
for index, c := range f.CalcChain.C {
colNum, rowNum, err := CellNameToCoordinates(c.R)
if err != nil {
return err
}
if dir == rows && num <= rowNum {
if newRow := rowNum + offset; newRow > 0 {
f.CalcChain.C[index].R, _ = CoordinatesToCellName(colNum, newRow)
}
}
if dir == columns && num <= colNum {
if newCol := colNum + offset; newCol > 0 {
f.CalcChain.C[index].R, _ = CoordinatesToCellName(newCol, rowNum)
}
}
}
return nil
}
47 changes: 47 additions & 0 deletions adjust_test.go
Original file line number Diff line number Diff line change
@@ -27,6 +27,24 @@ func TestAdjustMergeCells(t *testing.T) {
},
},
}, rows, 0, 0), `cannot convert cell "B" to coordinates: invalid cell name "B"`)
assert.NoError(t, f.adjustMergeCells(&xlsxWorksheet{
MergeCells: &xlsxMergeCells{
Cells: []*xlsxMergeCell{
{
Ref: "A1:B1",
},
},
},
}, rows, 1, -1))
assert.NoError(t, f.adjustMergeCells(&xlsxWorksheet{
MergeCells: &xlsxMergeCells{
Cells: []*xlsxMergeCell{
{
Ref: "A1:A2",
},
},
},
}, columns, 1, -1))
}

func TestAdjustAutoFilter(t *testing.T) {
@@ -67,3 +85,32 @@ func TestAdjustHelper(t *testing.T) {
// testing adjustHelper on not exists worksheet.
assert.EqualError(t, f.adjustHelper("SheetN", rows, 0, 0), "sheet SheetN is not exist")
}

func TestAdjustCalcChain(t *testing.T) {
f := NewFile()
f.CalcChain = &xlsxCalcChain{
C: []xlsxCalcChainC{
{R: "B2"},
},
}
assert.NoError(t, f.InsertCol("Sheet1", "A"))
assert.NoError(t, f.InsertRow("Sheet1", 1))

f.CalcChain.C[0].R = "invalid coordinates"
assert.EqualError(t, f.InsertCol("Sheet1", "A"), `cannot convert cell "invalid coordinates" to coordinates: invalid cell name "invalid coordinates"`)
f.CalcChain = nil
assert.NoError(t, f.InsertCol("Sheet1", "A"))
}

func TestCoordinatesToAreaRef(t *testing.T) {
f := NewFile()
_, err := f.coordinatesToAreaRef([]int{})
assert.EqualError(t, err, "coordinates length must be 4")
_, err = f.coordinatesToAreaRef([]int{1, -1, 1, 1})
assert.EqualError(t, err, "invalid cell coordinates [1, -1]")
_, err = f.coordinatesToAreaRef([]int{1, 1, 1, -1})
assert.EqualError(t, err, "invalid cell coordinates [1, -1]")
ref, err := f.coordinatesToAreaRef([]int{1, 1, 1, 1})
assert.NoError(t, err)
assert.EqualValues(t, ref, "A1:A1")
}
22 changes: 9 additions & 13 deletions cell.go
Original file line number Diff line number Diff line change
@@ -401,31 +401,27 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) error {
// If you create a merged cell that overlaps with another existing merged cell,
// those merged cells that already exist will be removed.
func (f *File) MergeCell(sheet, hcell, vcell string) error {
hcol, hrow, err := CellNameToCoordinates(hcell)
coordinates, err := f.areaRefToCoordinates(hcell + ":" + vcell)
if err != nil {
return err
}
x1, y1, x2, y2 := coordinates[0], coordinates[1], coordinates[2], coordinates[3]

vcol, vrow, err := CellNameToCoordinates(vcell)
if err != nil {
return err
}

if hcol == vcol && hrow == vrow {
if x1 == x2 && y1 == y2 {
return err
}

// Correct the coordinate area, such correct C1:B3 to B1:C3.
if vcol < hcol {
hcol, vcol = vcol, hcol
if x2 < x1 {
x1, x2 = x2, x1
}

if vrow < hrow {
hrow, vrow = vrow, hrow
if y2 < y1 {
y1, y2 = y2, y1
}

hcell, _ = CoordinatesToCellName(hcol, hrow)
vcell, _ = CoordinatesToCellName(vcol, vrow)
hcell, _ = CoordinatesToCellName(x1, y1)
vcell, _ = CoordinatesToCellName(x2, y2)

xlsx, err := f.workSheetReader(sheet)
if err != nil {
14 changes: 12 additions & 2 deletions cellmerged.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// Copyright 2016 - 2019 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 "strings"

// GetMergeCells provides a function to get all merged cells from a worksheet currently.
// GetMergeCells provides a function to get all merged cells from a worksheet
// currently.
func (f *File) GetMergeCells(sheet string) ([]MergeCell, error) {
var mergeCells []MergeCell
xlsx, err := f.workSheetReader(sheet)
@@ -45,4 +55,4 @@ func (m *MergeCell) GetStartAxis() string {
func (m *MergeCell) GetEndAxis() string {
axis := strings.Split((*m)[0], ":")
return axis[1]
}
}
Loading