ooxml

Artifact [8d2ffe7df1]
Login

Artifact 8d2ffe7df1bbcdcf3bc0e8fb7a48922217b1f568ffbb6b46c499f808cc1de6e5:

Wiki page [examples] by alex 2019-12-11 18:12:46.
D 2019-12-11T18:12:46.190
L examples
P f80af42934e91b6573397277e057380373a695194c4e1a8fe7599224d0865ed9
U alex
W 3388
<h3>Examples</h3>
<hr>
<p><b>Reading a complete XLSX workbook including all sheets:</b></p>
<verbatim>
package require ooxml

array set workbook [ooxml::xl_read my-first.xlsx]
</verbatim>
<p></p>
<hr>
<p><b>Generating XLSX with direct addressing with -index:</b></p>
<verbatim>
package require ooxml

set spreadsheet [::ooxml::xl_write new -creator {Creator Name}]
if {[set sheet [$spreadsheet worksheet {Sheet 1}]] > -1} {
  $spreadsheet cell $sheet 12.34 -index 0,0
  $spreadsheet cell $sheet 5.6 -index 0,1
  $spreadsheet cell $sheet {} -index C1 -formula {A1+B1}

  $spreadsheet cell $sheet {My Text} -index A2 -string 
}
$spreadsheet write my-first.xlsx
$spreadsheet destroy
</verbatim>
<p><b>You can use numeric index row,col (0,0) or alfanumeric index like Excel does rowcol (A1).</b></p>
<p>An other way is using autoincrement:</p>
<verbatim>
package require ooxml

set spreadsheet [::ooxml::xl_write new -creator {Creator Name}]
if {[set sheet [$spreadsheet worksheet {Sheet 1}]] > -1} {
  $spreadsheet row $sheet
  $spreadsheet cell $sheet 12.34
  $spreadsheet cell $sheet 5.6
  $spreadsheet cell $sheet {} -formula {A1+B1}

  $spreadsheet row $sheet
  $spreadsheet cell $sheet {My Text} -string
}
$spreadsheet write my-first.xlsx
$spreadsheet destroy
</verbatim>
<p><b>Rows and coulmns are auto incremented and can be skipped by -index like this:</b></p>
<verbatim>
$spreadsheet row
$spreadsheet cell $sheet Value1
$spreadsheet cell $sheet Value2 -index 4
$spreadsheet cell $sheet Value3
$spreadsheet row -index 3
$spreadsheet cell $sheet Value4
</verbatim>
<p>The result will be Value1 in 0,0 (A1), Value2 in 0,4 (E1), Value3 in 0,5 (F1) and Value4 in 3,0 (A4).</p>
<p><b>There are two helper to convert row,col to string and the other way around.</b></p>
<verbatim>
::ooxml::StringToRowColumn A1
</verbatim>
<p>Result = 0,0</p>
<verbatim>
::ooxml::RowColumnToString 0,0
</verbatim>
<p>Result = A1</p>
<p><b>An other helper can calculate the column width of a cell:</b></p>
<verbatim>
::ooxml::CalcColumnWidth 16
</verbatim>
<p>Result = 16.7109375</p>
<hr>
<h3>Example Files</h3>
<hr>
<p>[/artifact/08100118488d4bf3|sample1.tcl]:</p>
<p>Write an Excel file method one: direct addressing with -index.<br>Output: export1.xlsx</p>
<hr>
<p>[/artifact/b4c372acfe53d92a|sample2.tcl]:</p>
<p>Write an Excel file method two: with row auto increment.<br>Output: export2.xlsx</p>
<hr>
<p>[/artifact/0e61229dc27a38ed|sample3.tcl]:</p>
<p>Exporting a Tablelist to an Excel file.<br>Output: export3.xlsx</p>
<hr>
<p>[/artifact/186c1193f2c37296|sample4.tcl]:</p>
<p>Write an Excel file with a formula A1+B1.<br>Output: export4.xlsx</p>
<hr>
<p>[/artifact/341a4cbd7d5bc92d|sample5.tcl]:</p>
<p>Write an Excel file with defaultdatestyle set.<br>Output: export5.xlsx</p>
<hr>
<p>[/artifact/2e75521984e18f6c|sample6.tcl]:</p>
<p>Write a complex Excel file with a lot of formats.<br>Output: export6.xlsx</p>
<hr>
<p>[/artifact/0f8f51f54f5079c8|sample7.tcl]:</p>
<p>Read a complex Excel file (generated by Excel) interpret all known formats and write it back.<br>Input: original_excel.xlsx<br>Output: export7.xlsx</p>
<hr>
<p>[/artifact/a4549c1eb1159a39 |sample8.tcl]:</p>
<p>Read in an Excel file search and replace some cells and write a new file.<br>Input: form8.xlsx<br>Output: export8.xlsx</p>
<hr>
Z 1a3ec8bd92e0e9f6f0ac133aaa60c6e7