jferard / fastods

A very fast and lightweight (no dependency) library for creating ODS (Open Document Spreadsheet, mainly for Calc) files in Java. It's a Martin Schulz's SimpleODS fork
GNU General Public License v3.0
36 stars 6 forks source link

Please Support In-Memory Creation Instead Of File #215

Closed meSmashsta closed 3 years ago

meSmashsta commented 3 years ago

I don't want to save the file on disk but just want to send them to clients each request since the file is always new.

For example it would be nice to be able to do something like this:

final AnonymousOdsFileWriter writer = odsFactory.createWriter();
// ....
OutputStream out = new ByteArrayOutputStream();
writer.write(out);
return out;
jferard commented 3 years ago

Try this:

    final OdsFactory odsFactory = OdsFactory.create(Logger.getLogger("hello-world"), Locale.US);
    final AnonymousOdsFileWriter writer = odsFactory.createWriter();
    final OdsDocument document = writer.document();
    final Table table = document.addTable("hello-world");
    final TableRowImpl row = table.getRow(0);
    final TableCell cell = row.getOrCreateCell(0);
    cell.setStringValue("Hello, world!");
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    writer.save(out);

You can check the result:

    System.out.println(Arrays.toString(out.toByteArray()));

Output (depends on the FastODS version you are using):

[80, 75, 3, 4, 10, 0, 0, 8, 0, 0, 37, 126, 118, 81, -123 ...
meSmashsta commented 3 years ago

Try this:

    final OdsFactory odsFactory = OdsFactory.create(Logger.getLogger("hello-world"), Locale.US);
    final AnonymousOdsFileWriter writer = odsFactory.createWriter();
    final OdsDocument document = writer.document();
    final Table table = document.addTable("hello-world");
    final TableRowImpl row = table.getRow(0);
    final TableCell cell = row.getOrCreateCell(0);
    cell.setStringValue("Hello, world!");
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    writer.save(out);

You can check the result:

    System.out.println(Arrays.toString(out.toByteArray()));

Output (depends on the FastODS version you are using):

[80, 75, 3, 4, 10, 0, 0, 8, 0, 0, 37, 126, 118, 81, -123 ...

Ohhhh! Thanks!!! as long as it extends OutputStream it should work, thanks again!

jferard commented 3 years ago

You are welcome.