Hi All,
I am new to POI and HSSF.
I have already an existing excel file. In that excel there is a shhet having some data in side this and also there is some excel macro in side this excel.

I want to delete all the records of that sheet excluding the 1st rows(Header).
I used the following code for this, but it's deleting the data as well as all the macros. that means when I m opening the excel after execution of the java code , excel shows following error as pop up
an error occurred initializing the VBA libraries


Please help me as it's urgent

package com.iflex.masterLookUp;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

//import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class DeleteTest {
public static void main(String[] args){
String fileName = "D:\\kirti\\test.xls";
// String fileNameNew = "D:\\kirti\\test1.xls";
// if (StringUtils.isEmpty(fileName) || !fileName.endsWith("xls")) {
//
// throw new IllegalArgumentException("Only files with extension XLS can be read");
//
// }
try{

POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(fileName));

HSSFWorkbook book = new HSSFWorkbook(fs);
System.out.println("No of sheets:"+book.getNumberOfSheets());
if(book.getNumberOfSheets()>0){
HSSFSheet sheet = book.getSheetAt(0);

System.out.println("PhysicalRowNum:"+sheet.getPhys icalNumberOfRows());
System.out.println("LastRowNum:"+sheet.getLastRowN um());
int rowNo=sheet.getLastRowNum();
if(sheet.getLastRowNum()>0){
for(int i=1;i<=rowNo;i++){
HSSFRow row = sheet.getRow(i);
System.out.println("Row:"+i+"\n");
if(i>=1) {
sheet.removeRow(row);
}
}
//sheet.shiftRows(0, 3, -3);
//sheet.createRow(3);
}
}
fs = null;
FileOutputStream fos = new FileOutputStream(fileName);
book.write(fos);
fos.close();
}
catch(IOException ioe){
System.out.println("IOException raised:"+ioe);
}
catch(Exception e){
System.out.println("Other exception raised:"+e);
}
}


}



Thanks
Kirti Das