Je veux copier tout le contenu d'un Excel (.xls) dans un autre après avoir remplacé " et '. Cependant, ce code crée une nouvelle excel mais seulement copier la dernière colonne (dans mon cas, il est 7ème colonne). S'il vous plaît conseiller où vais-je pas avec ce code ...Création d'une copie d'un fichier Excel ne fonctionne pas comme prévu
public class {Renommer
static HSSFRow row_read = null;
static HSSFRow row_write = null;
static Cell cell;
static FileOutputStream output = null;
static HSSFWorkbook workbook_read = null;
static HSSFWorkbook workbook_write = null;
static HSSFSheet sheet_read = null;
static HSSFSheet sheet_write = null;
public static void removechar()
{
try{
FileInputStream input = new FileInputStream("inputpath//test_input.xls");
workbook_read = new HSSFWorkbook(input);
sheet_read = workbook_read.getSheet("Report");
workbook_write = new HSSFWorkbook();
sheet_write = workbook_write.createSheet("Test");
DataFormatter formatter = new DataFormatter();
int rowCount = sheet_read.getLastRowNum();
System.out.println(rowCount);
for(int rowNum = 0; rowNum<=rowCount; rowNum++)
{
for(int cellNum = 0; cellNum<=7; cellNum++)
{
//Cell cell = null;
row_read=sheet_read.getRow(rowNum);
row_write = sheet_write.createRow(rowNum);
String temp = formatter.formatCellValue(row_read.getCell(cellNum));
//System.out.println(temp);
String temp1 = temp.replaceAll("\'", "");
String temp2 = temp1.replaceAll("\"", "");
System.out.println(temp2);
cell = row_write.createCell(cellNum);
cell.setCellValue(temp2);
}
}
output = new FileOutputStream("outputpath\\test_output.xls");
workbook_write.write(output);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] argv) throws IOException {
Rename.removechar();
}
}
Merci
Ce changement de code est la copie seule la première ligne dans la nouvelle excel .... :( – aman
J'ai ajouté le code complet à la réponse, il fonctionne très bien .. – Jobin
Merci ... Il travaillé comme un charme ... :) – aman