Copy charts from workbook to another

Hello,


I try to copy all the charts from a workbook to another with the following code :
	Aspose.Cells.Drawing.ShapeCollection shapes = SheetAdd.Shapes;
if (shapes != null && shapes.Count > 0)
{
foreach (Aspose.Cells.Drawing.Shape shape in shapes)
{
if ((shape is Aspose.Cells.Drawing.ChartShape || shape is Aspose.Cells.Drawing.Picture) && shape.IsHidden == false)
{
//shape.
worksheet.Shapes.AddCopy(shape, shape.UpperLeftRow, shape.Top, shape.UpperLeftColumn, shape.Left);
}
}
}

But when my new Excel file is saved and I open it, I have an error that said:
Excel fin Unreadable content. Do you want to recover the workbook.

If I click on Yes, The file look great.
Is there a better way to do it ?
Best Regards
Hi,

Please download and use our latest version/fix: Aspose.Cells for .NET v7.1.2.3 If yous till find the issue, kindly give us your template and output files here, we will check it soon.

Thank you.


Hello,


I try the latest version and I have the same results.
Please find my template and my result joined to this message.

Best Regards

Hi,

I am unable to run your code because few lines are missing in your code that deals with SheetAdd and worksheet references.

Could you please provide us your complete code that could be run and we could check this problem at our end. Thank you.

Hello,

This is a summary of my code source.
Workbook templateworkbook = new Workbook(template);
Workbook targetworkbook = new Workbook();
Worksheet worksheet = targetworkbook.Worksheets[0];
            <span style="color:blue;">foreach</span> (<span style="color:#2b91af;">Worksheet</span> SheetAdd <span style="color:blue;">in</span> templateworkbook.Worksheets)
            {
                Aspose.Cells.Drawing.<span style="color:#2b91af;">ShapeCollection</span> shapes = SheetAdd.Shapes;
                <span style="color:blue;">if</span> (shapes != <span style="color:blue;">null</span> && shapes.Count > 0)
                {
                    <span style="color:blue;">foreach</span> (Aspose.Cells.Drawing.<span style="color:#2b91af;">Shape</span> shape <span style="color:blue;">in</span> shapes)
                    {
                        <span style="color:blue;">if</span> ((shape <span style="color:blue;">is</span> Aspose.Cells.Drawing.<span style="color:#2b91af;">ChartShape</span> || shape <span style="color:blue;">is</span> Aspose.Cells.Drawing.<span style="color:#2b91af;">Picture</span>) && shape.IsHidden == <span style="color:blue;">false</span>)
                        {
                            <span style="font-family:Lucida Sans;font-size:12;font-style:italic;color:green;">//shape.</span>
                            worksheet.Shapes.AddCopy(shape, shape.UpperLeftRow, shape.Top, shape.UpperLeftColumn, shape.Left);
                        }
                    }
                }
            }
            <span style="font-family:Lucida Sans;font-size:12;font-style:italic;color:green;">//Save the targetWorkbook</span></pre><pre style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; "><pre style="font-family: Consolas; font-size: 13px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; ">Thank you for your help</pre><pre style="font-family: Consolas; font-size: 13px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; ">Regards</pre><pre style="font-family: Consolas; font-size: 13px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; "><br></pre><pre style="font-family: Consolas; font-size: 13px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; "><br></pre>

Hi,

Thanks for your complete code.

I was able to replicate the problem using the latest version:
Aspose.Cells
for .NET v7.1.2.3


We have logged this issue in our database. Development team will look into this issue and once the issue is fixed or we have some other update relating to it, we will update you asap.

This issue has been logged as CELLSNET-40510.

Please see the code below for a reference, it throws a null reference exception.

C#


String template = “F:\Shak-Data-RW\Downloads\Template.xlsx”;


Workbook templateworkbook = new Workbook(template);

Workbook targetworkbook = new Workbook();

Worksheet worksheet = targetworkbook.Worksheets[0];


foreach (Worksheet SheetAdd in templateworkbook.Worksheets)

{

Aspose.Cells.Drawing.ShapeCollection shapes = SheetAdd.Shapes;

if (shapes != null && shapes.Count > 0)

{

foreach (Aspose.Cells.Drawing.Shape shape in shapes)

{

if ((shape is Aspose.Cells.Drawing.ChartShape || shape is Aspose.Cells.Drawing.Picture) && shape.IsHidden == false)

{

//shape.

worksheet.Shapes.AddCopy(shape, shape.UpperLeftRow, shape.Top, shape.UpperLeftColumn, shape.Left);

}

}

}

}

//Save the targetWorkbook*/


targetworkbook.Save(template + “.out.xlsx”);


Hi,

Please download and try this fix: Aspose.Cells for .NET v7.1.2.4

We have fixed this issue.

The issues you have found earlier (filed as CELLSNET-40510) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.