Skip to content

Commit 1bd5376

Browse files
Merge pull request #13 from securedeveloper/release
release to master [JSE-01]
2 parents 5d20c3d + fb44990 commit 1bd5376

File tree

4 files changed

+120
-3
lines changed

4 files changed

+120
-3
lines changed

src/Directory_Rels.ts

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import {JSExcel} from "./Types";
2+
import {___JSE_XLSX___Directory, ___JSE_XLSX___File, ___JSE_XLSX___FileContent, ___JSE_XLSX___Node} from "./xlsx";
3+
import {
4+
Relationship_Target_App,
5+
Relationship_Target_Core,
6+
Relationship_Target_Custom,
7+
Relationship_Target_Workbook,
8+
Relationship_Type_App,
9+
Relationship_Type_Core,
10+
Relationship_Type_Custom,
11+
Relationship_Type_Workbook,
12+
Xmlns_RelationShips
13+
} from "./Internals";
14+
15+
const fileProps: any = {
16+
name: null,
17+
extension: ".rels",
18+
version: "1.0",
19+
encoding: "UTF-8",
20+
standalone: true,
21+
nodes: {
22+
Relationships: "Relationships",
23+
Relationship: "Relationship"
24+
},
25+
keys: {
26+
xmlns: "xmlns",
27+
Id: "Id",
28+
Type: "Type",
29+
Target: "Target"
30+
},
31+
values: {
32+
Id_rId3: "rId3",
33+
Id_rId2: "rId2",
34+
Id_rId1: "rId1",
35+
Id_rId4: "rId4"
36+
}
37+
};
38+
39+
const directorProps: any = {
40+
name: "_rels",
41+
files: {rels: {...fileProps}}
42+
};
43+
44+
export default (excel: JSExcel): ___JSE_XLSX___Directory => ({
45+
directoryName: directorProps.name,
46+
content: getRelDirectoryFiles(excel)
47+
});
48+
49+
function getRelDirectoryFiles(excel: JSExcel): ___JSE_XLSX___File {
50+
return {
51+
fileName: fileProps.name,
52+
fileExtension: fileProps.extension,
53+
fileContent: getRelsNodes(excel)
54+
};
55+
}
56+
57+
function getRelsNodes(excel: JSExcel): ___JSE_XLSX___FileContent {
58+
return {
59+
xml: {
60+
version: fileProps.version,
61+
encoding: fileProps.encoding,
62+
standalone: fileProps.standalone
63+
},
64+
content: {
65+
name: fileProps.nodes.Relationships,
66+
values: [{key: fileProps.keys.xmlns, value: Xmlns_RelationShips}],
67+
content: [
68+
{
69+
name: fileProps.nodes.Relationship,
70+
values: [
71+
{key: fileProps.keys.Id, value: fileProps.values.Id_rId3},
72+
{key: fileProps.keys.Type, value: Relationship_Type_App},
73+
{key: fileProps.keys.Target, value: Relationship_Target_App}
74+
]
75+
},
76+
{
77+
name: fileProps.nodes.Relationship,
78+
values: [
79+
{key: fileProps.keys.Id, value: fileProps.values.Id_rId2},
80+
{key: fileProps.keys.Type, value: Relationship_Type_Core},
81+
{key: fileProps.keys.Target, value: Relationship_Target_Core}
82+
]
83+
},
84+
{
85+
name: fileProps.nodes.Relationship,
86+
values: [
87+
{key: fileProps.keys.Id, value: fileProps.values.Id_rId1},
88+
{key: fileProps.keys.Type, value: Relationship_Type_Workbook},
89+
{key: fileProps.keys.Target, value: Relationship_Target_Workbook}
90+
]
91+
},
92+
// ...getCustomRelationshipNode(excel) TODO: finish when file custom props are implemented
93+
]
94+
}
95+
};
96+
}
97+
98+
function getCustomRelationshipNode(excel: JSExcel): ___JSE_XLSX___Node {
99+
//TODO: return if custom values are provided
100+
return {
101+
name: fileProps.nodes.Relationship,
102+
values: [
103+
{key: fileProps.keys.Id, value: fileProps.values.Id_rId4},
104+
{key: fileProps.keys.Type, value: Relationship_Type_Custom},
105+
{key: fileProps.keys.Target, value: Relationship_Target_Custom}
106+
]
107+
};
108+
}

src/FileContentTypes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const fileProps: any = {
3333
}
3434
};
3535

36-
export const fileContentTypes = (excel: JSExcel): ___JSE_XLSX___File => ({
36+
export default (excel: JSExcel): ___JSE_XLSX___File => ({
3737
fileName: fileProps.name,
3838
fileExtension: fileProps.extension,
3939
fileContent: getContentTypeNodes(excel)

src/Internals.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const Xmlns_Types: string = "http://schemas.openxmlformats.org/package/2006/content-types";
2+
export const Xmlns_RelationShips: string = "http://schemas.openxmlformats.org/package/2006/relationships";
23
export const Extension_Rels: string = "application/vnd.openxmlformats-package.relationships+xml";
34
export const Extension_Xml: string = "application/xml";
45
export const PartName_Xl_Workbook: string = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml";
@@ -8,4 +9,12 @@ export const PartName_Xl_Styles: string = "application/vnd.openxmlformats-office
89
export const PartName_Xl_SharedStrings: string = "application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml";
910
export const PartName_DocProps_Core: string = "application/vnd.openxmlformats-package.core-properties+xml";
1011
export const PartName_DocProps_App: string = "application/vnd.openxmlformats-officedocument.extended-properties+xml";
11-
export const PartName_DocProps_Custom: string = "application/vnd.openxmlformats-officedocument.custom-properties+xml";
12+
export const PartName_DocProps_Custom: string = "application/vnd.openxmlformats-officedocument.custom-properties+xml";
13+
export const Relationship_Type_App: string = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties";
14+
export const Relationship_Type_Core: string = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";
15+
export const Relationship_Type_Custom: string = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties";
16+
export const Relationship_Type_Workbook: string = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
17+
export const Relationship_Target_App: string = "docProps/app.xml";
18+
export const Relationship_Target_Core: string = "docProps/core.xml";
19+
export const Relationship_Target_Custom: string = "xl/workbook.xml";
20+
export const Relationship_Target_Workbook: string = "docProps/custom.xml";

src/xlsx.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export interface ___JSE_XLSX___File {
9999
// TODO: add further file info as needed and verify later on
100100
}
101101

102-
interface ___JSE_XLSX___Directory {
102+
export interface ___JSE_XLSX___Directory {
103103
directoryName: ___JSE_XLSX___DirectoryName;
104104
content?: ___JSE_XLSX___File | Array<___JSE_XLSX___File> | ___JSE_XLSX___Directory | Array<___JSE_XLSX___Directory>;
105105
}

0 commit comments

Comments
 (0)