Boa noite, pessoal estou com um problema aqui, tenho o seguinte codigo, atualmente este codigo edita um arquivo xls ultilizando apache POI, no codigo tem o seguinte if(cell.toString().contains(“1.1019010128486E13”)), que faz uma verificação se conter o numero ele pega coluna na posição 2 e guarda na variavel cellNota1, depois do while e setado o valor 123123 para esta variavel, o que eu quero fazer e setar essa variavel por exemplo da linha 11 a linha 28 vai ser inserido este valor, um exemplo um for navegando nessas linhas e adicionando o valor da variavel pesquisei na internet e ate agora nao achei nada parecido alguem sabe como fazer?
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package retXlsx;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFCell;
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.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
public class EditaExcel {
// caminho do arquivo
private static final String fileName = "/home/fernandounix/Descargas/Arquivos/AC0143103051601.xls";
private static final String fileNameSaida = "/home/fernandounix/Descargas/Arquivos/saida.xls";
static Cell cellNota1;
public static void main(String[] args) throws IOException {
try {
FileInputStream file = new FileInputStream(new File(EditaExcel.fileName));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheetAlunos = workbook.getSheetAt(0);
// linhas do arquivo
Iterator<Row> rows = sheetAlunos.rowIterator();
// executa enquanto linhas existir
while (rows.hasNext()) {
HSSFRow row = (HSSFRow) rows.next();
// cell navegação das colunas
Iterator<Cell> cells = row.cellIterator();
while (cells.hasNext()) {
HSSFCell cell = (HSSFCell) cells.next();
// Pega linhas Cell que conter o numero
if (cell.toString().contains("1.1019010128486E13")) {
// captura coluna 2 que conter os numero acima
cellNota1 = row.getCell(2);
// System.out.println(cellNota1);
}
}
}
file.close();
// Faz alteração do valor da coluna pelo valor da
// variavel cellNota1
cellNota1.setCellValue(123123);
System.out.println(cellNota1);
// Salvar alterações
FileOutputStream outFile = new FileOutputStream(new
File(EditaExcel.fileNameSaida));
workbook.write(outFile);
outFile.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("Arquivo Excel não encontrado!");
} catch (IOException e) {
e.printStackTrace();
System.out.println("Erro na edição do arquivo!");
}
}
}