Discussion:
How to delete a column from Excel File using java
(too old to reply)
Paturi PRADEEP GOUD
2013-04-26 08:34:02 UTC
Permalink
I want to delete a column from Excel file using java. Following code I build to meet my requirement. but it is not working. Can anybody please help where I am going wrong.

public class Column
{
public static void main(String[] args)
{
Workbook wb = WorkbookFactory.create(new FileInputStream("Excel.xls"));
Sheet sheet = wb.getSheet("Failures");
Cell cell;
Column column;
Row row= sheet.getRow(0);
int numXolumns = row.getLastCellNum();

for(int col=0; col< numXolumns; col++)
{
cell = row.getCell(col);
String columnName = cell.getStringCellValue();
int Combo_index = 0;
if(columnName.contains("Combo".trim()))
{
Combo_index=cell.getColumnIndex();
sheet.removeRow(row);
}
}
}
}
Fred Kleinschmidt
2013-04-26 15:04:28 UTC
Permalink
I want to delete a column from Excel file using java. Following code I build to meet my requirement. but it is not working. Can anybody please help where I am going wrong. public class Column { public static void main(String[] args) { Workbook wb = WorkbookFactory.create(new FileInputStream("Excel.xls")); Sheet sheet = wb.getSheet("Failures"); Cell cell; Column column; Row row= sheet.getRow(0); int numXolumns = row.getLastCellNum(); for(int col=0; col< numXolumns; col++) { cell = row.getCell(col); String columnName = cell.getStringCellValue(); int Combo_index = 0; if(columnName.contains("Combo".trim())) { Combo_index=cell.getColumnIndex(); sheet.removeRow(row); } } } }
Why not just use sheet.removeColumn( columnNumber ) ?
--
Fred K
Loading...