ooxml

Check-in [58d5177915]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:save work
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tcltest
Files: files | file ages | folders
SHA3-256: 58d5177915325dcca253720f2b48194f1fde58a3fe2bc6968e4528a96c58ac35
User & Date: alex 2019-11-05 07:55:11
Context
2019-11-05
09:22
test validty of app.xml and core.xml check-in: a9b5d6ee1e user: alex tags: tcltest
07:55
save work check-in: 58d5177915 user: alex tags: tcltest
2019-11-04
13:44
save work check-in: 73393cf0b3 user: alex tags: tcltest
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to tests/simple.test.

13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


45
46
47
48
49
50










51
52




53
54
55


56
57
58
59
60
61
62
63




64
65
66
67

68
69

70

























71
72
73
74
75
76
77
  package require tcltest 2
  namespace import -force ::tcltest::*
  loadTestedCommands
}


package require ooxml



test SimpleExcel-1.1 {Write Simple Excel Sheet} {
  set spreadsheet [::ooxml::xl_write new -creator {User A} -created {2019-10-31 15:10:23} -modifiedby {User B} -modified {2019-10-31 15:10:23} -application {Tcl Test}]
  if {[set sheet [$spreadsheet worksheet {Sheet 1}]] > -1} {
    $spreadsheet cell $sheet {Tcl Test - SimpleExcel} -index A1
    $spreadsheet write simple.xlsx
  }
  $spreadsheet destroy

  return [file exists simple.xlsx]
} 1


test SimpleExcel-1.2 {Read Simple Excel Sheet} {
  array set workbook [ooxml::xl_read simple.xlsx]
  #parray workbook
  return $workbook(0,c,0,0)
} A1

test SimpleExcel-1.3 {Read Simple Excel and Check App, User, DateTime} {
  package require vfs::zip
  set mnt [vfs::zip::Mount simple.xlsx xlsx]

  # docProps/app.xml # Properties: Application


  set fd [open xlsx/docProps/app.xml r]
  fconfigure $fd -encoding utf-8
  set doc [dom parse [read $fd]]
  close $fd

  set root [$doc documentElement]










  $doc selectNodesNamespaces [list X [$root namespaceURI]]
  # ...




  $doc delete

  # docProps/core.xml # cp:coreProperties: dc:creator, cp:lastModifiedBy, dcterms:created and dcterms:modified


  set fd [open xlsx/docProps/app.xml r]
  fconfigure $fd -encoding utf-8
  set doc [dom parse [read $fd]]
  close $fd

  set root [$doc documentElement]
  # ...
  $doc delete





  vfs::zip::Unmount $mnt xlsx

  return 0

} 0




























#file delete -force simple.xlsx


# cleanup
::tcltest::cleanupTests
return








>

<
|
|










|

<



|
|
|
|
|
>
>





|
>
>
>
>
>
>
>
>
>
>
|
<
>
>
>
>
|

<
>
>
|




<
<
<
>
>
>
>
|
<

<
>
|

>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|






13
14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

63
64
65
66
67
68

69
70
71
72
73
74
75



76
77
78
79
80

81

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  package require tcltest 2
  namespace import -force ::tcltest::*
  loadTestedCommands
}


package require ooxml
package require vfs::zip


test SimpleExcelWrite-1.1 {Write a Simple Excel Sheet} {
  set spreadsheet [::ooxml::xl_write new -creator {User A} -created {2019-10-31 15:10:23} -modifiedby {User B} -modified {2019-10-31 17:20:45} -application {Tcl Test}]
  if {[set sheet [$spreadsheet worksheet {Sheet 1}]] > -1} {
    $spreadsheet cell $sheet {Tcl Test - SimpleExcel} -index A1
    $spreadsheet write simple.xlsx
  }
  $spreadsheet destroy

  return [file exists simple.xlsx]
} 1


test SimpleExcelRead-1.2 {Read a Simple Excel Sheet} {
  array set workbook [ooxml::xl_read simple.xlsx]

  return $workbook(0,c,0,0)
} A1


test MountXLSX-2.1 {Mount XLSX File} {
  catch {vfs::zip::Mount simple.xlsx xlsx} mnt
} 0


test DocPropsApp-3.1 {Parse xlsx/docProps/app.xml} {
  set fd [open xlsx/docProps/app.xml r]
  fconfigure $fd -encoding utf-8
  set doc [dom parse [read $fd]]
  close $fd

  set appXmlNs {
    ? http://schemas.openxmlformats.org/officeDocument/2006/extended-properties
    vt http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes
  }

  return [set appDoc [string match domDoc* $doc]]
} 1

testConstraint appCheck $appDoc

#test DocPropsApp-3.2 {Check Application -application} appCheck {
#  $doc selectNodesNamespaces $appXmlNs

#  [$doc selectNodes /Application/text()] nodeValue
#} {Tcl Test}
 

$doc delete



test DocPropsCore-4.1 {Parse xlsx/docProps/core.xml} {
  set fd [open xlsx/docProps/core.xml r]
  fconfigure $fd -encoding utf-8
  set doc [dom parse [read $fd]]
  close $fd




  set coreXmlNs {
    cp http://schemas.openxmlformats.org/package/2006/metadata/core-properties
    dc http://purl.org/dc/elements/1.1/
    dcterms http://purl.org/dc/terms/
  }



  return [set coreDoc [string match domDoc* $doc]]
} 1

testConstraint coreCheck $coreDoc

test DocPropsCore-4.2 {Check Creator -creator} coreCheck {
  $doc selectNodesNamespaces $coreXmlNs
  [$doc selectNodes /cp:coreProperties/dc:creator/text()] nodeValue
} {User A}
 
test DocPropsCore-4.3 {Check Modified By -modifiedby} coreCheck {
  $doc selectNodesNamespaces $coreXmlNs
  [$doc selectNodes /cp:coreProperties/cp:lastModifiedBy/text()] nodeValue
} {User B}

test DocPropsCore-4.4 {Check Modified By -created} coreCheck {
  $doc selectNodesNamespaces $coreXmlNs
  [$doc selectNodes /cp:coreProperties/dcterms:created/text()] nodeValue
} {2019-10-31T15:10:23Z}

test DocPropsCore-4.5 {Check Modified By -modified} coreCheck {
  $doc selectNodesNamespaces $coreXmlNs
  [$doc selectNodes /cp:coreProperties/dcterms:modified/text()] nodeValue
} {2019-10-31T17:20:45Z}


$doc delete


vfs::zip::Unmount $mnt xlsx
file delete -force simple.xlsx


# cleanup
::tcltest::cleanupTests
return