PHPOffice / PHPExcel

ARCHIVED
Other
11.46k stars 4.19k forks source link

[Feature Request] Duplicate entire rows and columns #180

Open kachkaev opened 11 years ago

kachkaev commented 11 years ago

It would be very helpful to have an opportunity to duplicate entire rows and columns. Doing so is a commonly needed operation, but it’s not trivial as it may look at first sight. The process includes:

I believe that the interface of one of the methods could look like this:

class PHPExcel_Worksheet implements PHPExcel_IComparable
{
   /* .... */

   /**
     * Copies a range of columns from $sourceWorksheet to $destinationWorksheet
     * Only one copy is pasted during a function call, but multiple columns can be copied
     * 
     * @param \PHPExcel_Worksheet $sourceWorksheet
     * @param \PHPExcel_Worksheet $targetWorksheet
     * @param string $sourceColumnRange range of columns to copy from $sourceWorksheet (using letters or numbers starting from zero) e.g. "A", "A:B", "FC:ZZ",  "1", "0:1"
     * @param string $insertBefore name / index of the column in $targetWorksheet in front of which the data will be inserted
     * @param array $replacements an array of string / regex replacements to perform while copying
     * @param int $rowLimit number of rows for which values and styles are being copied
     */
    public static function copyColumns(\PHPExcel_Worksheet $sourceWorksheet, \PHPExcel_Worksheet $targetWorksheet, $sourceColumnRange, $insertBefore, array $replacements = null, $rowLimit = null)
    {
        /* ... */
    }
} 

It is important to be able to copy several columns / rows at once because they may contain merged cells, which need to remain merged in the copy. Probably an ability to create a number of copies is even less important because it is possible to do so in a loop. However, doing multiple copies at once may improve the performance. One of the things to watch out for is that the $insertBefore should not be within the given $sourceColumnRange, otherwise it will break the integrity of columns and rows being copied.

I tried to implement this functionality myself, but simply could not overcome a number of problems. It would be great if someone knowledgeable enough in the library internals could put some effort in adding such feature, because it’s crucial for many dynamic reports generated with PHPExcel.

gkalpak commented 9 years ago

:+1: Is there a known solution to this ?

ValentinNikolaev commented 9 years ago

Rly need this

in-ilyas-kazi commented 8 years ago

+1

alandoyle95 commented 7 years ago

+1 as well.

iruy commented 6 years ago

After 4 years, this is still missing. I need this as well..

alandoyle95 commented 6 years ago

Sadly it's not something that is easy to do.

On Dec 13, 2017 11:22 PM, "Yuri Sarzi" notifications@github.com wrote:

After 4 years, this is still missing. I need this as well..

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PHPOffice/PHPExcel/issues/180#issuecomment-351629021, or mute the thread https://github.com/notifications/unsubscribe-auth/AF7q0WGibdGn9apuVdDXDHV2WbzGFpgwks5tAMycgaJpZM4AqSdk .

lsklyut commented 6 years ago

+1, halp