| 30 | } |
| 31 | |
| 32 | func BuildCopyRequests( |
| 33 | source, destination *sheets.GridRange, |
| 34 | transpose bool, |
| 35 | spans []Span, |
| 36 | options ...CopyOptions, |
| 37 | ) ([]*sheets.Request, error) { |
| 38 | if source == nil || destination == nil || |
| 39 | source.EndRowIndex <= source.StartRowIndex || source.EndColumnIndex <= source.StartColumnIndex || |
| 40 | destination.EndRowIndex <= destination.StartRowIndex || destination.EndColumnIndex <= destination.StartColumnIndex { |
| 41 | return nil, nil |
| 42 | } |
| 43 | |
| 44 | destination = EffectiveCopyDestination(source, destination, transpose) |
| 45 | sourceSpans := RelevantSourceSpans(source, spans) |
| 46 | ordinarySourceRanges := SubtractSpans(source, sourceSpans) |
| 47 | destinationSpan, hasDestinationTable := FirstIntersectingSpan(destination, spans) |
| 48 | |
| 49 | opts := CopyOptions{} |
| 50 | if len(options) > 0 { |
| 51 | opts = options[0] |
| 52 | } |
| 53 | |
| 54 | if hasDestinationTable && len(ordinarySourceRanges) > 0 { |
| 55 | if !opts.OrdinarySourceValidationKnown { |
| 56 | return nil, invalidf( |
| 57 | "copying validation into table column %d in table %s requires a table-column source", |
| 58 | destinationSpan.ColumnIndex+1, |
| 59 | destinationSpan.TableID, |
| 60 | ) |
| 61 | } |
| 62 | |
| 63 | for _, candidate := range spans { |
| 64 | if spanIntersects(destination, candidate) && |
| 65 | ordinaryValidationMapsToSpan( |
| 66 | source, |
| 67 | destination, |
| 68 | transpose, |
| 69 | opts.OrdinaryValidatedCells, |
| 70 | ordinarySourceRanges, |
| 71 | candidate, |
| 72 | ) { |
| 73 | return nil, invalidf( |
| 74 | "copying ordinary cell validation into table column %d in table %s is not supported", |
| 75 | candidate.ColumnIndex+1, |
| 76 | candidate.TableID, |
| 77 | ) |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if len(sourceSpans) == 0 && !hasDestinationTable { |
| 83 | return nil, nil |
| 84 | } |
| 85 | |
| 86 | merged := []copySegment{} |
| 87 | |
| 88 | if len(sourceSpans) > 0 { |
| 89 | segments, err := buildCopySegments(source, destination, transpose, sourceSpans) |