There is a class for writing a data structure to a new excel file, shown below. You need to add the ability to write to the template.

Those. now comes a list of sheets to write to the file (Map> ofd) where the key is the name of the sheet, and the value is a list of data lines.

And all this is recorded in the new file Excel.

I want to write the same data into a template in which several sheets of data already exist.

public class WriteToExcel { public String writeResult(String path, Map<String, List<String[]>> ofd){ SXSSFWorkbook newBook = new SXSSFWorkbook(100); Sheet newSheet = null; //в цикле получаю список названий листов и передаю их далее для записи for(String sheetName: ofd.keySet()){ newSheet = newBook.createSheet(sheetName); writeSheet(newSheet,ofd.get(sheetName)); } String pathResult = path + "\\ИМЯ.xlsx"; saveBook(newBook, pathResult); return pathResult; } //метод для сохранения результата private void saveBook(SXSSFWorkbook newBook, String path) { FileOutputStream fos; try { fos = new FileOutputStream(new File(path)); newBook.write(fos); fos.close(); } catch (Exception e) { e.printStackTrace(); } } // запись данных в эксель private void writeSheet(Sheet sheet, List<String[]> list){ Row row = null; for(int i=0;i<list.size();i++){ String [] rowData = list.get(i); row = sheet.createRow(i); for (int j = 0; j < list.get(0).length; j++) { try { //Чтобы числа были записаны в xml как числа а не как текст row.createCell(j).setCellValue(Double.parseDouble(list.get(i)[j])); } catch (Exception e) { row.createCell(j).setCellValue(list.get(i)[j]); } } } } } 
  • one
    So write down, the question is what? - ezhov_da
  • Do you have a program? I have a similar task. Can you share the source? - Maxim Taranyuk 1:51 pm
  • Sorry, everything remains on the old job. - Padawan
  • I beg you, look, I have described in detail the question link . - Maxim Taranyuk
  • Maybe there will be some advice? I honestly do not know what to do. - Maxim Taranyuk

0