I have a question which i think is very simple, but i can’t seem to find the answer for. Please help.
I have a report which output is in .docx format. Now i want the output of that same report in .txt format. The solution seems so far for.
This is an example of the output i want to generate, so i can be opened with notepad.
${account.accoutnumber}/${account.amount} Salary for ${account. month} ${account.year}/${account.voornaam} ${account.familienaam}
Hi,
To create a TXT content, use StringBuilder class from the Java standard library.
To download a file, inject ExportDisplay class to the screen controller.
Example:
@Inject
private CollectionContainer<Deck> decksDc;
@Inject
private ExportDisplay exportDisplay;
@Subscribe("decksTable.exportText")
public void onDecksTableExportText(Action.ActionPerformedEvent event) {
List<Deck> decks = decksDc.getItems();
StringBuilder text = new StringBuilder();
for (Deck deck: decks) {
text.append(deck.getName())
.append("/")
.append(deck.getCreationDate())
.append("/")
.append(deck.getPriority())
.append("\n");
}
exportDisplay.show(new ExportDataProvider() {
@Override
public InputStream provide() {
return new ByteArrayInputStream(text.toString().getBytes(StandardCharsets.UTF_8));
}
}, "report.txt");
}