Permalink
Browse files

New feature: File.DuplicateRowTo() duplicate row to specified row pos…

…ition.

DuplicateRowTo() is similar to DuplicateRow() but copies specified row not just after specified source row
but to any other specified position below or above source row.

Also I made minor modifications of tests: using filepath.Join() instead of direct unix-way paths strings
to avoid possible tests fails on other OS.
  • Loading branch information...
albenik committed Dec 27, 2018
1 parent b0ed4c1 commit 725c1a0c40971282ff924f4802a57e4c17431691
Showing with 434 additions and 173 deletions.
  1. +3 −2 datavalidation_test.go
  2. +5 −7 excelize.go
  3. +384 −140 excelize_test.go
  4. +1 −2 go.mod
  5. +4 −2 go.sum
  6. +37 −20 rows.go
@@ -10,13 +10,14 @@
package excelize

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
)

func TestDataValidation(t *testing.T) {
const resultFile = "./test/TestDataValidation.xlsx"
resultFile := filepath.Join("test", "TestDataValidation.xlsx")

xlsx := NewFile()

@@ -50,7 +51,7 @@ func TestDataValidation(t *testing.T) {
}

func TestDataValidationError(t *testing.T) {
const resultFile = "./test/TestDataValidationError.xlsx"
resultFile := filepath.Join("test", "TestDataValidationError.xlsx")

xlsx := NewFile()
xlsx.SetCellStr("Sheet1", "E1", "E1")
@@ -238,18 +238,16 @@ func (f *File) adjustRowDimensions(xlsx *xlsxWorksheet, rowIndex, offset int) {
}
for i, r := range xlsx.SheetData.Row {
if r.R >= rowIndex {
f.ajustSingleRowDimensions(&xlsx.SheetData.Row[i], offset)
f.ajustSingleRowDimensions(&xlsx.SheetData.Row[i], r.R+offset)
}
}
}

// ajustSingleRowDimensions provides a function to ajust single row
// dimensions.
func (f *File) ajustSingleRowDimensions(r *xlsxRow, offset int) {
r.R += offset
// ajustSingleRowDimensions provides a function to ajust single row dimensions.
func (f *File) ajustSingleRowDimensions(r *xlsxRow, row int) {
r.R = row
for i, col := range r.C {
row, _ := strconv.Atoi(strings.Map(intOnlyMapF, col.R))
r.C[i].R = string(strings.Map(letterOnlyMapF, col.R)) + strconv.Itoa(row+offset)
r.C[i].R = string(strings.Map(letterOnlyMapF, col.R)) + strconv.Itoa(r.R)
}
}

Oops, something went wrong.

0 comments on commit 725c1a0

Please sign in to comment.