Free Support Forum -

Delete the last column of resultset in worksheet

Hi all,

I use importResultSet(resultSet,“A4”,true); and true for Field Name Shown but I want to delete the last result Column which doesn’t have the same position in all case. I can’t do getCells().deleteColumns(’’, ‘’, true), because I don’t have the real position and i want to delete the field name too.

How can I do?



I think, you should just calculate how many fields are in your result sets, say you have 5 fields, then you should delete the 5th column

//Deleting a column from the worksheet at 5th position
//Column Index is 4
//Number of Colums is 1
//Shift cells to Left is true


I think the better way is that you should call the following method instead:

int com.aspose.cells.Cells.importResultSet(ResultSet rs, int rowIndex, int columnIndex, int rowNum, int columnNum, boolean isFieldNameShown) throws SQLException

where for rowNum you can input -1 to import all records in the resultset but columnNum is the total column count minus 1 to exclude the last column. For the total columns count of one ResultSet, it is easy to get by following code:

ResultSetMetaData meta = rs.getMetaData();

columnNum = meta.getColumnCount();

Thank you.


Thanks for your answers.
I found solution about this point, if it can help too

int c = worksheet.getRow(7).getLastCellIndex(); // I take the last row of my sheet
worksheet.getCells().deleteColumns(c,1,true); // and I delete


It is good to know you find a solution for your problem.