Skip to content

Commit 725c1a0

Browse files
committed
New feature: File.DuplicateRowTo() duplicate row to specified row position.
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.
1 parent b0ed4c1 commit 725c1a0

File tree

6 files changed

+434
-173
lines changed

6 files changed

+434
-173
lines changed

datavalidation_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
package excelize
1111

1212
import (
13+
"path/filepath"
1314
"testing"
1415

1516
"github.com/stretchr/testify/assert"
1617
)
1718

1819
func TestDataValidation(t *testing.T) {
19-
const resultFile = "./test/TestDataValidation.xlsx"
20+
resultFile := filepath.Join("test", "TestDataValidation.xlsx")
2021

2122
xlsx := NewFile()
2223

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

5253
func TestDataValidationError(t *testing.T) {
53-
const resultFile = "./test/TestDataValidationError.xlsx"
54+
resultFile := filepath.Join("test", "TestDataValidationError.xlsx")
5455

5556
xlsx := NewFile()
5657
xlsx.SetCellStr("Sheet1", "E1", "E1")

excelize.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,16 @@ func (f *File) adjustRowDimensions(xlsx *xlsxWorksheet, rowIndex, offset int) {
238238
}
239239
for i, r := range xlsx.SheetData.Row {
240240
if r.R >= rowIndex {
241-
f.ajustSingleRowDimensions(&xlsx.SheetData.Row[i], offset)
241+
f.ajustSingleRowDimensions(&xlsx.SheetData.Row[i], r.R+offset)
242242
}
243243
}
244244
}
245245

246-
// ajustSingleRowDimensions provides a function to ajust single row
247-
// dimensions.
248-
func (f *File) ajustSingleRowDimensions(r *xlsxRow, offset int) {
249-
r.R += offset
246+
// ajustSingleRowDimensions provides a function to ajust single row dimensions.
247+
func (f *File) ajustSingleRowDimensions(r *xlsxRow, row int) {
248+
r.R = row
250249
for i, col := range r.C {
251-
row, _ := strconv.Atoi(strings.Map(intOnlyMapF, col.R))
252-
r.C[i].R = string(strings.Map(letterOnlyMapF, col.R)) + strconv.Itoa(row+offset)
250+
r.C[i].R = string(strings.Map(letterOnlyMapF, col.R)) + strconv.Itoa(r.R)
253251
}
254252
}
255253

0 commit comments

Comments
 (0)