We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Cells.Range.CopyStyle (& Aspose.Cells.Range.Copy) - fails to copy PageBreak

Hi,


This is with repect to Aspose.Cells.
I am facing an issue while performing CopyRange function, while printing excel document using Aspose.

I have PageBreak embedded in a range, but when we perform the CopyRange function it fails to copy the PageBreak (though all other format & formulas in the range get copied).

To be more specific I am talking about below mentioned functions:
(where r2 & range are Aspose.Cells.Range)
r2.CopyStyle(range);
r2.Copy(range);

Do let me know if you need more information.

Regards,
Ashiyana

Hi,

Could you post your template file here with sample code to show the issue you have mentioned. We will look into it soon.

Thank you.

Hi,


PFA templates along with dummy application.

Regards,
Ashiyana

Hi,

Thanks for sharing your sample project.

We will look into your issue and get back to you soon.

Your issue has been logged (for investigation) into our issue tracking system with an issue id: CELLSNET-17836.

Once we have any update about it we will let you know.

Thank you.

Hi,

We do not support to copy PageBreak in copying range. It works as MS Excel, you may check it in MS Excel manually. Also, for your knowledge, Copying PageBreaks only can be supported in copying worksheets.


Thank you.

Hi,

I am sorry, but I dont understand your point.
I can see that while printing the same template using MSOffice it works perfect.

Please find attached my project where you can test with both Aspose & Office Utlitities to print the same templates. (Please switch between Aspose & Office in app.config to point to the right utlitity)

I have also attached set of output files to show the progress after each CopyRange & AddPageBreak. It looks like Aspose looses track of PageBreak in memory and just maintains the last one.

Do let me know if you need more info.

With Regards,
Ashiyana
Hi,

The following code is used in your project to add pagebreak:

protected override void AddPageBreak(object oRange)
{
//this._oAsposeWorksheet.HPageBreaks.Add(((Range)oRange).FirstRow, ((Range)oRange).FirstColumn);
this._oAsposeWorksheet.HPageBreaks.Add(((Range)oRange).FirstRow, ((Range)oRange).FirstColumn);
}

Please add HPageBreak and VPageBreak together.


Also, Please check the document on how to add page breaks:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/managing-page-breaks.html


Thank you.

Hi,


Even after modifying the Aspose’s AddPageBreak function to:
protected override void AddPageBreak(object oRange)
{
this._oAsposeWorksheet.HPageBreaks.Add(((Range)oRange).FirstRow, ((Range)oRange).FirstColumn);
this._oAsposeWorksheet.VPageBreaks.Add(((Range)oRange).FirstRow, ((Range)oRange).FirstColumn);
}
I am still facing the earlier issue. (i.e. pagebreak goes missing)
As mentioned earlier when MSOffice dll is used, it works fine.
Could you please look into it and get back.

PS: As you can see in the progress excels files attached earlier, Aspose does create pageBreak but loose it track as more of them are added.

With Regards,
Ashiyana

Hi,

Using the code:
private void btnPrint_Click(object sender, EventArgs e)
{
clsSpreadsheet excel = clsOfficeSuiteFactory.GetFactory().GetSpreadsheet(ApplyTemplates(),txtExcelSheet.Text);
excel.OutputFileName = txtSaveLocation.Text;
excel.SaveAs(@“F:\FileTemp\dest.xls”);
return;
excel.Print(txtPrinter.Text);

}
please post the generated file here which is used to print.

We will check your issue soon.

Thank you.

Please find attached the generated files.

aspose.xls - using aspose
excel.xls - using MSOffice

Regards,
Ashiyana

Hi,

Thanks for providing the documents showing the issue.

We will update you as soon as there is progress on investigations regarding this issue.

Best Regards

Hi,

Yes, we could not find any page break in your provided Aspose.xls file with the following code:
Workbook workbook = new Workbook();
workbook.Open(@“d:\cells500\pagebreak\aspose.xls”);
HPageBreaks hBreaks = workbook.Worksheets[0].HPageBreaks;
VPageBreaks vBreaks = workbook.Worksheets[0].VPageBreaks;
Console.WriteLine(hBreaks.Count);//0
Console.WriteLine(vBreaks.Count);//0
Console.Read();

Please confirm the following:

1) Has the medthod clsAsposeCells.AddPageBreak been called in running?
2) When is Cells.DeleteRows method called? If it is called after adding page break, please check whether page break is in the deleted rows because DeleteRows will remove page breaks if they are in the deleted row range.
3) Please check when the page break disappear (that both the hBreaks.Count and vBreaks.Count are zero) after adding page break.

Thank you

Hi,

Yes, we could not find any page break in your provided Aspose.xls file with the following code:
Workbook workbook = new Workbook();
workbook.Open(@“d:\cells500\pagebreak\aspose.xls”);
HPageBreaks hBreaks = workbook.Worksheets[0].HPageBreaks;
VPageBreaks vBreaks = workbook.Worksheets[0].VPageBreaks;
Console.WriteLine(hBreaks.Count);//0
Console.WriteLine(vBreaks.Count);//0
Console.Read();

Please confirm the following:

1) Has the medthod clsAsposeCells.AddPageBreak been called in running?
2) When is Cells.DeleteRows method called? If it is called after adding page break, please check whether page break is in the deleted rows because DeleteRows will remove page breaks if they are in the deleted row range.
3) Please check when the page break disappear (that both the hBreaks.Count and vBreaks.Count are zero) after adding page break.

Thank you

Hi,


I have one general question.
I need to know the difference between InsertRange & InstertRows with respect to below mentioned scenario:

Range range = _oAsposeWorksheet.WorkSheets.GetRangeByName(“L_1”);
CellArea ca = new CellArea();
ca.StartColumn = range.FirstColumn;
ca.EndColumn = range.FirstColumn + range.ColumnCount;
ca.StartRow = range.FirstRow;
ca.EndRow = range.FirstRow + range.RowCount;

InsertRange
this._oAsposeWorksheet.Cells.InsertRange(ca, ShiftType.Down);

InstertRows
this._oAsposeWorksheet.Cells.InsertRows(range.FirstRow, range.RowCount);

Currently I can see that when I use InsertRows the range objects are immediately updated with new positions, whereas in case of InsertRange I have to explicitly re-evaluate its value to reflect change.

Could you also let me know if its possible to use InsertRange and get similar behavior as InsertRange with respect to Range objects.

Thanks

Hi,

Well, it works fine. I have tested Cells.InsertRange() method with v5.1.1 and could not find any issue. There is slight / minor issue in your code though.
Please check/see my sample code with attached input and output files.

Sample code:
Workbook workbook = new Workbook(“e:\test\differ1.xls”);
Worksheet _oAsposeWorksheet = workbook.Worksheets[0];
Range range = workbook.Worksheets.GetRangeByName(“L_1”);
CellArea ca = new CellArea();
ca.StartColumn = range.FirstColumn;
ca.EndColumn = range.FirstColumn + range.ColumnCount-1;
ca.StartRow = range.FirstRow;
ca.EndRow = range.FirstRow + range.RowCount-1;

//InsertRange
_oAsposeWorksheet.Cells.InsertRange(ca, ShiftType.Down);
//InstertRows
//_oAsposeWorksheet.Cells.InsertRows(range.FirstRow, range.RowCount);

workbook.Save(“e:\test\2outdiffere1.xls”);


If you still have any issue or queries, please do create a sample test console application, zip it and post it here to show the issue. We will check it soon.

Thank you.

Hi,


Thanks for the reply.
Could you please try this:

Workbook workbook = new Workbook(“e:\test\differ1.xls”);
Worksheet _oAsposeWorksheet = workbook.Worksheets[0];
Range range = workbook.Worksheets.GetRangeByName(“L_1”);
CellArea ca = new CellArea();
ca.StartColumn = range.FirstColumn;
ca.EndColumn = range.FirstColumn + range.ColumnCount-1;
ca.StartRow = range.FirstRow;
ca.EndRow = range.FirstRow + range.RowCount-1;

//InsertRange
_oAsposeWorksheet.Cells.InsertRange(ca, ShiftType.Down);
//InstertRows
//_oAsposeWorksheet.Cells.InsertRows(range.FirstRow, range.RowCount);

MessageBox.Show("Before update " + range.FirstRow);

range = range = workbook.Worksheets.GetRangeByName(“L_1”);
MessageBox.Show("After update " + range.FirstRow);

workbook.Save(“e:\test\2outdiffere1.xls”);

And compare the result with InsertRow.

Thanks

Hi,


Thanks for the reply.
Could you please try this:

Workbook workbook = new Workbook(“e:\test\differ1.xls”);
Worksheet _oAsposeWorksheet = workbook.Worksheets[0];
Range range = workbook.Worksheets.GetRangeByName(“L_1”);
CellArea ca = new CellArea();
ca.StartColumn = range.FirstColumn;
ca.EndColumn = range.FirstColumn + range.ColumnCount-1;
ca.StartRow = range.FirstRow;
ca.EndRow = range.FirstRow + range.RowCount-1;

//InsertRange
_oAsposeWorksheet.Cells.InsertRange(ca, ShiftType.Down);
//InstertRows
//_oAsposeWorksheet.Cells.InsertRows(range.FirstRow, range.RowCount);

MessageBox.Show("Before update " + range.FirstRow);
range = workbook.Worksheets.GetRangeByName(“L_1”);
MessageBox.Show("After update " + range.FirstRow);

workbook.Save(“e:\test\2outdiffere1.xls”);

Also please try the same with InsertRows to find the difference.

Thanks

Hi,

Well, it works fine and same as MS Excel, you may manually insert range by selecting the L_1 range and right click on it to click insert… option, you will get the similar results. See your updated code with comments:

Workbook workbook = new Workbook(“e:\test\differ1.xls”);
Worksheet _oAsposeWorksheet = workbook.Worksheets[0];
Range range = workbook.Worksheets.GetRangeByName(“L_1”);
CellArea ca = new CellArea();
ca.StartColumn = range.FirstColumn;
ca.EndColumn = range.FirstColumn + range.ColumnCount - 1;
ca.StartRow = range.FirstRow;
ca.EndRow = range.FirstRow + range.RowCount - 1;

//InsertRange
_oAsposeWorksheet.Cells.InsertRange(ca, ShiftType.Down);
//InstertRows
//_oAsposeWorksheet.Cells.InsertRows(range.FirstRow, range.RowCount);

MessageBox.Show("Before update " + range.FirstRow);//1 --> fine - since the row index is zero based (actually 2nd row of the initial range)
range = workbook.Worksheets.GetRangeByName(“L_1”);
MessageBox.Show("After update " + range.FirstRow); //7 — fine - since the row index is zero based (now the first row would be 8th row)

workbook.Save(“e:\test\2outdiffere1.xls”);


Do you get different results than this?

Thank you.

My point in earlier mail was…

When I use InsertRange I need to re-initialize the “range” object to reflect the change in position. Whereas when InsertRows option is used “range” object automatically reflects the change.

In the above code try InsertRows and you wont see any difference in the alerts before and after update (as the range automatically gets updated)

Is this by design and also is there a way to make InsertRange work similar to InsertRows?
I hope you will understand my point.

Thanks

Hi,

Thanks for the explanation.

Now I can understand your point and in fact you are right, the Range object is not automatically re-initialized upon using Cells.InsertRange() method. I have logged it into our issue tracking system with an id: CELLSNET-18845. We will investigate if we can make it similar to what Cells.InsertRows() method does.

Thank you.