1

I'm trying to create Excel file in java. Right now, i'm using Apache POI library to create the file and save it to local drive. Is there a way to start up excel and populate the data without saving it to hard drive?

Progress Programmer
  • 7,076
  • 14
  • 49
  • 54

2 Answers2

1

Consider the approach shown in Downloading Excel file from server using servlets. I've used it for CSV files, but the xlsx mime type extension looks appealing.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
0

Something like this maybe

import java.awt.Desktop;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ManualXlsxTest {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        Workbook wb = new XSSFWorkbook();
        wb.createSheet("new sheet");
        File tempXlsx = File.createTempFile("temp", ".xlsx");
        wb.write(new FileOutputStream(tempXlsx));
        Desktop.getDesktop().open(tempXlsx);
    }
}
Ivan Sopov
  • 2,300
  • 4
  • 21
  • 39