Код: Выделить всё
void writeExcelFile() {
var workbook = new HSSFWorkbook();
byte[] bytes;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
workbook.write(bos);
bytes = bos.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
Files.write(Path.of("foo.xls"), bytes);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Код: Выделить всё
christoffer.gamrathКод: Выделить всё
$ strings foo.xls main?
christoffer.gamrath B
Arial1
Arial1
Arial1
Arial
"$"#,##0_);("$"#,##0)
"$"#,##0_);[Red]("$"#,##0)
"$"#,##0.00_);("$"#,##0.00)
"$"#,##0.00_);[Red]("$"#,##0.00)
_("$"* #,##0_);_("$"* (#,##0);_("$"* "-"_);_(@_)
_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)
_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)
_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)
Sheet1
< /code>
Я хочу избежать хранения моего имени пользователя в файле, так что, когда я запускаю один и тот же код на другой машине, полученный файл будет точно таким же.void writeExcelFileWithoutProperties() {
var workbook = new HSSFWorkbook();
workbook.createInformationProperties();
SummaryInformation summaryInfo = workbook.getSummaryInformation();
if (summaryInfo != null) {
summaryInfo.setAuthor("");
summaryInfo.setLastAuthor("");
summaryInfo.setTitle("");
summaryInfo.setSubject("");
summaryInfo.setKeywords("");
summaryInfo.setComments("");
}
DocumentSummaryInformation docSummaryInfo = workbook.getDocumentSummaryInformation();
if (docSummaryInfo != null) {
docSummaryInfo.setCompany("");
docSummaryInfo.setManager("");
}
byte[] bytes;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
workbook.write(bos);
bytes = bos.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
Files.write(Path.of("foo2.xls"), bytes);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... excel-file