Regarding Worksheet.insertRow problem

Hi Team,

import com.aspose.cells.Cell;

import com.aspose.cells.Cells;

//import com.aspose.cells.NamedRange;

import com.aspose.cells.CellArea;

import com.aspose.cells.Name;

import com.aspose.cells.NameCollection;

import com.aspose.cells.Range;

import com.aspose.cells.Style;

import com.aspose.cells.Workbook;

import com.aspose.cells.Worksheet;

public class aspose {

public static void main (String args[])

{

try {

Workbook workbook = new Workbook();

Worksheet worksheet = workbook.getWorksheets().get(0);

//Uncomment this line to get output with Memory Preference

//worksheet.getCells().setMemorySetting(MemorySetting.MEMORY_PREFERENCE);

Range cellRange = worksheet.getCells().createRange(2,1,2,1);

Range cellRange1 = worksheet.getCells().createRange(1,1,1,1);

worksheet.getCells().insertRows(3, 2);

System.out.println("hello");

System.out.println(cellRange.getFirstRow());

} catch (Exception e) {

// TODO Auto-generated catch block

if(e.getMessage().contains("Invalid formula"))

{

System.out.println("Error");

}

}

}

}


In above i have created two ranges. If i do the insert row then cellrange is not updating. Please guide me or if the code is in correct then correct me.



Thanks & Regards,

Saravanan MAni

<w:LatentStyles DefLockedState=“false” DefUnhideWhenUsed=“true”
DefSemiHidden=“true” DefQFormat=“false” DefPriority=“99”
LatentStyleCount=“267”>
<w:LsdException Locked=“false” Priority=“0” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Normal”/>
<w:LsdException Locked=“false” Priority=“9” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“heading 1”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 2”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 3”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 4”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 5”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 6”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 7”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 8”/>
<w:LsdException Locked=“false” Priority=“9” QFormat=“true” Name=“heading 9”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 1”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 2”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 3”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 4”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 5”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 6”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 7”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 8”/>
<w:LsdException Locked=“false” Priority=“39” Name=“toc 9”/>
<w:LsdException Locked=“false” Priority=“35” QFormat=“true” Name=“caption”/>
<w:LsdException Locked=“false” Priority=“10” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Title”/>
<w:LsdException Locked=“false” Priority=“1” Name=“Default Paragraph Font”/>
<w:LsdException Locked=“false” Priority=“11” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Subtitle”/>
<w:LsdException Locked=“false” Priority=“22” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Strong”/>
<w:LsdException Locked=“false” Priority=“20” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Emphasis”/>
<w:LsdException Locked=“false” Priority=“59” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Table Grid”/>
<w:LsdException Locked=“false” UnhideWhenUsed=“false” Name=“Placeholder Text”/>
<w:LsdException Locked=“false” Priority=“1” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“No Spacing”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading Accent 1”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List Accent 1”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid Accent 1”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1 Accent 1”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2 Accent 1”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1 Accent 1”/>
<w:LsdException Locked=“false” UnhideWhenUsed=“false” Name=“Revision”/>
<w:LsdException Locked=“false” Priority=“34” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“List Paragraph”/>
<w:LsdException Locked=“false” Priority=“29” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Quote”/>
<w:LsdException Locked=“false” Priority=“30” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Intense Quote”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2 Accent 1”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1 Accent 1”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2 Accent 1”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3 Accent 1”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List Accent 1”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading Accent 1”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List Accent 1”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid Accent 1”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading Accent 2”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List Accent 2”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid Accent 2”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1 Accent 2”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2 Accent 2”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1 Accent 2”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2 Accent 2”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1 Accent 2”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2 Accent 2”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3 Accent 2”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List Accent 2”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading Accent 2”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List Accent 2”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid Accent 2”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading Accent 3”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List Accent 3”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid Accent 3”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1 Accent 3”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2 Accent 3”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1 Accent 3”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2 Accent 3”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1 Accent 3”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2 Accent 3”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3 Accent 3”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List Accent 3”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading Accent 3”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List Accent 3”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid Accent 3”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading Accent 4”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List Accent 4”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid Accent 4”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1 Accent 4”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2 Accent 4”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1 Accent 4”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2 Accent 4”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1 Accent 4”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2 Accent 4”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3 Accent 4”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List Accent 4”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading Accent 4”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List Accent 4”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid Accent 4”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading Accent 5”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List Accent 5”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid Accent 5”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1 Accent 5”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2 Accent 5”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1 Accent 5”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2 Accent 5”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1 Accent 5”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2 Accent 5”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3 Accent 5”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List Accent 5”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading Accent 5”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List Accent 5”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid Accent 5”/>
<w:LsdException Locked=“false” Priority=“60” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Shading Accent 6”/>
<w:LsdException Locked=“false” Priority=“61” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light List Accent 6”/>
<w:LsdException Locked=“false” Priority=“62” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Light Grid Accent 6”/>
<w:LsdException Locked=“false” Priority=“63” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 1 Accent 6”/>
<w:LsdException Locked=“false” Priority=“64” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Shading 2 Accent 6”/>
<w:LsdException Locked=“false” Priority=“65” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 1 Accent 6”/>
<w:LsdException Locked=“false” Priority=“66” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium List 2 Accent 6”/>
<w:LsdException Locked=“false” Priority=“67” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 1 Accent 6”/>
<w:LsdException Locked=“false” Priority=“68” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 2 Accent 6”/>
<w:LsdException Locked=“false” Priority=“69” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Medium Grid 3 Accent 6”/>
<w:LsdException Locked=“false” Priority=“70” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Dark List Accent 6”/>
<w:LsdException Locked=“false” Priority=“71” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Shading Accent 6”/>
<w:LsdException Locked=“false” Priority=“72” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful List Accent 6”/>
<w:LsdException Locked=“false” Priority=“73” SemiHidden=“false”
UnhideWhenUsed=“false” Name=“Colorful Grid Accent 6”/>
<w:LsdException Locked=“false” Priority=“19” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Subtle Emphasis”/>
<w:LsdException Locked=“false” Priority=“21” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Intense Emphasis”/>
<w:LsdException Locked=“false” Priority=“31” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Subtle Reference”/>
<w:LsdException Locked=“false” Priority=“32” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Intense Reference”/>
<w:LsdException Locked=“false” Priority=“33” SemiHidden=“false”
UnhideWhenUsed=“false” QFormat=“true” Name=“Book Title”/>
<w:LsdException Locked=“false” Priority=“37” Name=“Bibliography”/>
<w:LsdException Locked=“false” Priority=“39” QFormat=“true” Name=“TOC Heading”/>
</w:LatentStyles>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman","serif";}

<![endif]–>

Hi Saravanan,


We have evaluated the presented scenario while using the latest version of Aspose.Cells for Java 8.6.0.4 and the following piece of code. We are able to notice that range is not getting updated after inserting a few rows in the area spanning the said range. In order to further investigate the matter, we have logged a ticket as CELLSJAVA-41525. Please allow us some time to properly analyze the scenario and get back to you with updates in this regard.

Java

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
Range cellRange = worksheet.getCells().createRange(0,0,3,1);
System.out.println(cellRange.getFirstRow() + " " + cellRange.getRowCount());
worksheet.getCells().insertRows(2, 2, true);
System.out.println(cellRange.getFirstRow() + " " + cellRange.getRowCount());

Hi,


We have evaluated your issue further.

Well, createRange of Cells class only provides a convenient way for the users to manipulate a range of cells. I am afraid, the returned range object is not kept in cells model due to performance grounds. As a result, without the reference of the created ranges, we cannot update them automatically when you insert/delete rows accordingly. So, if you change it to NamedRange which will be kept in cells model (also will be kept in the resultant Excel file), then it can be changed automatically.

You may also try the following sample code and it works fine and as expected.
e.g
Sample code:

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
Range cellRange = worksheet.getCells().createRange(2,1,2,1);
cellRange.setName(“MyRange”);
Range cellRange1 = worksheet.getCells().createRange(1,1,1,1);
worksheet.getCells().insertRows(2, 2);
System.out.println(“hello”);
cellRange = workbook.getWorksheets().getRangeByName(“MyRange”);

System.out.println(cellRange.getFirstRow()); //4 - Ok


Hope, this helps a bit.

Thank you.

The issues you have found earlier (filed as CELLSJAVA-41525) have been fixed in newer version of

Aspose.Cells for Java (Download | Maven).


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.