How to get the row and column indexes from range?

Hi,

I am working on chart and would like to get the rows and column indexes from getNSeries method.

the series.getValue() method returns something like this =Sheet1!$A$1:$A$4

I want to convert this to get the FirstRow,LastRow,FirstColumn,LastColum
Ex. in above example would be FirstRow=1,LastRow=4,FirstColumn=1,lastColumn=1

How do I Do that?

Regards,
Azhar

and even how to get chart position in excel (row and column where chart appears).

Hi,


I think you may try to use CellsHelper static class methods (the class has some useful methods) which Aspose.Cells for Java provides for your needs. You may get your desired data or information, see the sample code below with comments, you may refer to it and write your own codes accordingly.
e.g
Sample code:

Workbook wb = new Workbook();
//…

//Range String
String val = “Sheet1!$A$1:$C$10”;
//Get the first split
String [] strSplitData1 = val.split("!");
//Get the worksheet name from first array
System.out.println(“Sheet Name: " +strSplitData1[0]);

//Performing operations on the second array, replace the “$” first.
String strCellRange = strSplitData1[1].replace(”$", “”);
//Splitting by “:” - we will get two arrays.
String [] strCellRanges = strCellRange.split(":");

//Get the first row and first column from the first array.
int [] frowcol = CellsHelper.cellNameToIndex(strCellRanges[0]);
//Get the last row and last column indices from second array
int []lrowcol = CellsHelper.cellNameToIndex(strCellRanges[1]);

//Print the first array
System.out.println("First Row: " + frowcol[0]);
System.out.println("First Col: " + frowcol[1]);

//Print the second(last) array.
System.out.println("End Row: " + lrowcol[0]);
System.out.println("End Col: " + lrowcol[1]);

Hope, this helps you a bit.

Thank you.

Hi,

azhar920:
and even how to get chart position in excel (row and column where chart appears).
Please see the sample code snippet for your reference:
e.g
Sample code:
..............
ChartShape chartShape = chart.getChartObject();

System.out.println("Upper Left Row " + chartShape.getUpperLeftRow());
System.out.println("Upper Left Column " + chartShape.getUpperLeftColumn());
System.out.println("Lower Right Row " + chartShape.getLowerRightRow());
System.out.println("Lower Right Column " + chartShape.getLowerRightColumn());

Hope, this helps a bit.

Thank you.

Thanks for the pointer.

Regards,
Azhar

Hi,


Good to know that your issue is resolved now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.