Skip to content

Commit ba61c91

Browse files
author
Olivier Chédru
authored
Merge pull request #159 from ochedru/timestamp_prevent_excel_from_opening
Fix: wrong timestamp in docProps/core.xml
2 parents fd4b791 + 8ca4378 commit ba61c91

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

fastexcel-writer/src/main/java/org/dhatim/fastexcel/Workbook.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
import java.io.IOException;
2121
import java.io.OutputStream;
22-
import java.time.LocalDateTime;
22+
import java.time.Instant;
23+
import java.time.ZoneId;
2324
import java.time.format.DateTimeFormatter;
2425
import java.util.*;
25-
import java.util.Map;
26-
import java.util.stream.Stream;
2726
import java.util.stream.Collectors;
27+
import java.util.stream.Stream;
2828
import java.util.zip.ZipEntry;
2929

3030

@@ -129,7 +129,7 @@ public void finish() throws IOException {
129129
w.append("<Override PartName=\"/docProps/core.xml\" ContentType=\"application/vnd.openxmlformats-package.core-properties+xml\"/><Override PartName=\"/docProps/app.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.extended-properties+xml\"/></Types>");
130130
});
131131
writeFile("docProps/app.xml", w -> w.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\"><Application>").appendEscaped(applicationName).append("</Application>").append(applicationVersion == null ? "" : ("<AppVersion>" + applicationVersion + "</AppVersion>")).append("</Properties>"));
132-
writeFile("docProps/core.xml", w -> w.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><dcterms:created xsi:type=\"dcterms:W3CDTF\">").append(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)).append("Z</dcterms:created><dc:creator>").appendEscaped(applicationName).append("</dc:creator></cp:coreProperties>"));
132+
writeFile("docProps/core.xml", w -> w.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><dcterms:created xsi:type=\"dcterms:W3CDTF\">").append(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX").withZone(ZoneId.of("UTC")).format(Instant.now())).append("</dcterms:created><dc:creator>").appendEscaped(applicationName).append("</dc:creator></cp:coreProperties>"));
133133
writeFile("_rels/.rels", w -> w.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\"><Relationship Id=\"rId3\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties\" Target=\"docProps/app.xml\"/><Relationship Id=\"rId2\" Type=\"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties\" Target=\"docProps/core.xml\"/><Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\" Target=\"xl/workbook.xml\"/></Relationships>"));
134134

135135
writeWorkbookFile();
@@ -201,7 +201,7 @@ private void writeWorkbookFile() throws IOException {
201201
}
202202
w.append("</sheets>");
203203
/** Defining repeating rows and columns for the print setup...
204-
* This is defined for each sheet separately
204+
* This is defined for each sheet separately
205205
* (if there are any repeating rows or cols in the sheet at all) **/
206206

207207
w.append("<definedNames>");

0 commit comments

Comments
 (0)