Skip to content

Commit

Permalink
Fixed error during uncompression
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexJarrah committed Jan 4, 2024
1 parent 49baaf8 commit ccde9b3
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,38 @@ func Uncompress(content Content, ignore int) Content {
for _, row := range rows {
cells := row.TableCell

for i, cell := range cells {
// Create a new slice for the row's cells
newCells := make([]TableCell, 0, len(cells))

for _, cell := range cells {
// Retrieve the number of cell repetitions
repetitions := getRepetitionCount(cell)

// Reset the number of repetitions, as they are no longer needed
cell.NumberColumnsRepeated = ""

// Ensure we don't corrupt the file by adding too many rows/columns
// by avoiding uncompressing the ending of a row or column
// by avoiding uncompressing the end of a row or column
if repetitions > ignore {
newCells = append(newCells, cell)
continue
}

// Reset the number of repetitions, as they are no longer needed
cell.NumberColumnsRepeated = ""

// Insert a copy of the cell at the same index in the row for
// each repetition
for j := 2; j <= repetitions; j++ {
row.TableCell = append(row.TableCell[:i], row.TableCell[i+1:]...)
row.TableCell = append(row.TableCell[:i], append([]TableCell{cell}, row.TableCell[i:]...)...)
row.TableCell = append(row.TableCell[:i], append([]TableCell{cell}, row.TableCell[i:]...)...)
for j := 0; j < repetitions; j++ {
newCells = append(newCells, cell)
}
}

row.TableCell = newCells
}

sheet.TableRow = rows
}

content.Body.Spreadsheet.Table = sheets

return content
}

Expand Down

0 comments on commit ccde9b3

Please sign in to comment.