Exemplo n.º 1
0
  public void make(File source, DataSet header, DataSet master) throws Exception {
    this.header = header;
    this.master = master;

    if (header == null || master == null) throw new Exception("Dataset is empty");

    long t = System.currentTimeMillis();

    InputStream inp = new FileInputStream(source);
    Workbook oldBook = WorkbookFactory.create(inp);
    Sheet oldSheet = oldBook.getSheetAt(0);

    Workbook newBook = new HSSFWorkbook();
    Sheet newSheet = newBook.createSheet(oldSheet.getSheetName());

    init(newBook);
    process(oldSheet, newSheet);

    File target = File.createTempFile("libra", ".xls");
    target.deleteOnExit();
    FileOutputStream fileOut = new FileOutputStream(target);

    newBook.write(fileOut);
    fileOut.close();
    oldBook.close();
    inp.close();

    Desktop.getDesktop().open(target);

    System.out.println(System.currentTimeMillis() - t);
  }
Exemplo n.º 2
0
  @Test
  public void test_writeFile() {

    String path = "D:\\test.xlsx";
    // String path = "D:\\test.xls";
    // String path = "D:/";
    // String path = "D:\\";

    long startTime = System.currentTimeMillis();
    try {
      ExcelUtil.writeFile(path);
    } catch (IOException e) {
      e.printStackTrace();
    }

    System.out.println("cost :" + (System.currentTimeMillis() - startTime));
  }